Modify/remove GUI child widgets
Is your feature request related to a problem? Please describe. I want to build a GUI that updates depending on the data selected from a combobox. For example, selecting data A should display 3 checkboxes but selecting data B should display 4 checkboxes. This requires me to remove the old checkboxes (widgets) and add new ones. Adding new ones dynamically is not a problem but removing existing widgets is not currently possible.
Describe the solution you'd like One or all of the following for the Python API:
- A
remove_child()method forWidget - A
set_children()method forWidget - A
clear_children()method forWidget - Direct access to
Widget'schildren_list
Describe alternatives you've considered
Using the existing get_children() method and modifying the returned list. Noting that the docs specify that this should not be modified. This does not work.
I would also very much want this functionality for the C++ API. There is only Widget::AddChild() and Widget::GetChildren() which returns a const std::vector that should not be modified.
Like @nicholas-p1 , I would like the ability to set/remove/clear children. It might would also make sense for my application to have a function like InsertChild(int index) and RemoveChild(int index).
This has actually become a blocking issue for my project since I can't think of any workaround. There is no way I can find to "reset" the parent object. Things I've considered:
-
Recreating the parent object and adding the children again. This actually does not work. Consider an instance
std::shared_ptr<Widget> mywidgetthat has some children that i need to modify (remove, change order or something else) where in this contextWidgetcould be any derived class of thevisualization::gui::Widgetclass. I have tried to do*mywidget = open3d::visualization::gui::Widget()howeveroperator=is implicitly deleted because theWidgetclass has aunique_ptrto its implementation (which cannot be copied) and theWidgetclass does not implement a custom operator or copy constructor for these purposes. -
Using the output of
GetChildren(). I briefly considered const-casting the returned vector of this function, however this returns a copy of the vector containing the children, not a const reference, so this is immediately a dead end. -
"Escalate the issue". The
Windowclass faces the same issue - it only hasAddChildso there is no way to undo the addition of my top-level widget.Applicationdoes have the ability toRemoveWindowbut recreating the window is not practical from a usability perspective. -
"Disappear the children". By this I mean I have tried to use the
SetEnabled(),SetVisible()and layout functions to try to hide the widgets I no longer want, but could not get the layout into a workable state, and would have required substantial work to get the layouting of the hidden widgets to not be an issue.
I think i'm going to avoid GUI designs that involve the dynamic insertion & removal of widgets until the API can accomodate this.
Removing widgets is a very important feature, would be great if it could be implemented.
WidgetProxy would solve your problem
hi @forrestjgq , i've taken a look at the class and I think it would partially solve the problem, but i have 2 concerns/questions:
- WidgetProxy starts empty/invisible until the widget is set, however after a widget is set, i can't see a way to remove it (unless you could call
SetWidget(nullptr)?) - This seems like an overly complex solution to what i would think is a simple extension of the current Widget API. Is there a good reason why
Widget::RemoveChild(Index),Widget::InsertChild(Index), etc type functions can't exist?
hi @willat343
WidgetProxy starts empty/invisible until the widget is set, however after a widget is set, i can't see a way to remove it (unless you could call SetWidget(nullptr)?) -- that would be correct
This seems like an overly complex solution to what i would think is a simple extension of the current Widget API. Is there a good reason why Widget::RemoveChild(Index), Widget::InsertChild(Index), etc type functions can't exist? -- actually I think it's necessary to have these apis, but index might not be a good option. ask @errissa for more information of designing consideration.
@willat343 The design of the new UI system predates my involvement with the project so I don't know the reason Insert/RemoveChild wasn't implemented originally though I believe it was intentional. @forrestjgq'sWidgetProxy and WidgetStack contributions allow dynamic UIs to be built so although it's not a general solution it's enough that given our limited resources implementing a general solution is a low priority for us.
We would more than welcome the contribution of the ability to dynamically add/remove widgets beyond what is already provided by WidgetProxy and WidgetStack. If you're interested, I'm happy to help.