Fl_Tree API breaking changes (we haven't released 1.3.0 yet..):

Fl_Tree::labelsize() -> item_labelsize()            -- TO AVOID COLLISION WITH Fl_Widget::labelsize()!
    Fl_Tree::labelfont() -> item_labelfont()            -- TO AVOID COLLISION WITH Fl_Widget::labelfont()!

Fl_Tree_Prefs (internal) changes:
    Fl_Tree_Prefs::fgcolor() -> labelfgcolor()          -- for consistency with above
    Fl_Tree_Prefs::bgcolor() -> labelbgcolor()          -- for consistency with above
    Fl_Tree_Prefs::selectcolor() removed                -- uses Fl_Widget::selection_color() instead
    Fl_Tree_Prefs::inactivecolor() removed              -- was unused; inactive color procedurally calculated

Other Fl_Tree mods:
    o Fixed bug with select_all(item) and deselect_all(item)
      (they were not limiting themselves to children of specified item)
    o Fixed bug with item not drawing in its /own/ bgcolor when item selected
    o Fl_Tree uses the Fl_Widget::selection_color()
    o All methods that deal with 'font types' changed int -> Fl_Font
    o All methods that deal with 'font sizes' changed int -> Fl_Fontsize
    o Added needed methods to Fl_Tree for accessing colors:

        item_labelfgcolor()     -- access default fg color used for new items
        item_labelbgcolor()     -- access default bg color used for new items
        tree_connectorcolor()   -- access the connector line color

    o Small doxygen comment adjustments and general clarifications
    o test/tree demo modified to include testing of new label color methods, cleanup



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8340 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Greg Ercolano
2011-01-30 20:22:06 +00:00
parent 31db787583
commit 2c5006563f
7 changed files with 823 additions and 556 deletions
+39 -16
View File
@@ -97,6 +97,7 @@
/// next_selected_item(). /// next_selected_item().
/// Items can be found by their pathname using find_item(const char*), /// Items can be found by their pathname using find_item(const char*),
/// and an item's pathname can be found with item_pathname(). /// and an item's pathname can be found with item_pathname().
/// The selected items' colors are controlled by selection_color() (inherited from Fl_Widget).
/// ///
/// The tree can have different selection behaviors controlled by selectmode(). /// The tree can have different selection behaviors controlled by selectmode().
/// ///
@@ -604,32 +605,53 @@ public:
///////////////////////////////// /////////////////////////////////
/// Get the default label fontsize used for creating new items. /// Get the default label fontsize used for creating new items.
int labelsize() const { Fl_Fontsize item_labelsize() const {
return(_prefs.labelsize()); return(_prefs.labelsize());
} }
/// Set the default label font size used for creating new items. /// Set the default label font size used for creating new items.
/// To change the font size on a per-item basis, use Fl_Tree_Item::labelsize(int) /// To change the font size on a per-item basis, use Fl_Tree_Item::labelsize(Fl_Fontsize)
/// ///
void labelsize(int val) { void item_labelsize(Fl_Fontsize val) {
_prefs.labelsize(val); _prefs.labelsize(val);
} }
/// Get the default font face used for creating new items.
/// Get the default font face used for item's labels when new items are created. Fl_Font item_labelfont() const {
///
/// Don't use this if you want to change an existing label() size; use
/// item->labelfont() instead.
///
int labelfont() const {
return(_prefs.labelfont()); return(_prefs.labelfont());
} }
/// Set the default font face used for item's labels when new items are created. /// Set the default font face used for creating new items.
/// To change the font face on a per-item basis, use Fl_Tree_Item::labelfont(Fl_Font)
/// ///
/// Don't use this if you want to change an existing label() size; use void item_labelfont(Fl_Font val) {
/// item->labelfont(int) instead.
///
void labelfont(int val) {
_prefs.labelfont(val); _prefs.labelfont(val);
} }
/// Get the default label foreground color used for creating new items.
Fl_Color item_labelfgcolor(void) const {
return(_prefs.labelfgcolor());
}
/// Set the default label foreground color used for creating new items.
/// To change the foreground color on a per-item basis, use Fl_Tree_Item::labelfgcolor(Fl_Color)
///
void item_labelfgcolor(Fl_Color val) {
_prefs.labelfgcolor(val);
}
/// Get the default label background color used for creating new items.
Fl_Color item_labelbgcolor(void) const {
return(_prefs.labelbgcolor());
}
/// Set the default label background color used for creating new items.
/// To change the background color on a per-item basis, use Fl_Tree_Item::labelbgcolor(Fl_Color)
///
void item_labelbgcolor(Fl_Color val) {
_prefs.labelbgcolor(val);
}
/// Get the connector color used for tree connection lines.
Fl_Color connectorcolor() const {
return(_prefs.connectorcolor());
}
/// Set the connector color used for tree connection lines.
void connectorcolor(Fl_Color val) {
_prefs.connectorcolor(val);
}
/// Get the amount of white space (in pixels) that should appear /// Get the amount of white space (in pixels) that should appear
/// between the widget's left border and the tree's contents. /// between the widget's left border and the tree's contents.
/// ///
@@ -682,7 +704,8 @@ public:
_prefs.connectorwidth(val); _prefs.connectorwidth(val);
redraw(); redraw();
} }
/// Returns the Fl_Image being used as the default user icon for newly created items. /// Returns the Fl_Image being used as the default user icon for all
/// newly created items.
/// Returns zero if no icon has been set, which is the default. /// Returns zero if no icon has been set, which is the default.
/// ///
Fl_Image *usericon() const { Fl_Image *usericon() const {
+6 -6
View File
@@ -58,8 +58,8 @@
/// ///
class FL_EXPORT Fl_Tree_Item { class FL_EXPORT Fl_Tree_Item {
const char *_label; // label (memory managed) const char *_label; // label (memory managed)
int _labelfont; // label's font face Fl_Font _labelfont; // label's font face
int _labelsize; // label's font size Fl_Fontsize _labelsize; // label's font size
Fl_Color _labelfgcolor; // label's fg color Fl_Color _labelfgcolor; // label's fg color
Fl_Color _labelbgcolor; // label's bg color Fl_Color _labelbgcolor; // label's bg color
char _open; // item is open? char _open; // item is open?
@@ -99,19 +99,19 @@ public:
inline void* user_data() const { return _userdata; } inline void* user_data() const { return _userdata; }
/// Set item's label font face. /// Set item's label font face.
void labelfont(int val) { void labelfont(Fl_Font val) {
_labelfont = val; _labelfont = val;
} }
/// Get item's label font face. /// Get item's label font face.
int labelfont() const { Fl_Font labelfont() const {
return(_labelfont); return(_labelfont);
} }
/// Set item's label font size. /// Set item's label font size.
void labelsize(int val) { void labelsize(Fl_Fontsize val) {
_labelsize = val; _labelsize = val;
} }
/// Get item's label font size. /// Get item's label font size.
int labelsize() const { Fl_Fontsize labelsize() const {
return(_labelsize); return(_labelsize);
} }
/// Set item's label foreground text color. /// Set item's label foreground text color.
+22 -40
View File
@@ -83,8 +83,8 @@ enum Fl_Tree_Select {
/// instead of trying to accessing tree's preferences settings directly. /// instead of trying to accessing tree's preferences settings directly.
/// ///
class FL_EXPORT Fl_Tree_Prefs { class FL_EXPORT Fl_Tree_Prefs {
int _labelfont; // label's font face Fl_Font _labelfont; // label's font face
int _labelsize; // label's font size Fl_Fontsize _labelsize; // label's font size
int _margintop; // -- int _margintop; // --
int _marginleft; // |- tree's margins int _marginleft; // |- tree's margins
//int _marginright; // | //int _marginright; // |
@@ -95,10 +95,8 @@ class FL_EXPORT Fl_Tree_Prefs {
int _connectorwidth; // connector width (right of open/close icon) int _connectorwidth; // connector width (right of open/close icon)
int _linespacing; // vertical space between lines int _linespacing; // vertical space between lines
// Colors // Colors
Fl_Color _fgcolor; // label's foreground color Fl_Color _labelfgcolor; // label's foreground color
Fl_Color _bgcolor; // background color Fl_Color _labelbgcolor; // background color
Fl_Color _selectcolor; // selection color
Fl_Color _inactivecolor; // inactive color
Fl_Color _connectorcolor; // connector dotted line color Fl_Color _connectorcolor; // connector dotted line color
Fl_Tree_Connector _connectorstyle; // connector line style Fl_Tree_Connector _connectorstyle; // connector line style
Fl_Image *_openimage; // the 'open' icon [+] Fl_Image *_openimage; // the 'open' icon [+]
@@ -116,19 +114,19 @@ public:
// Labels // Labels
//////////////////////////// ////////////////////////////
/// Return the label's font. /// Return the label's font.
inline int labelfont() const { inline Fl_Font labelfont() const {
return(_labelfont); return(_labelfont);
} }
/// Set the label's font to \p val. /// Set the label's font to \p val.
inline void labelfont(int val) { inline void labelfont(Fl_Font val) {
_labelfont = val; _labelfont = val;
} }
/// Return the label's size in pixels. /// Return the label's size in pixels.
inline int labelsize() const { inline Fl_Fontsize labelsize() const {
return(_labelsize); return(_labelsize);
} }
/// Set the label's size in pixels to \p val. /// Set the label's size in pixels to \p val.
inline void labelsize(int val) { inline void labelsize(Fl_Fontsize val) {
_labelsize = val; _labelsize = val;
} }
@@ -204,50 +202,34 @@ public:
// Colors and Styles // Colors and Styles
//////////////////////////// ////////////////////////////
/// Get the default label foreground color /// Get the default label foreground color
inline Fl_Color fgcolor() const { inline Fl_Color labelfgcolor() const {
return(_fgcolor); return(_labelfgcolor);
} }
/// Set the default label foreground color /// Set the default label foreground color
inline void fgcolor(Fl_Color val) { inline void labelfgcolor(Fl_Color val) {
_fgcolor = val; _labelfgcolor = val;
} }
/// Get the default label background color /// Get the default label background color
inline Fl_Color bgcolor() const { inline Fl_Color labelbgcolor() const {
return(_bgcolor); return(_labelbgcolor);
} }
/// Set the default label background color /// Set the default label background color
inline void bgcolor(Fl_Color val) { inline void labelbgcolor(Fl_Color val) {
_bgcolor = val; _labelbgcolor = val;
} }
/// Get the default selection color /// Get the connector color used for tree connection lines.
inline Fl_Color selectcolor() const {
return(_selectcolor);
}
/// Set the default selection color
inline void selectcolor(Fl_Color val) {
_selectcolor = val;
}
/// Get the default inactive color
inline Fl_Color inactivecolor() const {
return(_inactivecolor);
}
/// Set the default inactive color
inline void inactivecolor(Fl_Color val) {
_inactivecolor = val;
}
/// Get the connector color; the color used for tree connection lines
inline Fl_Color connectorcolor() const { inline Fl_Color connectorcolor() const {
return(_connectorcolor); return(_connectorcolor);
} }
/// Set the connector color; the color used for tree connection lines /// Set the connector color used for tree connection lines.
inline void connectorcolor(Fl_Color val) { inline void connectorcolor(Fl_Color val) {
_connectorcolor = val; _connectorcolor = val;
} }
/// Get the connector style /// Get the connector style.
inline Fl_Tree_Connector connectorstyle() const { inline Fl_Tree_Connector connectorstyle() const {
return(_connectorstyle); return(_connectorstyle);
} }
/// Set the connector style /// Set the connector style.
inline void connectorstyle(Fl_Tree_Connector val) { inline void connectorstyle(Fl_Tree_Connector val) {
_connectorstyle = val; _connectorstyle = val;
} }
@@ -255,11 +237,11 @@ public:
inline void connectorstyle(int val) { inline void connectorstyle(int val) {
_connectorstyle = Fl_Tree_Connector(val); _connectorstyle = Fl_Tree_Connector(val);
} }
/// Get the tree connection line's width /// Get the tree connection line's width.
inline int connectorwidth() const { inline int connectorwidth() const {
return(_connectorwidth); return(_connectorwidth);
} }
/// Set the tree connection line's width /// Set the tree connection line's width.
inline void connectorwidth(int val) { inline void connectorwidth(int val) {
_connectorwidth = val; _connectorwidth = val;
} }
+8 -2
View File
@@ -697,10 +697,13 @@ int Fl_Tree::deselect_all(Fl_Tree_Item *item, int docallback) {
item = item ? item : first(); // NULL? use first() item = item ? item : first(); // NULL? use first()
if ( ! item ) return(0); if ( ! item ) return(0);
int count = 0; int count = 0;
for ( ; item; item = next(item) ) { // Deselect item
if ( item->is_selected() ) if ( item->is_selected() )
if ( deselect(item, docallback) ) if ( deselect(item, docallback) )
++count; ++count;
// Deselect its children
for ( int t=0; t<item->children(); t++ ) {
count += deselect_all(item->child(t), docallback); // recurse
} }
return(count); return(count);
} }
@@ -726,10 +729,13 @@ int Fl_Tree::select_all(Fl_Tree_Item *item, int docallback) {
item = item ? item : first(); // NULL? use first() item = item ? item : first(); // NULL? use first()
if ( ! item ) return(0); if ( ! item ) return(0);
int count = 0; int count = 0;
for ( ; item; item = next(item) ) { // Select item
if ( !item->is_selected() ) if ( !item->is_selected() )
if ( select(item, docallback) ) if ( select(item, docallback) )
++count; ++count;
// Select its children
for ( int t=0; t<item->children(); t++ ) {
count += select_all(item->child(t), docallback); // recurse
} }
return(count); return(count);
} }
+4 -4
View File
@@ -44,8 +44,8 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Prefs &prefs) {
_label = 0; _label = 0;
_labelfont = prefs.labelfont(); _labelfont = prefs.labelfont();
_labelsize = prefs.labelsize(); _labelsize = prefs.labelsize();
_labelfgcolor = prefs.fgcolor(); _labelfgcolor = prefs.labelfgcolor();
_labelbgcolor = prefs.bgcolor(); _labelbgcolor = prefs.labelbgcolor();
_widget = 0; _widget = 0;
_open = 1; _open = 1;
_visible = 1; _visible = 1;
@@ -562,8 +562,8 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
W += prefs.openicon()->w(); W += prefs.openicon()->w();
} }
// Colors, fonts // Colors, fonts
Fl_Color fg = _selected ? prefs.bgcolor() : _labelfgcolor; Fl_Color fg = _selected ? _labelbgcolor : _labelfgcolor; // selected uses bgcolor, unselected uses fgcolor
Fl_Color bg = _selected ? prefs.selectcolor() : _labelbgcolor; Fl_Color bg = _selected ? tree->selection_color() : _labelbgcolor; // selected uses selectcolor, unselected uses bgcolor
if ( ! _active ) { if ( ! _active ) {
fg = fl_inactive(fg); fg = fl_inactive(fg);
if ( _selected ) bg = fl_inactive(bg); if ( _selected ) bg = fl_inactive(bg);
+2 -4
View File
@@ -136,10 +136,8 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_usericonmarginleft = 3; _usericonmarginleft = 3;
_labelmarginleft = 3; _labelmarginleft = 3;
_linespacing = 0; _linespacing = 0;
_fgcolor = FL_BLACK; _labelfgcolor = FL_BLACK;
_bgcolor = FL_WHITE; _labelbgcolor = FL_WHITE;
_selectcolor = FL_DARK_BLUE;
_inactivecolor = FL_GRAY;
_connectorcolor = Fl_Color(43); _connectorcolor = Fl_Color(43);
#ifdef __APPLE__ #ifdef __APPLE__
_connectorstyle = FL_TREE_CONNECTOR_NONE; _connectorstyle = FL_TREE_CONNECTOR_NONE;
+603 -345
View File
File diff suppressed because it is too large Load Diff