diff options
| author | Matthias Melcher <github@matthiasm.com> | 2022-11-17 08:34:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-17 08:34:06 +0100 |
| commit | 72415b534de36888e1a393847ec38544cdbbc3f7 (patch) | |
| tree | 4361322149ec6515eb23390ae127827449e5380d /src/Fl_Group.cxx | |
| parent | 402764f5c1373792fce742c663eb995b1c8a1d70 (diff) | |
Fix rearranging children in Fl_Scroll (#546)
Implement Fl_Scroll::on_move()
Fix indexing in Fl_Group::on_move()
Diffstat (limited to 'src/Fl_Group.cxx')
| -rw-r--r-- | src/Fl_Group.cxx | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index bcdb962f6..f9bbcb541 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -489,10 +489,9 @@ int Fl_Group::on_insert(Fl_Widget *candidate, int index) { By returning -1, Fl_Group::insert will not move the child. \param oldIndex the current index of the child that will be moved - \param newIndex the new index of the child, counted with the old - child already removed - \return index to position the child as planned - \return a new index to force the child to a different position + \param newIndex the new index of the child + \return \p newIndex to position the child as planned + \return a different index to force the child to a different position \return -1 to keep the group from moving the child */ int Fl_Group::on_move(int oldIndex, int newIndex) { @@ -511,11 +510,11 @@ void Fl_Group::insert(Fl_Widget &o, int index) { if (o.parent()) { Fl_Group* g = o.parent(); int n = g->find(o); - if (g == this) { // avoid expensive remove() and add() if we just move a widget within the group - if (index > n) index--; + if (g == this) { + // avoid expensive remove() and add() if we just move a widget within the group index = on_move(n, index); - if (index == n) return; // this includes (children_ == 1) - if (index >= children_ || index < 0) return; + if ((index == n) || (index < 0)) return; // this includes (children_ == 1) + if (index >= children_) index = children_ - 1; if (index > n) memmove(array_+n, array_+(n+1), (index-n) * sizeof(Fl_Widget*)); else |
