FLTK logo

[master] be92843 - Fix Fl_Group::insert() and Fl_Scroll::on_move()

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] be92843 - Fix Fl_Group::insert() and Fl_Scroll::on_move() "Albrecht Schlosser" Nov 20, 2022  
 
commit be928430a6cc642b82bc1dfe6a94823ae0dd5016
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Sun Nov 20 14:11:19 2022 +0100
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Sun Nov 20 14:11:19 2022 +0100

    Fix Fl_Group::insert() and Fl_Scroll::on_move()

 src/Fl_Group.cxx  | 7 +++++--
 src/Fl_Scroll.cxx | 9 ++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git src/Fl_Group.cxx src/Fl_Group.cxx
index f9bbcb5..a492a6a 100644
--- src/Fl_Group.cxx
+++ src/Fl_Group.cxx
@@ -513,8 +513,11 @@ void Fl_Group::insert(Fl_Widget &o, int 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) || (index < 0)) return; // this includes (children_ == 1)
-      if (index >= children_) index = children_ - 1;
+      if (index < 0) return;      // don't move: requested by subclass
+      if (index > children_)
+        index = children_;
+      if (index > n) index--;     // compensate for removal and re-insertion
+      if (index == n) return;     // same position; this includes (children_ == 1)
       if (index > n)
         memmove(array_+n, array_+(n+1), (index-n) * sizeof(Fl_Widget*));
       else
diff --git src/Fl_Scroll.cxx src/Fl_Scroll.cxx
index fd7f4fb..bee0d71 100644
--- src/Fl_Scroll.cxx
+++ src/Fl_Scroll.cxx
@@ -113,13 +113,12 @@ int Fl_Scroll::on_insert(Fl_Widget *candidate, int index) {
  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
+ \param old_index the current index of the child that will be moved
+ \param new_index 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;
+int Fl_Scroll::on_move(int old_index, int new_index) {
+  return on_insert(child(old_index), new_index);
 }
 
 /**
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.