3 releases (breaking)

0.3.0 Jan 4, 2022
0.2.0 Dec 27, 2021
0.1.0 Dec 26, 2021

#17 in #advanced

35 downloads per month
Used in 3 crates

MIT/Apache

15KB
296 lines

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.

[!IMPORTANT] This library is in the middle of a sizable rework and therefore is not currently in a state where usage is technically feasible. The docs are also very out of date and will be updated once this work is nearing completion.

🛠️ Installation

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

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

🚀 Usage

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

Creating new widgets

Currently, widgets are created using StatelessWidget, StatefulWidget, LayoutWidget, PaintWidget, and InheritedWidget derive macros, and by implementing their respective trait.

#[derive(Default, StatelessWidget)]
pub struct MyWidget {
    // Widget is the convention for passing children. Vec<Widget> should be used for passing variable amounts.
    pub child: Widget,
}

impl StatelessWidget for MyWidget {
    fn build(&self, ctx: &mut StatelessBuildContext<Self>) -> Widget {
        build! {
            <Button> {
                // Widgets are stored as Rcs, so cloning has little overhead
                child: self.child.clone(),
            }
        }
    }
}

What's build!?

The build! macro makes it significantly cleaner and easier to init new widgets. It gives a struct-like syntax for widget creation, and is the recommended way to build interfaces.

use agui::macros::build;

fn build(&self, ctx: &mut StatelessBuildContext) -> Widget {
    build! {
        <Button> {
            color: Color::from_rgba((1.0, 0.0, 1.0)),

            child: <Text> {
                text: "A Button"
            }
        }
    }
}

// is equivalent to:

fn build(&self, ctx: &mut StatelessBuildContext) -> Widget {
    Button::builder()
        .color(Color::from_rgba((1.0, 0.0, 1.0)))
        .child(
                Text::builder()
                    .text(String::from("A Button"))
                    .build()
                    .into_widget()
        )
        .build()
        .into_widget()
}

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

Dependencies

~2MB
~42K SLoC