From c22269bff3085012d326a0df77bf27ad5bcb41b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 05:33:47 +0100 Subject: Introduce `Program` API --- README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 9f21fc83..6ec56e18 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,8 @@ that can be incremented and decremented using two buttons. We start by modelling the __state__ of our application: ```rust +#[derive(Default)] struct Counter { - // The counter value value: i32, } ``` @@ -110,8 +110,8 @@ the button presses. These interactions are our __messages__: ```rust #[derive(Debug, Clone, Copy)] pub enum Message { - IncrementPressed, - DecrementPressed, + Increment, + Decrement, } ``` @@ -126,15 +126,15 @@ impl Counter { // We use a column: a simple vertical layout column![ // The increment button. We tell it to produce an - // `IncrementPressed` message when pressed - button("+").on_press(Message::IncrementPressed), + // `Increment` message when pressed + button("+").on_press(Message::Increment), // We show the value of the counter here text(self.value).size(50), // The decrement button. We tell it to produce a - // `DecrementPressed` message when pressed - button("-").on_press(Message::DecrementPressed), + // `Decrement` message when pressed + button("-").on_press(Message::Decrement), ] } } @@ -160,8 +160,15 @@ impl Counter { } ``` -And that's everything! We just wrote a whole user interface. Iced is now able -to: +And that's everything! We just wrote a whole user interface. Let's run it: + +```rust +fn main() -> iced::Result { + iced::run("A cool counter", Counter::update, Counter::view) +} +``` + +Iced will automatically: 1. Take the result of our __view logic__ and layout its widgets. 1. Process events from our system and produce __messages__ for our -- cgit From 0a24611ccdb9402f89c88fd5f567b9d26e3533c2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 17:13:49 +0100 Subject: Fix `README` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 6ec56e18..dee8b99d 100644 --- a/README.md +++ b/README.md @@ -149,10 +149,10 @@ impl Counter { pub fn update(&mut self, message: Message) { match message { - Message::IncrementPressed => { + Message::Increment => { self.value += 1; } - Message::DecrementPressed => { + Message::Decrement => { self.value -= 1; } } -- cgit From e8483f0f0ba5d7883476f4f96c66e953f941a823 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Mar 2024 19:15:06 +0100 Subject: Link to the book in the `README` --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index dee8b99d..0db09ded 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ Iced will automatically: __update logic__. 1. Draw the resulting user interface. -Browse the [documentation] and the [examples] to learn more! +Read the [book], the [documentation], and the [examples] to learn more! ## Implementation details @@ -215,6 +215,7 @@ come chat to [our Discord server]. The development of Iced is sponsored by the [Cryptowatch] team at [Kraken.com] +[book]: https://book.iced.rs/ [documentation]: https://docs.rs/iced/ [examples]: https://github.com/iced-rs/iced/tree/master/examples [Coffee]: https://github.com/hecrj/coffee -- cgit