summaryrefslogtreecommitdiff
path: root/src/Fl_Scroll.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2022-11-17 08:34:06 +0100
committerGitHub <noreply@github.com>2022-11-17 08:34:06 +0100
commit72415b534de36888e1a393847ec38544cdbbc3f7 (patch)
tree4361322149ec6515eb23390ae127827449e5380d /src/Fl_Scroll.cxx
parent402764f5c1373792fce742c663eb995b1c8a1d70 (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_Scroll.cxx')
-rw-r--r--src/Fl_Scroll.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Fl_Scroll.cxx b/src/Fl_Scroll.cxx
index f218915a8..fd7f4fbae 100644
--- a/src/Fl_Scroll.cxx
+++ b/src/Fl_Scroll.cxx
@@ -105,6 +105,24 @@ int Fl_Scroll::on_insert(Fl_Widget *candidate, int index) {
}
/**
+ Change new position of a child before it is moved.
+
+ Fix new position if the new child is planned to be moved after the scrollbars.
+ We can assume that the scrollbars are always the last two children!
+
+ Fl_Group calls this when a widget is moved within the list of children.
+ We return a new index if the widget would be moved after the scrollbars.
+
+ \param oldIndex the current index of the child that will be moved
+ \param newIndex the new index of the child
+ \return new index, possibly corrected to avoid last two scrollbar entries
+ */
+int Fl_Scroll::on_move(int oldIndex, int newIndex) {
+ // Compensate index for the widget that will be removed before it re-inserted
+ return on_insert( child(oldIndex), newIndex+1 ) - 1;
+}
+
+/**
Removes the widget at \p index from the group and deletes it.
This method does nothing if \p index is out of bounds or