mirror of
https://github.com/fltk/fltk.git
synced 2026-05-21 22:51:41 +08:00
Changes to solve STR#2426;
1) Hitting ENTER to select an item should make sure the item is
displayed if off-screen (Mayank Malik, pointing out similar behavior in Fl_Browser_)
2) show_item() without a positional argument will invoke show_item_top()
if the item is off-screen.
3) Added new method displayed() (to match Fl_Browser_'s)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7893 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+3
-1
@@ -803,7 +803,9 @@ public:
|
||||
void selectmode(Fl_Tree_Select val) {
|
||||
_prefs.selectmode(val);
|
||||
}
|
||||
void show_item(Fl_Tree_Item *item, int yoff=0);
|
||||
int displayed(Fl_Tree_Item *item);
|
||||
void show_item(Fl_Tree_Item *item, int yoff);
|
||||
void show_item(Fl_Tree_Item *item);
|
||||
void show_item_bottom(Fl_Tree_Item *item);
|
||||
void show_item_middle(Fl_Tree_Item *item);
|
||||
void show_item_top(Fl_Tree_Item *item);
|
||||
|
||||
@@ -520,6 +520,7 @@ int Fl_Tree::handle(int e) {
|
||||
case FL_KP_Enter:
|
||||
if ( when() & ~FL_WHEN_ENTER_KEY) {
|
||||
select_only(_item_focus);
|
||||
show_item(_item_focus); // STR #2426
|
||||
return(1);
|
||||
}
|
||||
break;
|
||||
@@ -789,6 +790,27 @@ void Fl_Tree::show_item(Fl_Tree_Item *item, int yoff) {
|
||||
redraw();
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// edges of the display window. This does NOT take into account the hide()/show()
|
||||
/// status of the item.
|
||||
///
|
||||
int Fl_Tree::displayed(Fl_Tree_Item *item) {
|
||||
return( (item->y() >= y() && item->y() <= (y()+h()-item->h())) ? 1 : 0);
|
||||
}
|
||||
|
||||
/// Adjust the vertical scroll bar to show \p item at the top
|
||||
/// of the display IF it is currently off-screen (eg. show_item_top()).
|
||||
/// If it is already on-screen, no change is made.
|
||||
///
|
||||
/// \see show_item_top(), show_item_middle(), show_item_bottom()
|
||||
///
|
||||
void Fl_Tree::show_item(Fl_Tree_Item *item) {
|
||||
if ( displayed(item) ) return;
|
||||
show_item_top(item);
|
||||
}
|
||||
|
||||
/// Adjust the vertical scrollbar so that \p item is at the top of the display.
|
||||
void Fl_Tree::show_item_top(Fl_Tree_Item *item) {
|
||||
item = item ? item : first();
|
||||
|
||||
+20
-10
@@ -142,7 +142,7 @@ Function {} {open
|
||||
} {
|
||||
Fl_Window window {
|
||||
label tree open
|
||||
xywh {1099 53 580 695} type Double visible
|
||||
xywh {1153 115 580 695} type Double visible
|
||||
} {
|
||||
Fl_Group tree {
|
||||
user_data 1234
|
||||
@@ -538,38 +538,49 @@ switch ( whenmode_chooser->value() ) {
|
||||
Fl_Box showitem_box {
|
||||
label {show_item()
|
||||
}
|
||||
xywh {468 423 60 77} box GTK_DOWN_BOX color 47 labelsize 11 align 1
|
||||
xywh {480 425 70 82} box GTK_DOWN_BOX color 47 labelsize 11 align 1
|
||||
}
|
||||
Fl_Button {} {
|
||||
label Show
|
||||
callback {Fl_Tree_Item *item = tree->next_selected_item();
|
||||
tree->show_item(item);} selected
|
||||
tooltip {Tests show_item() with no position specified.
|
||||
Makes the selected item visible IF it is off-screen.
|
||||
No change made if it is not off-screen.} xywh {495 434 40 17} labelsize 11
|
||||
}
|
||||
Fl_Button {} {
|
||||
label Top
|
||||
callback {Fl_Tree_Item *item = tree->next_selected_item();
|
||||
tree->show_item_top(item);}
|
||||
tooltip {Scrolls selected item to the top of the display
|
||||
tooltip {Test show_item_top().
|
||||
Scrolls selected item to the top of the display
|
||||
(only works if scrollbar showing)
|
||||
To use:
|
||||
1) open '500 items'
|
||||
2) select item 0010
|
||||
3) Hit Top/Mid/Bot} xywh {478 433 40 16} labelsize 11
|
||||
3) Hit Top/Mid/Bot} xywh {495 451 40 16} labelsize 11
|
||||
}
|
||||
Fl_Button {} {
|
||||
label Mid
|
||||
callback {Fl_Tree_Item *item = tree->next_selected_item();
|
||||
tree->show_item_middle(item);}
|
||||
tooltip {Scrolls the selected item to the middle of the display
|
||||
tooltip {Tests show_item_middle().
|
||||
Scrolls the selected item to the middle of the display
|
||||
To use:
|
||||
1) open '500 items'
|
||||
2) select 'item 0010'
|
||||
3) Hit Top/Mid/Bot} xywh {478 453 40 16} labelsize 11
|
||||
3) Hit Top/Mid/Bot} xywh {495 467 40 16} labelsize 11
|
||||
}
|
||||
Fl_Button {} {
|
||||
label Bot
|
||||
callback {Fl_Tree_Item *item = tree->next_selected_item();
|
||||
tree->show_item_bottom(item);}
|
||||
tooltip {Scrolls the selected item to the bottom of the display
|
||||
tooltip {Tests show_item_bottom().
|
||||
Scrolls the selected item to the bottom of the display
|
||||
To use:
|
||||
1) open '500 items'
|
||||
2) select 'item 0010'
|
||||
3) Hit Top/Mid/Bot} xywh {478 473 40 16} labelsize 11
|
||||
3) Hit Top/Mid/Bot} xywh {495 483 40 16} labelsize 11
|
||||
}
|
||||
Fl_Box docallback_box {
|
||||
label {Selection State Changes}
|
||||
@@ -848,6 +859,5 @@ window->size_range(window->w(), window->h(), 0, 0);
|
||||
|
||||
if ( tree->when() == FL_WHEN_CHANGED ) whenmode_chooser->value(0);
|
||||
else if ( tree->when() == FL_WHEN_RELEASE ) whenmode_chooser->value(1);
|
||||
else if ( tree->when() == FL_WHEN_NEVER ) whenmode_chooser->value(2);} {selected
|
||||
}
|
||||
else if ( tree->when() == FL_WHEN_NEVER ) whenmode_chooser->value(2);} {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user