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

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

Open
tobia opened this issue Apr 4, 2019 · 1 comment
Open

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

tobia opened this issue Apr 4, 2019 · 1 comment
Labels
c-enhancement New feature or request p-medium Medium Priority

Comments

@tobia
Copy link

tobia commented Apr 4, 2019

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

@NoraCodes
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-enhancement New feature or request p-medium Medium Priority
Projects
None yet
Development

No branches or pull requests

2 participants