Skip to content
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

style_push_* API seem to be unusable #28

Open
parasyte opened this issue Feb 6, 2020 · 1 comment
Open

style_push_* API seem to be unusable #28

parasyte opened this issue Feb 6, 2020 · 1 comment

Comments

@parasyte
Copy link

parasyte commented Feb 6, 2020

Here's an example of using this API in C: https://github.com/Immediate-Mode-UI/Nuklear/blob/d74ffc7157890fe1e16c09e3cb3e5103f5067720/demo/overview.c#L957-L958

    nk_style_push_vec2(ctx, &ctx->style.window.spacing, nk_vec2(0,0));
    nk_style_push_float(ctx, &ctx->style.button.rounding, 0);

This doesn't seem like it would work in Rust, since it requires mutable references to ctx and ctx->style.window.spacing at the same time (mutable aliasing).

I am able to push a value into a cloned struct, then copy it to the context with a setter, but this is more code (and more copying):

    let mut spacing = ctx.style().window().spacing().clone();
    ctx.style_push_vec2(&mut spacing, Vec2 { x: 0.0, y: 0.0 });
    ctx.style_mut().window_mut().set_spacing(spacing);

    let mut rounding = ctx.style().button().rounding();
    ctx.style_push_float(&mut rounding, 0.0);
    ctx.style_mut().button_mut().set_rounding(rounding);

Seems there should be a better way?

@snuk182
Copy link
Owner

snuk182 commented Feb 8, 2020

Thanks for the ticket.
Hm. I have to rethink this API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants