summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2012-04-27 02:03:48 +0000
committerGreg Ercolano <erco@seriss.com>2012-04-27 02:03:48 +0000
commit474feee1db323f45fb121b02d76e776cb5c7c2f1 (patch)
tree9782a4a5eec8b676e75cf34a83342f6d9a2a1f6d /src
parentfa60da1ca74c8ed9c037ba41dca82f59c31f50a5 (diff)
o Added FL_TREE_ITEM_HEIGHT_FROM_WIDGET option to item_draw_mode()
to allow widgets to control the size of items in the tree (instead of vice versa). o Added item_draw_mode(int) to allow for easier bitflag maintenance, since enums don't seem to be typesafe yet. o Tree demo modified to demonstrate this feature. An important feature for adding large widgets to tree items. Will probably add an example, 'tree-of-tables' to demo this usage. o Small doc fixes. o Had to rename FL_TREE_ITEM_DRAW_WIDGET_ONLY to FL_TREE_ITEM_DRAW_DEFAULT. Its meaning for the bit fields changed when new bit fields were added. (The prev name just didn't make sense in the new context. Since it was just a few svn commits old and an unreleased ABI feature, it shouldn't affect anyone not in R&D) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9404 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tree.cxx5
-rw-r--r--src/Fl_Tree_Item.cxx26
-rw-r--r--src/Fl_Tree_Prefs.cxx2
3 files changed, 23 insertions, 10 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index 48eca8460..e1ab1baf0 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -554,7 +554,7 @@ Fl_Tree_Item* Fl_Tree::add(const char *path) {
return(item);
}
-/// Add a new child to a tree-item.
+/// Add a new child to a specific item in the tree.
///
/// \param[in] item The existing item to add new child to. Must not be NULL.
/// \param[in] name The label for the new item
@@ -1724,6 +1724,9 @@ Fl_Tree_Item_Draw_Mode Fl_Tree::item_draw_mode() const {
void Fl_Tree::item_draw_mode(Fl_Tree_Item_Draw_Mode val) {
_prefs.item_draw_mode(val);
}
+void Fl_Tree::item_draw_mode(int val) {
+ _prefs.item_draw_mode(Fl_Tree_Item_Draw_Mode(val));
+}
#endif
/// See if \p item is currently displayed on-screen (visible within the widget).
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index 39e061d64..79ab11ad4 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -564,9 +564,16 @@ int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) const {
if ( ! _visible ) return(0);
int H = 0;
if ( _label ) {
- fl_font(_labelfont, _labelsize); // fldescent() needs this :/
+ fl_font(_labelfont, _labelsize); // fl_descent() needs this :/
H = _labelsize + fl_descent() + 1; // at least one pixel space below descender
}
+#if FLTK_ABI_VERSION >= 10302
+ if ( widget() &&
+ (prefs.item_draw_mode() & FL_TREE_ITEM_HEIGHT_FROM_WIDGET) &&
+ H < widget()->h()) {
+ H = widget()->h();
+ }
+#endif
if ( has_children() && prefs.openicon() && H<prefs.openicon()->h() )
H = prefs.openicon()->h();
if ( usericon() && H<usericon()->h() )
@@ -632,15 +639,18 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
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 ) {
+ int wh = (prefs.item_draw_mode() & FL_TREE_ITEM_HEIGHT_FROM_WIDGET)
+ ? widget()->h() : H;
+ if ( _label &&
+ (prefs.item_draw_mode() & FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) {
#else
+ int wh = H; // lock widget's height to item height
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);
+ int lw=0, lh=0;
+ fl_measure(_label,lw,lh); // get box around text (including white space)
#if FLTK_ABI_VERSION >= 10302
// NEW
wx += (lw + prefs.widgetmarginleft());
@@ -717,14 +727,14 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
// Draw label
#if FLTK_ABI_VERSION >= 10302
if ( _label &&
- ( !widget() || prefs.item_draw_mode() ==
- FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) {
+ ( !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);
+ int label_y = Y+(H/2)+(_labelsize/2)-fl_descent()/2;
fl_draw(_label, label_x, label_y);
}
} // end non-child damage
diff --git a/src/Fl_Tree_Prefs.cxx b/src/Fl_Tree_Prefs.cxx
index c32262d5b..7f4a5337b 100644
--- a/src/Fl_Tree_Prefs.cxx
+++ b/src/Fl_Tree_Prefs.cxx
@@ -154,7 +154,7 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_selectmode = FL_TREE_SELECT_SINGLE;
#if FLTK_ABI_VERSION >= 10302
_itemreselectmode = FL_TREE_SELECTABLE_ONCE;
- _itemdrawmode = FL_TREE_ITEM_DRAW_WIDGET_ONLY;
+ _itemdrawmode = FL_TREE_ITEM_DRAW_DEFAULT;
#endif
// Let fltk's current 'scheme' affect defaults
if ( Fl::scheme() ) {