diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2017-03-06 16:54:33 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2017-03-06 16:54:33 +0000 |
| commit | 18bb55545e6f99e9ab80900db65222e8b98aee13 (patch) | |
| tree | cb0239f5da7b528ee159fbc0f0f6f8468460407e | |
| parent | 168979e6fb9e338ba9c6033d14dba7c2c04782f6 (diff) | |
Fl_Tabs: improve tab label drawing (STR #3075, STR #3076).
New method Fl_Tabs::tab_align() supports icons in tabs (STR #3076).
This commit also enables drawing labels of Fl_Window children (STR #3075).
Setting tab_align(FL_IMAGE_NEXT_TO_TEXT) draws images (icons) in the tab
labels if the child has an image(). Currently this draws the image() even
if the child is deactived (so it should presumably draw the deimage()).
Todo: Label measurement and Fl_Windows as children still need fixups.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12185 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | FL/Fl_Tabs.H | 19 | ||||
| -rw-r--r-- | src/Fl_Tabs.cxx | 21 |
3 files changed, 40 insertions, 3 deletions
@@ -17,6 +17,8 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017 New Features and Extensions + - New method Fl_Tabs::tab_align() allows to set alignment of tab labels, + particularly to support icons on tab labels (STR #3076). - Added '--enable-print' option to configure effective under X11 platforms and with 'yes' default value. Using '--enable-print=no' removes print and PostScript support from the FLTK library, thus reducing its size. @@ -51,6 +53,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017 Bug Fixes - (add new items here) + - Fix Fl_Tabs label drawing for Fl_Window children (STR #3075). - Fix line number alignment in Fl_Text_Display/Editor (STR #3363). - Fix ignored buffer pre-allocation (requestedSize) in Fl_Text_Buffer. See fltk.general "Fl_Text_Buffer constructor bug" on Dec 5, 2016. diff --git a/FL/Fl_Tabs.H b/FL/Fl_Tabs.H index 3d75db81d..06c23aee5 100644 --- a/FL/Fl_Tabs.H +++ b/FL/Fl_Tabs.H @@ -208,6 +208,7 @@ class FL_EXPORT Fl_Tabs : public Fl_Group { int tab_height(); void draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int sel=0); protected: + Fl_Align tab_align_; // tab label alignment void redraw_tabs(); void draw(); @@ -231,6 +232,24 @@ public: Fl_Widget *which(int event_x, int event_y); ~Fl_Tabs(); void client_area(int &rx, int &ry, int &rw, int &rh, int tabh=0); + /** + Sets the tab label alignment. + + The default is FL_ALIGN_CENTER so tab labels are centered, but since + the label space is measured (per label) to fit the labels, there + wouldn't be any difference if labels were aligned left or right. + + If you want to show an image (icon) next to the group's label you can + set a different label alignment. FL_ALIGN_IMAGE_NEXT_TO_TEXT is the + recommended alignment to show the icon left of the text. + */ + void tab_align(Fl_Align a) {tab_align_ = a;} + /** + Gets the tab label alignment. + + \see tab_align(Fl_Align) + */ + Fl_Align tab_align() const {return tab_align_;} }; #endif diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx index d57b92bc9..eaba0dbbb 100644 --- a/src/Fl_Tabs.cxx +++ b/src/Fl_Tabs.cxx @@ -63,7 +63,15 @@ int Fl_Tabs::tab_positions() { if (o->visible()) selected = i; int wt = 0; int ht = 0; + Fl_Labeltype ot = o->labeltype(); + Fl_Align oa = o->align(); + if (ot == FL_NO_LABEL) { + o->labeltype(FL_NORMAL_LABEL); + } + o->align(tab_align()); o->measure_label(wt,ht); + o->labeltype(ot); + o->align(oa); tab_width[i] = wt + EXTRASPACE; tab_pos[i+1] = tab_pos[i] + tab_width[i] + BORDER; @@ -380,8 +388,13 @@ void Fl_Tabs::draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int what) { Fl_Boxtype bt = (o == push_ && !sel) ? fl_down(box()) : box(); Fl_Color bc = sel ? selection_color() : o->selection_color(); - // Save the label color + // Save the label color and label type Fl_Color oc = o->labelcolor(); + Fl_Labeltype ot = o->labeltype(); + + // Set a labeltype that really draws a label + if (ot == FL_NO_LABEL) + o->labeltype(FL_NORMAL_LABEL); // compute offsets to make selected tab look bigger int yofs = sel ? 0 : BORDER; @@ -398,7 +411,7 @@ void Fl_Tabs::draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int what) { // Draw the label using the current color... o->labelcolor(sel ? labelcolor() : o->labelcolor()); - o->draw_label(x1, y() + yofs, W, H - yofs, FL_ALIGN_CENTER); + o->draw_label(x1, y() + yofs, W, H - yofs, tab_align()); if (Fl::focus() == this && o->visible()) draw_focus(box(), x1, y(), W, H); @@ -425,8 +438,9 @@ void Fl_Tabs::draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int what) { } fl_draw_shortcut = prev_draw_shortcut; - // Restore the original label color + // Restore the original label color and label type o->labelcolor(oc); + o->labeltype(ot); } /** @@ -458,6 +472,7 @@ Fl_Tabs::Fl_Tabs(int X,int Y,int W, int H, const char *l) : tab_pos = 0; tab_width = 0; tab_count = 0; + tab_align_ = FL_ALIGN_CENTER; } Fl_Tabs::~Fl_Tabs() { |
