diff options
author | 2024-03-16 05:33:47 +0100 | |
---|---|---|
committer | 2024-03-16 05:33:47 +0100 | |
commit | c22269bff3085012d326a0df77bf27ad5bcb41b7 (patch) | |
tree | 1083f21d012ab2bac88fb51537d4dc431bc7f170 /README.md | |
parent | 0524e9b4571d264018656418f02a1f9e27e268d7 (diff) | |
download | iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.gz iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.bz2 iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.zip |
Introduce `Program` API
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -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 |