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.
This commit is contained in:
parent
da4d16b59a
commit
9abbff2078
@ -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)
|
||||
|
@ -546,6 +546,52 @@ void Fl_Group::remove(Fl_Widget &o) {
|
||||
if (i < children_) remove(i);
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user