Re: [fltk/fltk] Tree & delete node (as button), 1.3.6, linux (#251)
erco77
Jul 13, 2021
When you create a custom button/custom widget to be used in Fl_Tree, it becomes a child of the Fl_Group which then 'owns' it. The widget's ownership is then managed with the inherited Fl_Group::xxx() methods (such as Fl_Group::clear(w), Fl_Group::remove(w), or Fl::delete_widget(w), etc)
When you assign the widget to a particular Fl_Tree_Item with item->widget(your_widget), it's just associating the widget pointer to that particular item, not re-parenting it. (Fl_Tree_Item is not derived from Fl_Widget or Fl_Group). So the widget is still 'owned' by Fl_Group.
This allows the widget to be unassigned from one Fl_Tree_Item (with item->remove(w)), and reassigned to another (with item->widget(w)), without needing to destroy + recreate the widget.
To actually destroy the widget, first un-assign it from the item (using item->widget(0)) and then use the usual techniques to either remove or delete a child widget from an Fl_Group, e.g. Fl_Tree::Fl_Group::remove(w) to remove from the tree's group without deleting, or Fl::delete_widget(w) to remove + destroy, etc.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.