Crates.io | backer |
lib.rs | backer |
version | 0.11.1 |
source | src |
created_at | 2024-09-07 02:27:43.340644 |
updated_at | 2024-11-10 02:58:23.65405 |
description | A library for straight-forward UI layout. |
homepage | |
repository | https://github.com/ejjonny/backer |
max_upload_size | |
id | 1366864 |
size | 234,003 |
A library for straight-forward UI layout.
Dependency free & framework-agnostic. Backer can be used in an index-based layout approach or with inline drawing code.
This library only implements layout & would be most useful along with a GUI library that can do GUI things (like macroquad or egui).
This project intends to be a flexible layout tool & not much else.
Check out the demo site: a mock page showcasing layout capabilities in a realistic interface. Built with egui!
Backer relies on simple rules that can compose to create complex, flexible layouts.
column_spaced(
10.,
vec![
draw_a(ui),
row_spaced(
10.,
vec![
draw_b(ui).width(180.).align(Align::Leading),
column_spaced(10., vec![draw_a(ui), draw_b(ui), draw_c(ui)]),
],
),
draw_c(ui),
],
)
.pad(10.)
Layout
struct with your layout function.use backer::layout::Layout;
use backer::layout::Node;
let layout = Layout::new(my_layout_fn);
fn my_layout_fn(state: &mut MyState) -> Node<MyState> { todo!() }
draw
nodeFor reuse, you can construct your drawable in a function
fn my_drawable(state: &mut MyState) -> Node<MyState> {
draw(move |area: Area, state: &mut MyState| {
// The `area` parameter is the space alotted for your view after layout is calculated
// The `state` parameter is *your* mutable state that you pass when you call layout.
// This closure should draw UI based on the alotted area or update state so that drawing can be performed later.
})
}
fn my_layout_fn(state: &mut MyState) -> Node<MyState> {
row(vec![
my_drawable(state)
])
}
// UI libraries generally will expose methods to get the available screen size
// In a real implementation this should use the real screen size!
let available_area = Area {
x: todo!(),
y: todo!(),
width: todo!(),
height: todo!().
};
let mut my_state = MyState::new();
let layout = Layout::new(my_layout_fn);
// Perform layout & draw all of your drawable nodes.
layout.draw(available_area, &mut my_state);
The crate is currently usable but new! Breaking changes may be relatively frequent as the crate matures.
Contributions are always welcome 🤗