Skip to content

Commit

Permalink
edits, and write Responding to Actions section
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDM committed Aug 12, 2024
1 parent bca3743 commit a8bc89d
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 74 deletions.
1 change: 0 additions & 1 deletion src/.quick_start/setting_up.md

This file was deleted.

3 changes: 2 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
- [Static Layout](./quick_start/static_layout.md)
- [Dynamic Layout](./quick_start/dynamic_layout.md)
- [Adding Style](./quick_start/adding_style.md)
- [Responding to Actions](./quick_start/responding_to_actions.md)
- [Responding to Actions](./quick_start/responding_to_actions.md)
- [Z Indexes](./quick_start/z_indexes.md)
15 changes: 13 additions & 2 deletions src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ The Yarrow framework is built using the Rust programming language. To use Yarrow

## Running the Examples

The [Yarrow repository](https://github.com/MeadowlarkDAW/Yarrow) on github contains some example applications. To run these examples, first clone the repository to a local directory. Then inside a terminal, navigate to the root directory and run the following command:
The [Yarrow repository](https://github.com/MeadowlarkDAW/Yarrow) on github contains some [example applications](https://github.com/MeadowlarkDAW/Yarrow/tree/main/examples). To run these examples, first clone the repository and enter the root directory of the project in a terminal:

```
git clone https://github.com/MeadowlarkDAW/Yarrow.git
cd Yarrow
```

Then run the following command:

`cargo run --example <name_of_example>`

Where `<name_of_example>` should be replaced with the example name (i.e. `cargo run --example gallery`)
Where `<name_of_example>` should be replaced with the example name, for example:

`cargo run --example gallery`

> The first compile may take quite a while as it is compiling an entire GUI library from scratch. Subsequent compiles should be much faster.
## Join the Community

Expand Down
Binary file added src/img/responding_to_actions_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/static_layout_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
This chapter will walk you through the basics of Yarrow by creating a simple application.

This book is not meant as an introduction to the Rust programming language. If you are new to Rust, it is highly recommended to first read through the [official Rust book](https://doc.rust-lang.org/book/). You can find even more Rust learning resources at [https://www.rust-lang.org/learn](https://www.rust-lang.org/learn).
This book is not meant as an introduction to the Rust programming language. If you are new to Rust, it is highly recommended to first read through the [official Rust book](https://doc.rust-lang.org/book/). More Rust learning resources can also be found at [https://www.rust-lang.org/learn](https://www.rust-lang.org/learn).
24 changes: 5 additions & 19 deletions src/quick_start/adding_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ impl MyStyle {
true, // 4
LabelStyle { // 5
back_quad: QuadStyle {
bg: Background::Solid(RGBA8::new(100, 30, 80, 255)),
border: BorderStyle {
color: RGBA8::new(200, 60, 160, 255),
width: 2.0,
radius: 10.0.into(),
},
bg: background_hex(0x641e50),
border: border(hex(0xc83ca0), 2.0, radius(10.0)),
},
text_padding: Padding::new(10.0, 10.0, 10.0, 10.0),
text_padding: padding_all_same(10.0),
..Default::default() // 6
},
);
Expand All @@ -46,24 +42,14 @@ impl MyStyle {
Now store our new style struct in `MyApp` and load it when the application starts:

```rust
#[derive(Default)]
struct MyApp {
// ...

// new
style: MyStyle,
}

impl MyApp {
fn new(action_sender: ActionSender<()>, action_receiver: ActionReceiver<()>) -> Self {
Self {
// ...

// new
style: MyStyle::default(),
}
}
}

impl Application for MyApp {
type Action = ();

Expand Down Expand Up @@ -102,7 +88,7 @@ By default all elements have a style which is very bare-bones (and most of the t
At the time of this writing, Yarrow has only one built-in theme called "Yarrow dark". To use it, simply add this inside of `MyStyle::load()`:

```rust
yarrow::theme::yarrow_dark::load(None, None, res);
yarrow::theme::yarrow_dark::load(Default::default(), res);
```

After loading a theme, it's probably a good idea to use a class for our custom fancy label so it doesn't conflict with the default one in the theme:
Expand Down
6 changes: 3 additions & 3 deletions src/quick_start/dynamic_layout.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Dynamic Layout

Setting the bounding rectangle inside of the element builder works great and all for static content, but what if we wanted the layout to dynamically change due to a change in the application state (or the window being resized)? And for that matter, what if we wanted to layout other elements based on the size of the text in the label element?
Setting the bounding rectangle inside via element builder works fine for static content, but what if we wanted the layout to dynamically change due to a change in the application state (or the window being resized)? And for that matter, what if we wanted to layout other elements based on the size of the text in the label element?

To achieve this, we will define a "layout function" for our main window. Remove the `.bounding_rect` property from the Label builder and then add the following method to `MainWindowElements`:
To achieve this, we will define a "layout function" for our main window. Remove the `.rect` property from the Label builder and then add the following method to `MainWindowElements`:

```rust
impl MainWindowElements {
Expand Down Expand Up @@ -32,7 +32,7 @@ impl MainWindowElements {
> self.hello_label.layout_aligned(window_rect.center(), Align2::CENTER, cx.res);
> ```
No we must call the layout function after the main window is built and whenever the window resizes. To do this, add the following to the `on_window_event` trait method:
Now we must call that layout function after the main window is built and whenever the window resizes. To do this, add the following to the `on_window_event` trait method:
```rust
fn on_window_event(
Expand Down
Loading

0 comments on commit a8bc89d

Please sign in to comment.