|
|
commit 9abbff2078e2a092ecc252f6b147c24fe567f616
Author: Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Tue May 25 17:39:20 2021 +0200
Commit: Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Tue May 25 17:39:20 2021 +0200
Add virtual int Fl_Group::delete_child(int n) (STR 3218)
This is a convenience method that does range checking (index n),
removes the child given by index n from the group and deletes it.
FL/Fl_Group.H | 5 ++++-
src/Fl_Group.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git FL/Fl_Group.H FL/Fl_Group.H
index 5d28f8c..2271962 100644
--- FL/Fl_Group.H
+++ FL/Fl_Group.H
@@ -1,7 +1,7 @@
//
// Group header file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2020 by Bill Spitzak and others.
+// Copyright 1998-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -117,6 +117,9 @@ public:
void remove(Fl_Widget* o) {remove(*o);}
void clear();
+ /* delete child n (by index) */
+ virtual int delete_child(int n);
+
/**
Sets the group's resizable widget.
See void Fl_Group::resizable(Fl_Widget *o)
diff --git src/Fl_Group.cxx src/Fl_Group.cxx
index 769d286..541c841 100644
--- src/Fl_Group.cxx
+++ src/Fl_Group.cxx
@@ -547,6 +547,52 @@ void Fl_Group::remove(Fl_Widget &o) {
}
/**
+ Removes the widget at \p index from the group and deletes it.
+
+ This method does nothing if \p index is out of bounds.
+
+ This method differs from the remove() method in that it deletes
+ the widget from memory. Since this method is virtual it can be
+ reimplemented in subclasses with additional requirements and
+ consequences. See the documentation of subclasses.
+
+ Many subclasses don't need to reimplement this method.
+
+ \note This method \b may refuse to remove and delete the widget
+ if it is an essential part of the Fl_Group, for instance
+ a scrollbar in an Fl_Scroll group. In this case the widget is
+ neither removed nor deleted.
+
+ This method does not call init_sizes() or redraw(). This is left
+ to user code if necessary.
+
+ Returns 0 if the widget was removed and deleted.
+ Return values \> 0 are reserved for use by FLTK core widgets.
+ Return values \< 0 are free to be used by user defined widgets.
+
+ \todo Reimplementation of Fl_Group::delete_widget(int) in more FLTK
+ subclasses. This is not yet complete.
+
+ \param[in] index index of child to be removed
+
+ \returns success (0) or error code
+ \retval 0 success
+ \retval 1 index out of range
+ \retval 2 widget not allowed to be removed (see note)
+ \retval >2 reserved for FLTK use
+
+ \since FLTK 1.4.0
+*/
+int Fl_Group::delete_child(int index) {
+ if (index < 0 || index >= children_)
+ return 1;
+ Fl_Widget *w = child(index);
+ remove(index);
+ delete w;
+ return 0;
+}
+
+/**
Resets the internal array of widget sizes and positions.
The Fl_Group widget keeps track of the original widget sizes and
[ Direct Link to Message ] | |
|
| |