mirui 0.33.1

A lightweight, no_std ECS-driven UI framework for embedded, desktop, and WebAssembly
Documentation
use crate::prelude::*;
use crate::ui::widgets::{Image, assets::*};

pub fn build_widgets(world: &mut World, parent: Entity) {
    //~focus-start
    ui! {
        :(
            parent: parent
            world: world
        :)

        Column (
            bg_color: Color::rgb(30, 30, 46),
            width: 480,
            height: 320
        ) {
            View (
                bg_color: Color::rgb(88, 166, 255),
                text: "Absolute Position Demo",
                height: 40
            )
            View (
                bg_color: Color::rgb(40, 40, 60),
                grow: 1.0
            )
            View (
                bg_color: Color::rgb(248, 81, 73),
                border_radius: 8,
                position: Position::Absolute,
                left: 50,
                top: 80,
                width: 60,
                height: 60
            )
            View (
                bg_color: Color::rgb(63, 185, 80),
                border_radius: 8,
                position: Position::Absolute,
                left: 200,
                top: 120,
                width: 80,
                height: 40
            )
            Image (
                position: Position::Absolute,
                left: 350,
                top: 60,
                width: IMG_THUMBS_UP.width as i32,
                height: IMG_THUMBS_UP.height as i32,
                src: "thumbs_up"
            )
            View (
                bg_color: Color::rgb(210, 168, 255),
                text: "floating",
                border_radius: 12,
                position: Position::Absolute,
                left: 100,
                top: 200,
                width: 120,
                height: 50
            )
        }
    };
    //~focus-end
}

#[cfg(feature = "std")]
pub fn setup_app<B, F>(app: &mut App<B, F>, parent: Entity)
where
    B: Surface,
    F: RendererFactory<B>,
{
    app.add_plugin(crate::app::plugins::ImageResourcesPlugin::default());
    build_widgets(&mut app.world, parent);
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::ui::Children;
    use crate::ui::IdMap;

    #[test]
    fn build_widgets_smoke() {
        let mut world = World::new();
        world.insert_resource(IdMap::new());
        let parent = WidgetBuilder::new(&mut world).id();
        build_widgets(&mut world, parent);
        assert!(
            world
                .get::<Children>(parent)
                .is_some_and(|c| !c.0.is_empty()),
        );
    }
}