-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convenience methods to add multiple children to layouts, etc #26
Comments
Is there a reason we have to pass the |
Yes. The `UI` context reference allows `iui` to ensure, at compile time,
that you your code will not call `libui` functions prior to initialization,
which would be unsound.
…On Thu, Jun 28, 2018 at 3:18 PM, Trey Del Bonis ***@***.***> wrote:
Is there a reason we have to pass the &UI everywhere by hand? Is there a
way that it could be hidden and inferred when needed?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/LeoTindall/libui-rs/issues/26#issuecomment-401160379>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADI0_VRb7LUo7CoRfakLUwiC-Dh0kBI3ks5uBTorgaJpZM4UogoN>
.
--
Leo Tindall
leotindall.com | [email protected]
|
Perhaps change the design so that when you, for example, call Of course this would require a pretty major refactoring so that's annoying. 🤷♂️ |
This is a good idea, and something that I might do once `libui` gets its
internal memory management sorted out; at the moment, unfortunately, it's a
recipe for having a lot of memory leaks, because controls we create can't
be freed manually (i.e. they have toe be bound into a tree and then the
tree has to be deinitialized).
…On Thu, Jun 28, 2018 at 3:46 PM, Trey Del Bonis ***@***.***> wrote:
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
actual UI object that would traverse the tree and create everything in
one shot. You'd keep track of the bindings to the ui* 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. 🤷♂️
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/LeoTindall/libui-rs/issues/26#issuecomment-401168109>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADI0_Z2yMx4ayV9ikm2qOc_MGF4CPbRsks5uBUC6gaJpZM4UogoN>
.
--
Leo Tindall
leotindall.com | [email protected]
|
This is like the solution we were discussion to #54 and will likely be solved in the same way. |
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 |
I agree with what this comment said about hiding away A global context is created on |
Just spitballing, perhaps we could create a trait like trait Bind: UnboundedControl {
fn bind(&mut self, _ctx: &UI);
} where control-specific bindings are run for rust data structs impl UnboundedControl. Theoretically this should mean unsafe C code is only called during let mut win = Window::new("Test App", 200, 200, WindowType::NoMenubar);
win.bind(&ui); Then unbounded controls could be added with recursive calls to ui.add(win); // would call `bind()` on `win`
// or
ui.add_all([
Window::new("Test App", 200, 200, WindowType::NoMenubar)
.set_child(
Button::new("Button")
.on_clicked(move |btn| {
btn.set_text("Clicked!")
}) // Unbounded controls follow a builder pattern -> &mut Self?
),
Window::new(...),
...
]); |
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: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.The text was updated successfully, but these errors were encountered: