agui

Crates.ioagui
lib.rsagui
version0.3.0
sourcesrc
created_at2021-12-14 21:19:36.144946
updated_at2022-01-04 03:13:09.743058
descriptionA reactive GUI project
homepagehttps://github.com/Stumblinbear/agui
repositoryhttps://github.com/Stumblinbear/agui
max_upload_size
id497945
size17,357
Stumblinbear (Stumblinbear)

documentation

README

Logo
An advanced, reactive UI library for Rust
Report a Bug ยท Request a Feature . Ask a Question


What is agui?

Agui is an advanced reactive GUI project for Rust, inspired by Flutter and taking some concepts from other related UI systems.

WARNING

Agui is very much still in heavy active development. The API will likely change, and it has yet to go under rigorous testing. However, that's not to say it's not ready for moderate use.

๐Ÿ› ๏ธ Installation

Agui is available on crates.io, Rust's official package repository. Just add this to your Cargo.toml file:

[dependencies]
agui = "0.1" # ensure this is the latest version

๐Ÿš€ Usage

Docs for agui are under development, however you can check the agui_agpu/examples directory for basic setup, and agui_widgets for many examples on widget creation.

Creating new widgets

Currently, widgets are created using a Widget derive macro, and by implementing the WidgetBuilder trait.

#[derive(Default, Widget)]
// The default layout type is "column" but we want it to be a "row" instead.
pub struct MyWidget {
    // We can define parameters, here.
    pub layout: Ref<Layout>,
}

impl WidgetBuilder for MyWidget {
    // Widgets can return nothing, one or more children, or an error. BuildResult is the enum we use to cover those possibilities.
    fn build(&self, ctx: &WidgetContext) -> BuildResult {
        // `ctx.set_layout` is what we use to define this widget's layout parameters.
        ctx.set_layout_type(LayoutType::Row.into());
        
        // `ctx.set_layout` is what we use to define this widget's layout parameters.
        ctx.set_layout(Ref::clone(&self.layout));

        build! {
            Button { }
        }
    }
}

What's build!?

The build! macro makes it significantly cleaner and easier to init new widgets. All it does is initialize unset fields in a struct to their Default::default(), and add .into() to the struct itself.

// It allows us to turn this:

fn build(&self, ctx: &WidgetContext) -> BuildResult {
    BuildResult::One(
        Button {
            layout: Layout::default(),
            color: Color::default(),
            child: Text {
                text: String::from("A Button")
            }
        }
    )
}

// Into this:

use agui::macros::build;

fn build(&self, ctx: &WidgetContext) -> BuildResult {
    build!{
        Button {
            child: Text {
                text: String::from("A Button")
            }
        }
    }
}

A more complex widget implementation (featuring global state and computed values) can be seen in the Button widget.

Functional Widgets are coming soon, which will make creating them even easier.

๐Ÿค Contributing

Contributions are encouraged, and very welcome. Feel free to check the issues page if you wish to do so!

Please go through existing issues and pull requests to check if somebody else is already working on it. Also, make sure to run cargo test before you commit your changes!

Commit count: 348

cargo fmt