rust-native-ui / libui-rs

Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`
Apache License 2.0
932 stars 73 forks source link

Consider linking to or including my crate `iui-builder` #69

Open tobia opened 5 years ago

tobia commented 5 years ago

Hello

I have published a simple macro that allows the definition of IUI user interfaces through a hierarchical, declarative DSL.

Here is the central part of the inputs.rs example defined using my macro:

// Create the layout and add the controls
iui! { &ui,
    let contents = HorizontalBox() {
        Stretchy: let input_group = Group("Inputs") {
            let input_vbox = VerticalBox(padded: true) {
                Compact: let slider = Slider(1, 100)
                Compact: let spinner = Spinbox(1, 100)
                Compact: let _sp = Spacer()
                Compact: let _sp = HorizontalSeparator()
                Compact: let _sp = Spacer()
                Compact: let entry = Entry()
                Stretchy: let multi = MultilineEntry()
            }
        }
        Stretchy: let output_group = Group("Outputs") {
            let output_vbox = VerticalBox() {
                Compact: let add_label = Label("")
                Compact: let sub_label = Label("")
                Compact: let text_label = Label("")
                Stretchy: let bigtext_label = Label("")
            }
        }
    }
}

// Add the layout to the window
window.set_child(&ui, contents);

// Update the application state when a control changes its value.
slider.on_changed(&ui, |val| {
    state.borrow_mut().slider_val = val;
});

I tried several variations of the syntax, before settling on this one. Some of my objectives were:

More information and an explanation of the macro syntax is available in the project's README.

I'm still learning Rust and experimenting with the available libraries and I don't yet know whether I will work with Rust or IUI much in the future. Therefore if you like the idea and wish to incorporate it into your project, feel free to do so.

In the meantime, users of the stable 0.3.0 version can include my crate from GitHub and use this version of the macro to define their interfaces. (A link from your README would be appreciated!)

NoraCodes commented 5 years ago

This is cool, thank you! I'll look more into whether this will fit into the crate itself.