Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

Modify/remove GUI child widgets

Open nepfaff opened this issue 5 years ago • 7 comments

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 for Widget
  • A set_children() method for Widget
  • A clear_children() method for Widget
  • Direct access to Widget's children_ 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.

nepfaff avatar Jul 27 '21 16:07 nepfaff

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).

willat343 avatar Aug 28 '21 00:08 willat343

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> mywidget that has some children that i need to modify (remove, change order or something else) where in this context Widget could be any derived class of the visualization::gui::Widget class. I have tried to do *mywidget = open3d::visualization::gui::Widget() however operator= is implicitly deleted because the Widget class has a unique_ptr to its implementation (which cannot be copied) and the Widget class 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 Window class faces the same issue - it only has AddChild so there is no way to undo the addition of my top-level widget. Application does have the ability to RemoveWindow but 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.

willat343 avatar Aug 29 '21 12:08 willat343

Removing widgets is a very important feature, would be great if it could be implemented.

cansik avatar Dec 14 '21 19:12 cansik

WidgetProxy would solve your problem

forrestjgq avatar Feb 08 '22 08:02 forrestjgq

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?

willat343 avatar Feb 12 '22 01:02 willat343

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.

forrestjgq avatar Feb 14 '22 08:02 forrestjgq

@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.

errissa avatar Feb 14 '22 19:02 errissa