mirror of
https://github.com/fltk/fltk.git
synced 2026-05-31 13:55:38 +08:00
o Added new 0xffffffff 'transparent' color behavior for the item's bg color;
with this as the default color, Fl_Tree::color() can control the tree's background.
Tests added to the test/tree application.
o test/tree.fl modified:
o Added a 'Test Suggestions' button to document various tests
o Added tests for new 'transparent' color behavior
o Added test for STR#2832 to check if items can be drawn to the /right/ of child widgets
o Added new methods to Fl_Tree_Prefs:
item_labelfont() -- obsoletes labelfont()
item_labelsize() -- obsoletes labelsize()
item_labelfgcolor() -- obsoletes labelfgcolor()
item_labelbgcolor() -- obsoletes labelbgcolor()
o Added 'Fonts and Colors' section to Fl_Tree docs
o Fl_Tree_Item ABI feature added: using bitflags instead of chars
to keep the class small, as it gets instanced a lot. (fast + LIGHT)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9478 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+65
-13
@@ -56,11 +56,23 @@ class FL_EXPORT Fl_Tree_Item {
|
||||
Fl_Font _labelfont; // label's font face
|
||||
Fl_Fontsize _labelsize; // label's font size
|
||||
Fl_Color _labelfgcolor; // label's fg color
|
||||
Fl_Color _labelbgcolor; // label's bg color
|
||||
Fl_Color _labelbgcolor; // label's bg color (0xffffffff is 'transparent')
|
||||
enum {
|
||||
OPEN = 1<<0, ///> item is open
|
||||
VISIBLE = 1<<1, ///> item is visible
|
||||
ACTIVE = 1<<2, ///> item is active
|
||||
SELECTED = 1<<3, ///> item is selected
|
||||
};
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
// NEW
|
||||
unsigned short _flags; // misc flags
|
||||
#else /*FLTK_ABI_VERSION*/
|
||||
// OLD: this will go away after 1.3.x
|
||||
char _open; // item is open?
|
||||
char _visible; // item is visible?
|
||||
char _active; // item activated?
|
||||
char _selected; // item selected?
|
||||
#endif /*FLTK_ABI_VERSION*/
|
||||
int _xywh[4]; // xywh of this widget (if visible)
|
||||
int _collapse_xywh[4]; // xywh of collapse icon (if visible)
|
||||
int _label_xywh[4]; // xywh of label
|
||||
@@ -131,10 +143,12 @@ public:
|
||||
return(_labelfgcolor);
|
||||
}
|
||||
/// Set item's label background color.
|
||||
/// A special case is made for color 0xffffffff which is treated as 'transparent'.
|
||||
void labelbgcolor(Fl_Color val) {
|
||||
_labelbgcolor = val;
|
||||
}
|
||||
/// Return item's background text color.
|
||||
/// If the color is 0xffffffff, it is 'transparent'.
|
||||
Fl_Color labelbgcolor() const {
|
||||
return(_labelbgcolor);
|
||||
}
|
||||
@@ -208,26 +222,26 @@ public:
|
||||
void close();
|
||||
/// See if the item is 'open'.
|
||||
int is_open() const {
|
||||
return(_open?1:0);
|
||||
return(is_flag(OPEN));
|
||||
}
|
||||
/// See if the item is 'closed'.
|
||||
int is_close() const {
|
||||
return(_open?0:1);
|
||||
return(is_flag(OPEN)?0:1);
|
||||
}
|
||||
/// Toggle the item's open/closed state.
|
||||
void open_toggle() {
|
||||
_open?close():open();
|
||||
is_open()?close():open();
|
||||
}
|
||||
/// Change the item's selection state to the optionally specified 'val'.
|
||||
/// If 'val' is not specified, the item will be selected.
|
||||
///
|
||||
void select(int val=1) {
|
||||
_selected = val;
|
||||
set_flag(SELECTED, val);
|
||||
}
|
||||
/// Toggle the item's selection state.
|
||||
void select_toggle() {
|
||||
if ( is_selected() ) {
|
||||
deselect(); // deselect if selected
|
||||
deselect(); // deselect if selected
|
||||
} else {
|
||||
select(); // select if deselected
|
||||
}
|
||||
@@ -249,7 +263,7 @@ public:
|
||||
}
|
||||
/// Disable the item's selection state.
|
||||
void deselect() {
|
||||
_selected = 0;
|
||||
set_flag(SELECTED, 0);
|
||||
}
|
||||
/// Deselect item and all its children.
|
||||
/// Returns count of how many items were in the 'selected' state,
|
||||
@@ -268,7 +282,7 @@ public:
|
||||
}
|
||||
/// See if the item is selected.
|
||||
char is_selected() const {
|
||||
return(_selected);
|
||||
return(is_flag(SELECTED));
|
||||
}
|
||||
/// Change the item's activation state to the optionally specified 'val'.
|
||||
///
|
||||
@@ -280,7 +294,7 @@ public:
|
||||
/// If 'val' is not specified, the item will be activated.
|
||||
///
|
||||
void activate(int val=1) {
|
||||
_active = val;
|
||||
set_flag(ACTIVE,val);
|
||||
if ( _widget && val != (int)_widget->active() ) {
|
||||
if ( val ) {
|
||||
_widget->activate();
|
||||
@@ -298,15 +312,19 @@ public:
|
||||
}
|
||||
/// See if the item is activated.
|
||||
char is_activated() const {
|
||||
return(_active);
|
||||
return(is_flag(ACTIVE));
|
||||
}
|
||||
/// See if the item is activated.
|
||||
char is_active() const {
|
||||
return(_active);
|
||||
return(is_activated());
|
||||
}
|
||||
/// See if the item is visible. Alias for is_visible().
|
||||
int visible() const {
|
||||
return(is_visible());
|
||||
}
|
||||
/// See if the item is visible.
|
||||
int visible() const {
|
||||
return(_visible ? 1 : 0);
|
||||
int is_visible() const {
|
||||
return(is_flag(VISIBLE));
|
||||
}
|
||||
int visible_r() const;
|
||||
|
||||
@@ -329,6 +347,40 @@ public:
|
||||
int is_root() const {
|
||||
return(_parent==0?1:0);
|
||||
}
|
||||
|
||||
// Protected methods
|
||||
protected:
|
||||
#if FLTK_ABI_VERSION >= 10302
|
||||
/// Set a flag to an on or off value. val is 0 or 1.
|
||||
inline void set_flag(unsigned short flag,int val) {
|
||||
if ( val ) _flags |= flag; else _flags &= ~flag;
|
||||
}
|
||||
/// See if flag set. Returns 0 or 1.
|
||||
inline int is_flag(unsigned short val) const {
|
||||
return(_flags & val ? 1 : 0);
|
||||
}
|
||||
#else /*FLTK_ABI_VERSION*/
|
||||
/// Set a flag to an on or off value. val is 0 or 1.
|
||||
void set_flag(unsigned short flag,int val) {
|
||||
switch (flag) {
|
||||
case OPEN: _open = val; break;
|
||||
case VISIBLE: _visible = val; break;
|
||||
case ACTIVE: _active = val; break;
|
||||
case SELECTED: _selected = val; break;
|
||||
}
|
||||
}
|
||||
/// See if flag set. Returns 0 or 1.
|
||||
int is_flag(unsigned short flag) const {
|
||||
switch (flag) {
|
||||
case OPEN: return(_open ? 1 : 0);
|
||||
case VISIBLE: return(_visible ? 1 : 0);
|
||||
case ACTIVE: return(_active ? 1 : 0);
|
||||
case SELECTED: return(_selected ? 1 : 0);
|
||||
default: return(0);
|
||||
}
|
||||
}
|
||||
#endif /*FLTK_ABI_VERSION*/
|
||||
|
||||
};
|
||||
|
||||
#endif /*FL_TREE_ITEM_H*/
|
||||
|
||||
Reference in New Issue
Block a user