Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
cyypherus committed Jan 31, 2025
2 parents 703ecd8 + f845beb commit 2dc9182
Show file tree
Hide file tree
Showing 12 changed files with 1,648 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
run: cargo build --verbose --features 'egui-examples macroquad-examples'
- name: Run tests
run: cargo test --verbose

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors = ["cyypherus"]
crate-type = ["lib"]

[features]
default = []
test-api = []
macroquad-examples = ["macroquad"]
egui-examples = ["egui", "eframe", "egui_extras"]
Expand Down
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ fn my_layout_fn(state: &mut MyState) -> Node<MyState> { todo!() }
For reuse, you can construct your drawable in a function

```rust
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_drawable<'a>(state: &'_ mut MyState) -> Node<'a, 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.
})
}
```

## 3. Combine nodes to define & customize your layout

```rust
fn my_layout_fn(state: &mut MyState) -> Node<MyState> {
row(vec![
my_drawable(state)
])
}
let mut layout = Layout::new(dynamic(|state| {
row(vec![
my_drawable(state),
])
}));
```

## 4. Draw your layout
Expand All @@ -100,14 +100,13 @@ fn my_layout_fn(state: &mut MyState) -> Node<MyState> {
// 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();
x: todo!(),
y: todo!(),
width: todo!(),
height: todo!(),
};
let mut my_state = MyState;

let layout = Layout::new(my_layout_fn);
// Perform layout & draw all of your drawable nodes.
layout.draw(available_area, &mut my_state);
```
Expand Down
Loading

0 comments on commit 2dc9182

Please sign in to comment.