From 2dbcdba209b4c815fb5aa68584bfdf052c983e9a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 27 Jul 2022 06:56:26 +0200 Subject: Update `counter` example in `README` :tada: --- README.md | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index abb5b037..5e52234e 100644 --- a/README.md +++ b/README.md @@ -98,15 +98,9 @@ that can be incremented and decremented using two buttons. We start by modelling the __state__ of our application: ```rust -use iced::button; - struct Counter { // The counter value value: i32, - - // The local state of the two buttons - increment_button: button::State, - decrement_button: button::State, } ``` @@ -125,28 +119,23 @@ Now, let's show the actual counter by putting it all together in our __view logic__: ```rust -use iced::{Button, Column, Text}; +use iced::widget::{button, column, text, Column}; impl Counter { - pub fn view(&mut self) -> Column { + pub fn view(&self) -> Column { // We use a column: a simple vertical layout - Column::new() - .push( - // The increment button. We tell it to produce an - // `IncrementPressed` message when pressed - Button::new(&mut self.increment_button, Text::new("+")) - .on_press(Message::IncrementPressed), - ) - .push( - // We show the value of the counter here - Text::new(self.value.to_string()).size(50), - ) - .push( - // The decrement button. We tell it to produce a - // `DecrementPressed` message when pressed - Button::new(&mut self.decrement_button, Text::new("-")) - .on_press(Message::DecrementPressed), - ) + column![ + // The increment button. We tell it to produce an + // `IncrementPressed` message when pressed + button("+").on_press(Message::IncrementPressed), + + // 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), + ] } } ``` -- cgit