RAUI-labs/raui

[Feature] An "Easy Host" For RAUI

Closed this issue ยท 2 comments

As I'm writing the RAUI guide I'm realizing that even the minimal amount of setup necessary to hook RAUI up to Tetra is distracting from what I really want to be getting to, which is understanding and using RAUI itself.

Having to explain the tetra integration code forces the user to understand two new concepts instead of just one ( assuming they've never used Tetra before ).

I think it would be great to have a "RAUI Quick Start" host that can be used to get started rendering a RAUI widget tree immediately with no more than a few lines of setup.

I think I'm going to try to create a raui-quick-start create really quick so that I can use this for the guide. Let me know if you think there's a better way to do this.

Just got a simple mostly working example of the usage:

use raui::prelude::*;
use raui_quick_start::RauiQuickStartBuilder;

fn main() {
    // Create our quick start builder
    RauiQuickStartBuilder::default()
        // Set our window title
        .window_title("RAUI Guide".into())
        // Set the RAUI widget tree for our app
        .widget_tree(widget! {
            (my_first_widget)
        })
        // Build the app
        .build()
        .expect("Error building quick start")
        // And run it! ๐Ÿš€
        .run()
        .expect("Error running RAUI app");
}

/// We create our own widget by making a function that takes a `WidgetContext`
/// and that returns `WidgetNode`.
pub fn my_first_widget(_ctx: WidgetContext) -> WidgetNode {
    // We may do any amount of processing in the body of the function.

    // For now we will simply be creating a text box properties struct that we
    // will use to configure the `text_box` component.
    let text_box_props = TextBoxProps {
        text: "Hello world!".to_owned(),
        color: Color {
            r: 0.0,
            g: 0.0,
            b: 0.0,
            a: 1.0,
        },
        font: TextBoxFont {
            name: "verdana".to_owned(),
            size: 32.0,
        },
        ..Default::default()
    };

    // And at the end of the function we return a `WidgetNode` which we can
    // conveniently create with the `widget!` macro.
    widget! {
        (text_box: {text_box_props})
        // ^          ^
        // |          |
        // |          ---- After the name of the widget component we pass in
        // |               the component properties.
        // |
        // --- This is the name of the `text_box` widget component, which is a
        //     part of the RAUI prelude
    }
}

Now I'm going to try to work in #38 so that you don't have to specify fonts and images manually.

PR has got merged so i think i can close the issue :D