Crates.io | mcgooey |
lib.rs | mcgooey |
version | 0.1.4 |
source | src |
created_at | 2022-05-01 18:04:16.760043 |
updated_at | 2022-05-03 12:07:47.400739 |
description | A GUI system that works exclusively with percentages and widget trees |
homepage | |
repository | https://github.com/actuday6418/xando |
max_upload_size | |
id | 578698 |
size | 2,558,995 |
McGooey is a GUI system written in Rust on top of Macroquad. McGooey is Mc — Macroquad, and, Gooey — GUI. Also GUIs made with McGooey are indeed gooey.
GUIs in McGooey are written as a tree of Widgets. Widget
is a trait that may be implemented to create new Widgets for your UI.
McGooey is also very opinionated about how widgets are laid out. Each Widget is logically supposed to draw only within the space passed to it, which is that of it's parent widget, after allowing for margins and other children of that parent Widget. All Widgets therefore have their dimensions specified in percentages. Even text scales with the size of it's parent widget (as it's size is a percentage of that of it's parent).
A simple widget tree:
View::new(
Column::new().push(
Button::default(state.clone())
.color(WHITE)
.is_pressed_callback(|_button: &mut Button<()>| { // Specify the type of the external state variable as a type parameter
panic!("EXIT");
})
.child(
Text::default()
.text("Click me to exit")
.geometry(Geometry::new(Vector2::from(90, 90))) // that is, occupy 90% of parent's width and height.
// 10% of vertical and horizontal padding are added automatically
.color(RED),
),
),
)
A View is a single screen with a bunch of widgets defining what it looks like. Each View must pass it's interactive widgets an Rc<RefCell
fn ui(state: Rc<RefCell<()>>) -> View {
View::new(
Column::new().push(
Button::default(state.clone())
.color(WHITE)
.is_pressed_callback(|_button: &mut Button<()>| {
panic!("EXIT");
})
.child(
Text::default()
.text("Click me to exit")
.geometry(Geometry::new(Vector2::from(90, 90)))
.color(RED),
),
),
)
}
#[macroquad::main("XandO")]
async fn main() {
let mut ui = ui(Rc::new(RefCell::new(())));
loop {
ui.tick();
ui.draw();
next_frame().await
}
}
Xando is a Tic Tac Toe implementation using McGooey, which showcases some common scenarios like mutating external state on events like a button click, etc. Xando, through McGooey, is able to easily implement a variable number of cells in the game.