summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2012-04-22 13:40:02 +0000
committerGreg Ercolano <erco@seriss.com>2012-04-22 13:40:02 +0000
commitf58cd169c08a4be9ae07903a9e61b686bb7a75b6 (patch)
treea2a498a84c10cb1c8ba57f52f6511922aa8ce8a1 /src
parentdc6e8a5f8ae8c24bf7fb3aa0d702eb4415ace6b5 (diff)
Various mods for Fl_Tree
o Fix STR#2828 (E): {Vertical|Widget} Gap o Moved Fabien's reselected methods to Fl_Tree_Prefs, return method made const, doxygen, removed underbars from methods (to follow general API) o Widgets can now appear to the right of labels. This can be controlled with item_draw_mode(FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) o Cleaned up Fl_Tree_Item::draw(), Fl_Tree::draw() o New methods: marginbottom() -- [ABI feature] extra space below last tree element when scrolling widgetmarginleft() -- [ABI feature] space to left of widget usericonmarginleft() -- space to left of usericon labelmarginleft() -- space to left of label item_draw_mode() -- control how items, widget() are drawn o Updated Fl_Tree docs, tree-elements.png o test/tree: added sliders to test the above new features, added "open all" and "close all" buttons o Probably other stuff.. TODO: Fix "scroll-beyond-bottom" (STR#2796) TODO: Fix other items in STR#2828 git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9377 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tree.cxx179
-rw-r--r--src/Fl_Tree_Item.cxx292
-rw-r--r--src/Fl_Tree_Prefs.cxx12
3 files changed, 307 insertions, 176 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index 2d68a3037..8769578cc 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -102,7 +102,6 @@ Fl_Tree::Fl_Tree(int X, int Y, int W, int H, const char *L) : Fl_Group(X,Y,W,H,L
#if FLTK_ABI_VERSION >= 10302
// NEW
_lastselect = 0;
- _itemReselectMode = FL_TREE_SELECTABLE_ONCE;
#else
// OLD: data initialized static inside handle()
#endif
@@ -372,17 +371,25 @@ void Fl_Tree::draw() {
int cy = y() + Fl::box_dy(box());
int cw = w() - Fl::box_dw(box());
int ch = h() - Fl::box_dh(box());
- if (damage() & ~FL_DAMAGE_CHILD) { // redraw entire thing
+ {
// Handle group's bg
- Fl_Group::draw_box();
- Fl_Group::draw_label();
+ if ( damage() & ~FL_DAMAGE_CHILD) { // redraw entire widget?
+ Fl_Group::draw_box();
+ Fl_Group::draw_label();
+ }
if ( ! _root ) return;
// These values are changed during drawing
- // 'Y' will be the lowest point on the tree
+ // By end, 'Y' will be the lowest point on the tree
int X = cx + _prefs.marginleft();
int Y = cy + _prefs.margintop() - (_vscroll->visible() ? _vscroll->value() : 0);
int W = cw - _prefs.marginleft(); // - _prefs.marginright();
+ // Adjust root's X/W if connectors off
+ if (_prefs.connectorstyle() == FL_TREE_CONNECTOR_NONE) {
+ X -= _prefs.openicon()->w();
+ W += _prefs.openicon()->w();
+ }
int Ysave = Y;
+
fl_push_clip(cx,cy,cw,ch);
{
fl_font(_prefs.labelfont(), _prefs.labelsize());
@@ -393,53 +400,34 @@ void Fl_Tree::draw() {
fl_pop_clip();
// Show vertical scrollbar?
- int ydiff = (Y+_prefs.margintop())-Ysave; // ydiff=size of tree
- int ytoofar = (cy+ch) - Y; // ytoofar -- scrolled beyond bottom (e.g. stow)
-
- //printf("ydiff=%d ch=%d Ysave=%d ytoofar=%d value=%d\n",
- //int(ydiff),int(ch),int(Ysave),int(ytoofar), int(_vscroll->value()));
-
- if ( ytoofar > 0 ) ydiff += ytoofar;
- if ( Ysave<cy || ydiff > ch || int(_vscroll->value()) > 1 ) {
- _vscroll->visible();
-
- int scrollsize = _scrollbar_size ? _scrollbar_size : Fl::scrollbar_size();
- int sx = x()+w()-Fl::box_dx(box())-scrollsize;
- int sy = y()+Fl::box_dy(box());
- int sw = scrollsize;
- int sh = h()-Fl::box_dh(box());
- _vscroll->show();
- _vscroll->range(0.0,ydiff-ch);
- _vscroll->resize(sx,sy,sw,sh);
- _vscroll->slider_size(float(ch)/float(ydiff));
- } else {
- _vscroll->Fl_Slider::value(0);
- _vscroll->hide();
- }
- }
- // Draw children
- fl_push_clip(cx,cy,cw-(_vscroll->visible()?_vscroll->w():0),ch);
- // Similar to Fl_Group::draw(), but optimized to ignore drawing
- // items outside the viewport.
- // TODO: Suggest Fl_Group::draw() do this if clip_children() is enabled.
- {
- Fl_Widget*const* a = Fl_Group::array();
- if (damage() & ~FL_DAMAGE_CHILD) { // redraw the entire thing:
- for (int i=Fl_Group::children(); i--;) {
- Fl_Widget& o = **a++;
- if ( (o.y()+o.h()) < y() || (o.y() > (y()+h())) ) continue;
- Fl_Group::draw_child(o);
- Fl_Group::draw_outside_label(o);
- }
- } else { // only redraw the children that need it:
- for (int i=Fl_Group::children(); i--;) {
- Fl_Widget& o = **a++;
- if ( (o.y()+o.h()) < y() || (o.y() > (y()+h())) ) continue;
- Fl_Group::update_child(o);
+ {
+#if FLTK_ABI_VERSION >= 10302
+ // NEW
+ int SY = Y + _prefs.marginbottom();
+#else
+ // OLD
+ int SY = Y;
+#endif
+ int ydiff = (SY+_prefs.margintop())-Ysave; // ydiff=size of tree
+ int ytoofar = (cy+ch) - SY; // ytoofar -- scrolled beyond bottom (e.g. stow)
+ if ( ytoofar > 0 ) ydiff += ytoofar;
+ if ( Ysave<cy || ydiff>ch || int(_vscroll->value())>1 ) {
+ _vscroll->visible();
+ int scrollsize = _scrollbar_size ? _scrollbar_size : Fl::scrollbar_size();
+ int sx = x()+w()-Fl::box_dx(box())-scrollsize;
+ int sy = y()+Fl::box_dy(box());
+ int sw = scrollsize;
+ int sh = h()-Fl::box_dh(box());
+ _vscroll->show();
+ _vscroll->resize(sx,sy,sw,sh);
+ _vscroll->slider_size(float(ch)/float(ydiff));
+ _vscroll->range(0.0,ydiff-ch);
+ } else {
+ _vscroll->Fl_Slider::value(0);
+ _vscroll->hide();
}
}
}
- fl_pop_clip();
draw_child(*_vscroll); // draw scroll last
}
@@ -1399,6 +1387,38 @@ void Fl_Tree::margintop(int val) {
redraw();
}
+#if FLTK_ABI_VERSION >= 10302
+/// Get the amount of white space (in pixels) that should appear
+/// below the last visible item when the vertical scroller is scrolled to the bottom.
+///
+int Fl_Tree::marginbottom() const {
+ return(_prefs.marginbottom());
+}
+
+/// Sets the amount of white space (in pixels) that should appear
+/// below the last visible item when the vertical scroller is scrolled to the bottom.
+///
+void Fl_Tree::marginbottom(int val) {
+ _prefs.marginbottom(val);
+ redraw();
+}
+#endif
+
+/// Get the amount of white space (in pixels) that should appear
+/// between items in the tree.
+///
+int Fl_Tree::linespacing() const {
+ return(_prefs.linespacing());
+}
+
+/// Sets the amount of white space (in pixels) that should appear
+/// between items in the tree.
+///
+void Fl_Tree::linespacing(int val) {
+ _prefs.linespacing(val);
+ redraw();
+}
+
/// Get the amount of white space (in pixels) that should appear
/// below an open child tree's contents.
///
@@ -1413,6 +1433,41 @@ void Fl_Tree::openchild_marginbottom(int val) {
_prefs.openchild_marginbottom(val);
redraw();
}
+/// Get the amount of white space (in pixels) that should appear
+/// to the left of the usericon.
+int Fl_Tree::usericonmarginleft() const {
+ return(_prefs.usericonmarginleft());
+}
+/// Set the amount of white space (in pixels) that should appear
+/// to the left of the usericon.
+void Fl_Tree::usericonmarginleft(int val) {
+ _prefs.usericonmarginleft(val);
+ redraw();
+}
+/// Get the amount of white space (in pixels) that should appear
+/// to the left of the label text.
+int Fl_Tree::labelmarginleft() const {
+ return(_prefs.labelmarginleft());
+}
+/// Set the amount of white space (in pixels) that should appear
+/// to the left of the label text.
+void Fl_Tree::labelmarginleft(int val) {
+ _prefs.labelmarginleft(val);
+ redraw();
+}
+#if FLTK_ABI_VERSION >= 10302
+/// Get the amount of white space (in pixels) that should appear
+/// to the left of the child fltk widget (if any).
+int Fl_Tree::widgetmarginleft() const {
+ return(_prefs.widgetmarginleft());
+}
+/// Set the amount of white space (in pixels) that should appear
+/// to the left of the child fltk widget (if any).
+void Fl_Tree::widgetmarginleft(int val) {
+ _prefs.widgetmarginleft(val);
+ redraw();
+}
+#endif
/// Gets the width of the horizontal connection lines (in pixels)
/// that appear to the left of each tree item's label.
@@ -1570,6 +1625,32 @@ void Fl_Tree::selectmode(Fl_Tree_Select val) {
_prefs.selectmode(val);
}
+#if FLTK_ABI_VERSION >= 10302
+/// Returns the current item re/selection mode
+Fl_Tree_Item_Reselect_Mode Fl_Tree::item_reselect_mode() const {
+ return(_prefs.item_reselect_mode());
+}
+
+/// Sets the item re/selection mode
+void Fl_Tree::item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode) {
+ _prefs.item_reselect_mode(mode);
+}
+
+/// Get the 'item draw mode' used for the tree
+Fl_Tree_Item_Draw_Mode Fl_Tree::item_draw_mode() const {
+ return(_prefs.item_draw_mode());
+}
+
+/// Set the 'item draw mode' used for the tree to \p val.
+/// This affects how items in the tree are drawn,
+/// such as when a widget() is defined.
+/// See Fl_Tree_Item_Draw_Mode for possible values.
+///
+void Fl_Tree::item_draw_mode(Fl_Tree_Item_Draw_Mode val) {
+ _prefs.item_draw_mode(val);
+}
+#endif
+
/// See if \p item is currently displayed on-screen (visible within the widget).
/// This can be used to detect if the item is scrolled off-screen.
/// Checks to see if the item's vertical position is within the top and bottom
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index 1b28602c9..ea91092fb 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -26,6 +26,7 @@
//
// http://www.fltk.org/str.php
//
+/////////////////////////////////////////////////////////////////////////// 80 /
// Was the last event inside the specified xywh?
static int event_inside(const int xywh[4]) {
@@ -556,6 +557,25 @@ static void draw_item_focus(Fl_Boxtype B, Fl_Color C, int X, int Y, int W, int H
#endif
}
+/// Return the item's 'visible' height
+int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) {
+ if ( ! _visible ) return(0);
+ int H = 0;
+ if ( _label ) {
+ fl_font(_labelfont, _labelsize); // fldescent() needs this :/
+ H = _labelsize + fl_descent() + 1; // at least one pixel space below descender
+ }
+ if ( has_children() && prefs.openicon() && H<prefs.openicon()->h() )
+ H = prefs.openicon()->h();
+ if ( usericon() && H<usericon()->h() )
+ H = usericon()->h();
+ // NO: we don't use widget's height, we force it to match ours
+ //if ( widget() && widget()->visible() && H<widget()->h() )
+ // H = widget()->h();
+ H += prefs.linespacing();
+ return(H);
+}
+
/// Draw this item and its children.
void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
Fl_Tree_Item *itemfocus,
@@ -563,145 +583,167 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
if ( ! _visible ) return;
int tree_top = tree->y();
int tree_bot = tree_top + tree->h();
- fl_font(_labelfont, _labelsize);
- int H = _labelsize;
- if(usericon() && H < usericon()->h()) H = usericon()->h();
- H += prefs.linespacing() + fl_descent();
- // adjust horizontally if we draw no connecting lines
- if ( is_root() && prefs.connectorstyle() == FL_TREE_CONNECTOR_NONE ) {
- X -= prefs.openicon()->w();
- W += prefs.openicon()->w();
- }
- // Colors, fonts
- Fl_Color fg = _selected ? fl_contrast(_labelfgcolor, tree->selection_color())
- : _active ? _labelfgcolor
- : fl_inactive(_labelfgcolor);
- Fl_Color bg = _selected ? _active ? tree->selection_color()
- : fl_inactive(tree->selection_color())
- : _labelbgcolor;
+ int H = calc_item_height(prefs);
+
// Update the xywh of this item
_xywh[0] = X;
_xywh[1] = Y;
_xywh[2] = W;
_xywh[3] = H;
- // Text size
- int textw=0, texth=0;
- fl_measure(_label, textw, texth, 0);
- int textycenter = Y+(H/2);
+
+ // Determine collapse icon's xywh
+ // Note: calculate collapse icon's xywh for possible mouse click detection.
+ // We don't care about items clipped off the viewport; they won't get mouse events.
+ //
+ int item_y_center = Y+(H/2);
int &icon_w = _collapse_xywh[2] = prefs.openicon()->w();
int &icon_x = _collapse_xywh[0] = X + (icon_w + prefs.connectorwidth())/2 - 3;
- int &icon_y = _collapse_xywh[1] = textycenter - (prefs.openicon()->h()/2);
+ int &icon_y = _collapse_xywh[1] = item_y_center - (prefs.openicon()->h()/2);
_collapse_xywh[3] = prefs.openicon()->h();
+
// Horizontal connector values
- int hstartx = X+icon_w/2-1;
- int hendx = hstartx + prefs.connectorwidth();
- int hcenterx = X + icon_w + ((hendx - (X + icon_w)) / 2);
-
- // See if we should draw this item
- // If this item is root, and showroot() is disabled, don't draw.
- // 'clipped' is an optimization to prevent drawing anything offscreen.
+ // XXX: Must calculate these even if(clipped) because 'draw children' code (below)
+ // needs hconn_x_center value. (Otherwise, these calculations could be 'clipped')
//
- char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1;
- char clipped = ((Y+H) < tree_top) || (Y>tree_bot) ? 1 : 0;
- if ( drawthis ) {
- // Draw connectors
- if ( prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) {
- // Horiz connector between center of icon and text
- // if this is root, the connector should not dangle in thin air on the left
- if (is_root()) {
- if (!clipped) draw_horizontal_connector(hcenterx, hendx, textycenter, prefs);
- } else {
- if (!clipped) draw_horizontal_connector(hstartx, hendx, textycenter, prefs);
- }
- if ( has_children() && is_open() ) {
- // Small vertical line down to children
- if (!clipped) draw_vertical_connector(hcenterx, textycenter, Y+H, prefs);
- }
- // Connectors for last child
- if ( ! is_root() ) {
- if ( lastchild ) {
- if (!clipped) draw_vertical_connector(hstartx, Y, textycenter, prefs);
- } else {
- if (!clipped) draw_vertical_connector(hstartx, Y, Y+H, prefs);
- }
- }
- }
- // Draw collapse icon
- if ( has_children() && prefs.showcollapse() ) {
- // Draw icon image
- if ( is_open() ) {
- if (!clipped) prefs.closeicon()->draw(icon_x,icon_y);
- } else {
- if (!clipped) prefs.openicon()->draw(icon_x,icon_y);
- }
- }
- // Background for this item
- int cw1 = icon_w+prefs.connectorwidth()/2, cw2 = prefs.connectorwidth();
- int cwidth = cw1>cw2 ? cw1 : cw2;
- int &bx = _label_xywh[0] = X+(icon_w/2-1+cwidth);
- int &by = _label_xywh[1] = Y;
- int &bw = _label_xywh[2] = W-(icon_w/2-1+cwidth);
- int &bh = _label_xywh[3] = H;
- // Draw bg only if different from tree's bg
- if ( bg != tree->color() || is_selected() ) {
- if ( is_selected() ) {
- // Selected? Use selectbox() style
- if (!clipped) fl_draw_box(prefs.selectbox(), bx, by, bw, bh, bg);
- } else {
- // Not Selected? use plain filled rectangle
- if (!clipped) {
- fl_color(bg);
- fl_rectf(bx, by, bw, bh);
- }
- }
+ int hconn_x = X+icon_w/2-1;
+ int hconn_x2 = hconn_x + prefs.connectorwidth();
+ int hconn_x_center = X + icon_w + ((hconn_x2 - (X + icon_w)) / 2);
+ int cw1 = icon_w+prefs.connectorwidth()/2, cw2 = prefs.connectorwidth();
+ int conn_w = cw1>cw2 ? cw1 : cw2;
+
+ // Background position
+ int &bg_x = _label_xywh[0] = X+(icon_w/2-1+conn_w);
+ int &bg_y = _label_xywh[1] = Y;
+ int &bg_w = _label_xywh[2] = W-(icon_w/2-1+conn_w);
+ int &bg_h = _label_xywh[3] = H;
+
+ // Usericon position
+ int uicon_x = bg_x + ( (usericon() || prefs.usericon()) ? prefs.usericonmarginleft() : 0);
+ int uicon_w = usericon() ? usericon()->w() : prefs.usericon() ? prefs.usericon()->w() : 0;
+
+ // Label position
+ int label_x = uicon_x + uicon_w + (_label ? prefs.labelmarginleft() : 0);
+
+ // Recalc widget position
+ // Do this whether clipped or not, so that when scrolled,
+ // the widgets move to appropriate 'offscreen' positions
+ // (so that they don't get mouse events, etc)
+ //
+ if ( widget() ) {
+ int wx = label_x;
+ int wy = bg_y;
+ int ww = widget()->w(); // use widget's width
+ int wh = H; // lock widget's height to item height
+#if FLTK_ABI_VERSION >= 10302
+ if ( _label && prefs.item_draw_mode() == FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET ) {
+#else
+ if ( _label && !widget() ) { // back compat: don't draw label if widget() present
+#endif
+ fl_font(_labelfont, _labelsize); // fldescent() needs this
+ int dx,dy,lw,lh;
+ fl_text_extents(_label,dx,dy,lw,lh);
+#if FLTK_ABI_VERSION >= 10302
+ // NEW
+ wx += (lw + prefs.widgetmarginleft());
+#else
+ // OLD
+ wx += (lw + 3);
+#endif
}
- // Draw user icon (if any)
- int useroff = (icon_w/2-1+cwidth);
- if ( usericon() ) {
- // Item has user icon? Use it
- useroff += prefs.usericonmarginleft();
- icon_y = textycenter - (usericon()->h() >> 1);
- if (!clipped) usericon()->draw(X+useroff,icon_y);
- useroff += usericon()->w();
- } else if ( prefs.usericon() ) {
- // Prefs has user icon? Use it
- useroff += prefs.usericonmarginleft();
- icon_y = textycenter - (prefs.usericon()->h() >> 1);
- if (!clipped) prefs.usericon()->draw(X+useroff,icon_y);
- useroff += prefs.usericon()->w();
+ if ( widget()->x() != wx || widget()->y() != wy ||
+ widget()->w() != ww || widget()->h() != wh ) {
+ widget()->resize(wx,wy,ww,wh); // we'll handle redraw below
}
- useroff += prefs.labelmarginleft();
- // Draw label
- if ( widget() ) {
- // Widget? Draw it
- int lx = X+useroff;
- int ly = by;
- int lw = widget()->w();
- int lh = bh;
- if ( widget()->x() != lx || widget()->y() != ly ||
- widget()->w() != lw || widget()->h() != lh ) {
- widget()->resize(lx, ly, lw, lh); // fltk will handle drawing this
+ }
+ char clipped = ((Y+H) < tree_top) || (Y>tree_bot) ? 1 : 0;
+ char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1;
+ if ( !clipped ) {
+ Fl_Color fg = _selected ? fl_contrast(_labelfgcolor, tree->selection_color())
+ : _active ? _labelfgcolor
+ : fl_inactive(_labelfgcolor);
+ Fl_Color bg = _selected ? _active ? tree->selection_color()
+ : fl_inactive(tree->selection_color())
+ : _labelbgcolor;
+ // See if we should draw this item
+ // If this item is root, and showroot() is disabled, don't draw.
+ // 'clipped' is an optimization to prevent drawing anything offscreen.
+ //
+ if ( drawthis ) { // draw this item at all?
+ if ( tree->damage() & ~FL_DAMAGE_CHILD ) { // non-child damage?
+ // Draw connectors
+ if ( prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) {
+ // Horiz connector between center of icon and text
+ // if this is root, the connector should not dangle in thin air on the left
+ if (is_root()) draw_horizontal_connector(hconn_x_center, hconn_x2, item_y_center, prefs);
+ else draw_horizontal_connector(hconn_x, hconn_x2, item_y_center, prefs);
+ // Small vertical line down to children
+ if ( has_children() && is_open() )
+ draw_vertical_connector(hconn_x_center, item_y_center, Y+H, prefs);
+ // Connectors for last child
+ if ( !is_root() ) {
+ if ( lastchild ) draw_vertical_connector(hconn_x, Y, item_y_center, prefs);
+ else draw_vertical_connector(hconn_x, Y, Y+H, prefs);
+ }
+ }
+ // Draw collapse icon
+ if ( has_children() && prefs.showcollapse() ) {
+ // Draw icon image
+ if ( is_open() ) {
+ prefs.closeicon()->draw(icon_x,icon_y);
+ } else {
+ prefs.openicon()->draw(icon_x,icon_y);
+ }
+ }
+ // Background for this item
+ // Draw bg only if different from tree's bg
+ if ( bg != tree->color() || is_selected() ) {
+ if ( is_selected() ) { // Selected? Use selectbox() style
+ fl_draw_box(prefs.selectbox(),bg_x,bg_y,bg_w,bg_h,bg);
+ } else { // Not Selected? use plain filled rectangle
+ fl_color(bg);
+ fl_rectf(bg_x,bg_y,bg_w,bg_h);
+ }
+ if ( widget() ) widget()->damage(FL_DAMAGE_ALL); // if there's a child widget, we just damaged it
+ }
+ // Draw user icon (if any)
+ if ( usericon() ) {
+ // Item has user icon? Use it
+ int uicon_y = item_y_center - (usericon()->h() >> 1);
+ usericon()->draw(uicon_x,uicon_y);
+ } else if ( prefs.usericon() ) {
+ // Prefs has user icon? Use it
+ int uicon_y = item_y_center - (prefs.usericon()->h() >> 1);
+ prefs.usericon()->draw(uicon_x,uicon_y);
+ }
+ // Draw label
+#if FLTK_ABI_VERSION >= 10302
+ if ( _label &&
+ ( !widget() || prefs.item_draw_mode() ==
+ FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) {
+#else
+ if ( _label && !widget() ) { // back compat: don't draw label if widget() present
+#endif
+ int label_y = Y+(H/2)+(_labelsize/2)-fl_descent()/2;
+ fl_color(fg);
+ fl_font(_labelfont, _labelsize);
+ fl_draw(_label, label_x, label_y);
+ }
+ } // end non-child damage
+ // Draw child FLTK widget?
+ if ( widget() && widget()->damage() ) {
+ widget()->draw();
}
- } else {
- // No label widget? Draw text label
- if ( _label && !clipped ) {
- fl_color(fg);
- fl_draw(_label, X+useroff, Y+H-fl_descent()-1);
+ // Draw focus box around item's bg last
+ if ( this == itemfocus && Fl::visible_focus() && Fl::focus() == tree) {
+ draw_item_focus(FL_NO_BOX,bg,bg_x+1,bg_y+1,bg_w-1,bg_h-1);
}
- }
- if ( !clipped &&
- this == itemfocus &&
- Fl::visible_focus() &&
- Fl::focus() == tree) {
- // Draw focus box around this item
- draw_item_focus(FL_NO_BOX,bg,bx+1,by+1,bw-1,bh-1);
- }
- Y += H;
- } // end drawthis
- // Draw children
+ } // end drawthis
+ } // end clipped
+ if ( drawthis ) Y += H; // adjust Y (even if clipped)
+ // Draw child items (if any)
if ( has_children() && is_open() ) {
- int child_x = drawthis ? // offset children to right,
- (hcenterx - (icon_w/2) + 1) : X; // unless didn't drawthis
+ int child_x = drawthis ? (hconn_x_center - (icon_w/2) + 1) // offset children to right,
+ : X; // unless didn't drawthis
int child_w = W - (child_x-X);
int child_y_start = Y;
for ( int t=0; t<children(); t++ ) {
@@ -715,7 +757,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
// Special 'clipped' calculation. (intentional variable shadowing)
int clipped = ((child_y_start < tree_top) && (Y < tree_top)) ||
((child_y_start > tree_bot) && (Y > tree_bot));
- if (!clipped) draw_vertical_connector(hstartx, child_y_start, Y, prefs);
+ if (!clipped) draw_vertical_connector(hconn_x, child_y_start, Y, prefs);
}
}
}
diff --git a/src/Fl_Tree_Prefs.cxx b/src/Fl_Tree_Prefs.cxx
index b8b640d4a..c32262d5b 100644
--- a/src/Fl_Tree_Prefs.cxx
+++ b/src/Fl_Tree_Prefs.cxx
@@ -125,11 +125,15 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_labelsize = FL_NORMAL_SIZE;
_marginleft = 6;
_margintop = 3;
- //_marginright = 3;
- //_marginbottom = 3;
+#if FLTK_ABI_VERSION >= 10302
+ _marginbottom = 20;
+#endif
_openchild_marginbottom = 0;
_usericonmarginleft = 3;
_labelmarginleft = 3;
+#if FLTK_ABI_VERSION >= 10302
+ _widgetmarginleft = 3;
+#endif
_linespacing = 0;
_labelfgcolor = FL_BLACK;
_labelbgcolor = FL_WHITE;
@@ -148,6 +152,10 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_sortorder = FL_TREE_SORT_NONE;
_selectbox = FL_FLAT_BOX;
_selectmode = FL_TREE_SELECT_SINGLE;
+#if FLTK_ABI_VERSION >= 10302
+ _itemreselectmode = FL_TREE_SELECTABLE_ONCE;
+ _itemdrawmode = FL_TREE_ITEM_DRAW_WIDGET_ONLY;
+#endif
// Let fltk's current 'scheme' affect defaults
if ( Fl::scheme() ) {
if ( strcmp(Fl::scheme(), "gtk+") == 0 ) {