Open
Description
Several controls, especially Group
and {Vertical, Horizontal}Box
, could be much more ergonomic to use if they provided an interface looking something like the following:
fn add_all(&mut self, ctx: &UI, children: Vec<Control>)
These are of course not precisely the correct types, but the general shape of the interface is correct. Adding many children is a pain, and this would make it easier.
Bonus points if it takes impl Iterator<Item=Control>
or similar.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
delbonis commentedon Jun 28, 2018
Is there a reason we have to pass the
ctx: &UI
everywhere by hand? Is there a way that it could be hidden and inferred when needed?NoraCodes commentedon Jun 28, 2018
delbonis commentedon Jun 28, 2018
Perhaps change the design so that when you, for example, call
Label::new()
, it doesn't actually make any calls to libui, instead giving you an unbound label object. Then take this and go build your whole UI with these unbound object. Then later, you go and instantiate the view by giving it to the actualUI
object that would traverse the tree and create everything in one shot. You'd keep track of the bindings to theui*
objects internally, away from the user. And I don't know enough about the internals of libui to know how you'd implement mutating the UI tree, later on though.Of course this would require a pretty major refactoring so that's annoying. 🤷♂️
NoraCodes commentedon Jun 28, 2018
NoraCodes commentedon Feb 26, 2019
This is like the solution we were discussion to #54 and will likely be solved in the same way.
tobia commentedon Apr 2, 2019
That is the only reason? Could this not be done by checking some global flag before calling any C methods and panic if it is not set?
Or rather, if a panic-like behaviour is what you mean by "unsound", then let just that happen. I cannot imagine somebody not calling
UI::init()
and then complaining about a panic or other crash.Inc0n commentedon Mar 26, 2020
I agree with what this comment said about hiding away
ctx:&UI
, ImGui, i think, does it in a similar way.A global context is created on
ImGui::init()
.Whenever a functions that requires the context, it can get the context with
ImGui::get_current_context()
bdamitz commentedon Sep 13, 2020
Just spitballing, perhaps we could create a trait like
where control-specific bindings are run for rust data structs impl UnboundedControl. Theoretically this should mean unsafe C code is only called during
bind()
? This would allow a model likeThen unbounded controls could be added with recursive calls to
bind()
by UI and its children with syntax like