Skip to content

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

Open
@tobia

Description

@tobia

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:

  • Reduce boilerplate for the final user as much as possible, but keeping the code easy to read (for example, I could have abbreviated Compact to "C" and Stretchy to "S", but it would only save a few bytes and decrease the readability.)
  • Keep the implementation as simple as possible (I managed to do it all with a single macro that is less than 200 lines long and as simple as I could make it.)
  • Let the programmer omit any part of their UI from the macro if they need to define it dynamically (for example, you can omit a container's children and add them later through code, using the proper .append() methods.) This is also why all controls are defined with variable names that are available to use right after the iui! macro.

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!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions