diff options
author | 2024-03-16 05:33:47 +0100 | |
---|---|---|
committer | 2024-03-16 05:33:47 +0100 | |
commit | c22269bff3085012d326a0df77bf27ad5bcb41b7 (patch) | |
tree | 1083f21d012ab2bac88fb51537d4dc431bc7f170 /examples/pane_grid | |
parent | 0524e9b4571d264018656418f02a1f9e27e268d7 (diff) | |
download | iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.gz iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.bz2 iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.zip |
Introduce `Program` API
Diffstat (limited to 'examples/pane_grid')
-rw-r--r-- | examples/pane_grid/src/main.rs | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 5e728ce1..005536f7 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -1,17 +1,16 @@ use iced::alignment::{self, Alignment}; -use iced::executor; use iced::keyboard; use iced::widget::pane_grid::{self, PaneGrid}; use iced::widget::{ button, column, container, responsive, row, scrollable, text, }; -use iced::{ - Application, Color, Command, Element, Length, Settings, Size, Subscription, - Theme, -}; +use iced::{Color, Element, Length, Size, Subscription}; pub fn main() -> iced::Result { - Example::run(Settings::default()) + iced::sandbox(Example::update, Example::view) + .subscription(Example::subscription) + .title("Pane Grid - Iced") + .run() } struct Example { @@ -35,30 +34,18 @@ enum Message { CloseFocused, } -impl Application for Example { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Self, Command<Message>) { +impl Example { + fn new() -> Self { let (panes, _) = pane_grid::State::new(Pane::new(0)); - ( - Example { - panes, - panes_created: 1, - focus: None, - }, - Command::none(), - ) - } - - fn title(&self) -> String { - String::from("Pane grid - Iced") + Example { + panes, + panes_created: 1, + focus: None, + } } - fn update(&mut self, message: Message) -> Command<Message> { + fn update(&mut self, message: Message) { match message { Message::Split(axis, pane) => { let result = @@ -132,8 +119,6 @@ impl Application for Example { } } } - - Command::none() } fn subscription(&self) -> Subscription<Message> { @@ -209,6 +194,12 @@ impl Application for Example { } } +impl Default for Example { + fn default() -> Self { + Example::new() + } +} + const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb( 0xFF as f32 / 255.0, 0xC7 as f32 / 255.0, |