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 --- examples/scrollable/src/main.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'examples/scrollable/src/main.rs') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 2ad7272b..3e1b0408 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -1,20 +1,23 @@ -use iced::executor; use iced::widget::scrollable::Properties; use iced::widget::{ button, column, container, horizontal_space, progress_bar, radio, row, scrollable, slider, text, vertical_space, Scrollable, }; -use iced::{ - Alignment, Application, Border, Color, Command, Element, Length, Settings, - Theme, -}; +use iced::{Alignment, Border, Color, Command, Element, Length, Theme}; use once_cell::sync::Lazy; static SCROLLABLE_ID: Lazy = Lazy::new(scrollable::Id::unique); pub fn main() -> iced::Result { - ScrollableDemo::run(Settings::default()) + iced::application( + ScrollableDemo::new, + ScrollableDemo::update, + ScrollableDemo::view, + ) + .theme(ScrollableDemo::theme) + .title("Scrollable - Iced") + .run() } struct ScrollableDemo { @@ -45,13 +48,8 @@ enum Message { Scrolled(scrollable::Viewport), } -impl Application for ScrollableDemo { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: Self::Flags) -> (Self, Command) { +impl ScrollableDemo { + fn new() -> (Self, Command) { ( ScrollableDemo { scrollable_direction: Direction::Vertical, @@ -65,10 +63,6 @@ impl Application for ScrollableDemo { ) } - fn title(&self) -> String { - String::from("Scrollable - Iced") - } - fn update(&mut self, message: Message) -> Command { match message { Message::SwitchDirection(direction) => { @@ -340,7 +334,7 @@ impl Application for ScrollableDemo { container(content).padding(20).center_x().center_y().into() } - fn theme(&self) -> Self::Theme { + fn theme(&self) -> Theme { Theme::Dark } } -- cgit From 93ae790da14544667176ecdbdd6a4eaaa98a248a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 15:53:03 +0100 Subject: Implement `Program::load` to specify startup `Command` --- examples/scrollable/src/main.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'examples/scrollable/src/main.rs') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 3e1b0408..a6f3c689 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -11,12 +11,11 @@ static SCROLLABLE_ID: Lazy = Lazy::new(scrollable::Id::unique); pub fn main() -> iced::Result { iced::application( - ScrollableDemo::new, + "Scrollable - Iced", ScrollableDemo::update, ScrollableDemo::view, ) .theme(ScrollableDemo::theme) - .title("Scrollable - Iced") .run() } @@ -49,18 +48,15 @@ enum Message { } impl ScrollableDemo { - fn new() -> (Self, Command) { - ( - ScrollableDemo { - scrollable_direction: Direction::Vertical, - scrollbar_width: 10, - scrollbar_margin: 0, - scroller_width: 10, - current_scroll_offset: scrollable::RelativeOffset::START, - alignment: scrollable::Alignment::Start, - }, - Command::none(), - ) + fn new() -> Self { + ScrollableDemo { + scrollable_direction: Direction::Vertical, + scrollbar_width: 10, + scrollbar_margin: 0, + scroller_width: 10, + current_scroll_offset: scrollable::RelativeOffset::START, + alignment: scrollable::Alignment::Start, + } } fn update(&mut self, message: Message) -> Command { @@ -339,6 +335,12 @@ impl ScrollableDemo { } } +impl Default for ScrollableDemo { + fn default() -> Self { + Self::new() + } +} + fn progress_bar_custom_style(theme: &Theme) -> progress_bar::Appearance { progress_bar::Appearance { background: theme.extended_palette().background.strong.color.into(), -- cgit From 54f44754eb216d4b2c08cd2a7c3582f1dc295205 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Mar 2024 14:16:38 +0100 Subject: Move `Program` to `application` module --- examples/scrollable/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/scrollable/src/main.rs') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index a6f3c689..240ae908 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -10,7 +10,7 @@ use once_cell::sync::Lazy; static SCROLLABLE_ID: Lazy = Lazy::new(scrollable::Id::unique); pub fn main() -> iced::Result { - iced::application( + iced::program( "Scrollable - Iced", ScrollableDemo::update, ScrollableDemo::view, -- cgit