dash-recipes icon indicating copy to clipboard operation
dash-recipes copied to clipboard

style_push_* API seem to be unusable

Open parasyte opened this issue 5 years ago • 1 comments

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?

parasyte avatar Feb 06 '20 06:02 parasyte

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

snuk182 avatar Feb 08 '20 19:02 snuk182