diff options
author | 2024-06-19 01:53:40 +0200 | |
---|---|---|
committer | 2024-06-19 01:53:40 +0200 | |
commit | 341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b (patch) | |
tree | 6a37f29352b1768911b6d42c220f22ebecc202ee /examples | |
parent | 368b15f70896b387ae3f072e807b289b36b2d103 (diff) | |
download | iced-341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b.tar.gz iced-341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b.tar.bz2 iced-341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b.zip |
Introduce `daemon` API and unify shell runtimes
Diffstat (limited to 'examples')
36 files changed, 81 insertions, 72 deletions
diff --git a/examples/arc/src/main.rs b/examples/arc/src/main.rs index 4576404f..b1e8402a 100644 --- a/examples/arc/src/main.rs +++ b/examples/arc/src/main.rs @@ -7,7 +7,7 @@ use iced::widget::canvas::{ use iced::{Element, Length, Point, Rectangle, Renderer, Subscription, Theme}; pub fn main() -> iced::Result { - iced::program("Arc - Iced", Arc::update, Arc::view) + iced::application("Arc - Iced", Arc::update, Arc::view) .subscription(Arc::subscription) .theme(|_| Theme::Dark) .antialiasing(true) diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 29df3eeb..eaf84b97 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -4,7 +4,7 @@ use iced::widget::{button, container, horizontal_space, hover}; use iced::{Element, Length, Theme}; pub fn main() -> iced::Result { - iced::program("Bezier Tool - Iced", Example::update, Example::view) + iced::application("Bezier Tool - Iced", Example::update, Example::view) .theme(|_| Theme::CatppuccinMocha) .antialiasing(true) .run() diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index bec4a954..f06557f8 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -4,7 +4,7 @@ use iced::{Element, Font}; const ICON_FONT: Font = Font::with_name("icons"); pub fn main() -> iced::Result { - iced::program("Checkbox - Iced", Example::update, Example::view) + iced::application("Checkbox - Iced", Example::update, Example::view) .font(include_bytes!("../fonts/icons.ttf").as_slice()) .run() } diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index 7c4685c4..4584a0c7 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -11,7 +11,7 @@ use iced::{ pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program("Clock - Iced", Clock::update, Clock::view) + iced::application("Clock - Iced", Clock::update, Clock::view) .subscription(Clock::subscription) .theme(Clock::theme) .antialiasing(true) diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs index d9325edb..e4b19731 100644 --- a/examples/color_palette/src/main.rs +++ b/examples/color_palette/src/main.rs @@ -11,7 +11,7 @@ use std::marker::PhantomData; use std::ops::RangeInclusive; pub fn main() -> iced::Result { - iced::program( + iced::application( "Color Palette - Iced", ColorPalette::update, ColorPalette::view, diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 463b2df9..b04a8183 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -9,9 +9,13 @@ use iced::window; use iced::{Alignment, Color, Element, Length, Subscription}; fn main() -> iced::Result { - iced::program("Custom Shader - Iced", IcedCubes::update, IcedCubes::view) - .subscription(IcedCubes::subscription) - .run() + iced::application( + "Custom Shader - Iced", + IcedCubes::update, + IcedCubes::view, + ) + .subscription(IcedCubes::subscription) + .run() } struct IcedCubes { diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index 7974d5a0..d91e5eab 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -4,9 +4,13 @@ use iced::widget::{button, center, column, progress_bar, text, Column}; use iced::{Alignment, Element, Subscription}; pub fn main() -> iced::Result { - iced::program("Download Progress - Iced", Example::update, Example::view) - .subscription(Example::subscription) - .run() + iced::application( + "Download Progress - Iced", + Example::update, + Example::view, + ) + .subscription(Example::subscription) + .run() } #[derive(Debug)] diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs index ec65e2fa..bed9d94a 100644 --- a/examples/editor/src/main.rs +++ b/examples/editor/src/main.rs @@ -12,7 +12,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; pub fn main() -> iced::Result { - iced::program("Editor - Iced", Editor::update, Editor::view) + iced::application("Editor - Iced", Editor::update, Editor::view) .load(Editor::load) .subscription(Editor::subscription) .theme(Editor::theme) diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index 504ed5d8..4f0f07b0 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -5,7 +5,7 @@ use iced::window; use iced::{Alignment, Element, Length, Subscription, Task}; pub fn main() -> iced::Result { - iced::program("Events - Iced", Events::update, Events::view) + iced::application("Events - Iced", Events::update, Events::view) .subscription(Events::subscription) .exit_on_close_request(false) .run() diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs index 8ba180a5..b998016e 100644 --- a/examples/exit/src/main.rs +++ b/examples/exit/src/main.rs @@ -3,7 +3,7 @@ use iced::window; use iced::{Alignment, Element, Task}; pub fn main() -> iced::Result { - iced::program("Exit - Iced", Exit::update, Exit::view).run() + iced::application("Exit - Iced", Exit::update, Exit::view).run() } #[derive(Default)] diff --git a/examples/ferris/src/main.rs b/examples/ferris/src/main.rs index 0400c376..88006898 100644 --- a/examples/ferris/src/main.rs +++ b/examples/ferris/src/main.rs @@ -9,7 +9,7 @@ use iced::{ }; pub fn main() -> iced::Result { - iced::program("Ferris - Iced", Image::update, Image::view) + iced::application("Ferris - Iced", Image::update, Image::view) .subscription(Image::subscription) .theme(|_| Theme::TokyoNight) .run() diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 7e6d461d..421f862a 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -15,12 +15,16 @@ use std::time::Duration; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program("Game of Life - Iced", GameOfLife::update, GameOfLife::view) - .subscription(GameOfLife::subscription) - .theme(|_| Theme::Dark) - .antialiasing(true) - .centered() - .run() + iced::application( + "Game of Life - Iced", + GameOfLife::update, + GameOfLife::view, + ) + .subscription(GameOfLife::subscription) + .theme(|_| Theme::Dark) + .antialiasing(true) + .centered() + .run() } struct GameOfLife { diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 2b906c32..e5b19443 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,5 +1,5 @@ +use iced::application; use iced::gradient; -use iced::program; use iced::widget::{ checkbox, column, container, horizontal_space, row, slider, text, }; @@ -8,7 +8,7 @@ use iced::{Alignment, Color, Element, Length, Radians, Theme}; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program("Gradient - Iced", Gradient::update, Gradient::view) + iced::application("Gradient - Iced", Gradient::update, Gradient::view) .style(Gradient::style) .transparent(true) .run() @@ -95,11 +95,11 @@ impl Gradient { .into() } - fn style(&self, theme: &Theme) -> program::Appearance { - use program::DefaultStyle; + fn style(&self, theme: &Theme) -> application::Appearance { + use application::DefaultStyle; if self.transparent { - program::Appearance { + application::Appearance { background_color: Color::TRANSPARENT, text_color: theme.palette().text, } diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index c40ac820..2e774415 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -10,7 +10,7 @@ use iced::{ }; pub fn main() -> iced::Result { - iced::program(Layout::title, Layout::update, Layout::view) + iced::application(Layout::title, Layout::update, Layout::view) .subscription(Layout::subscription) .theme(Layout::theme) .run() diff --git a/examples/loading_spinners/src/main.rs b/examples/loading_spinners/src/main.rs index a63c51d4..503f2d7a 100644 --- a/examples/loading_spinners/src/main.rs +++ b/examples/loading_spinners/src/main.rs @@ -11,7 +11,7 @@ use circular::Circular; use linear::Linear; pub fn main() -> iced::Result { - iced::program( + iced::application( "Loading Spinners - Iced", LoadingSpinners::update, LoadingSpinners::view, diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index d185cf3b..413485e7 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -10,7 +10,7 @@ use iced::{Alignment, Color, Element, Length, Subscription, Task}; use std::fmt; pub fn main() -> iced::Result { - iced::program("Modal - Iced", App::update, App::view) + iced::application("Modal - Iced", App::update, App::view) .subscription(App::subscription) .run() } diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index b82ad1f3..dfb816cf 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -1,18 +1,21 @@ -use iced::executor; -use iced::multi_window::{self, Application}; use iced::widget::{ button, center, column, container, horizontal_space, scrollable, text, text_input, }; use iced::window; -use iced::{ - Alignment, Element, Length, Settings, Subscription, Task, Theme, Vector, -}; +use iced::{Alignment, Element, Length, Subscription, Task, Theme, Vector}; use std::collections::BTreeMap; fn main() -> iced::Result { - Example::run(Settings::default()) + iced::daemon(Example::title, Example::update, Example::view) + .load(|| { + window::open(window::Settings::default()).map(Message::WindowOpened) + }) + .subscription(Example::subscription) + .theme(Example::theme) + .scale_factor(Example::scale_factor) + .run() } #[derive(Default)] @@ -39,21 +42,7 @@ enum Message { TitleChanged(window::Id, String), } -impl multi_window::Application for Example { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: ()) -> (Self, Task<Message>) { - ( - Example { - windows: BTreeMap::from([(window::Id::MAIN, Window::new(1))]), - }, - Task::none(), - ) - } - +impl Example { fn title(&self, window: window::Id) -> String { self.windows .get(&window) @@ -97,7 +86,11 @@ impl multi_window::Application for Example { Message::WindowClosed(id) => { self.windows.remove(&id); - Task::none() + if self.windows.is_empty() { + iced::exit() + } else { + Task::none() + } } Message::ScaleInputChanged(id, scale) => { if let Some(window) = self.windows.get_mut(&id) { @@ -149,7 +142,7 @@ impl multi_window::Application for Example { .unwrap_or(1.0) } - fn subscription(&self) -> Subscription<Self::Message> { + fn subscription(&self) -> Subscription<Message> { window::close_events().map(Message::WindowClosed) } } diff --git a/examples/multitouch/src/main.rs b/examples/multitouch/src/main.rs index 2453c7f5..69717310 100644 --- a/examples/multitouch/src/main.rs +++ b/examples/multitouch/src/main.rs @@ -13,7 +13,7 @@ use std::collections::HashMap; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program("Multitouch - Iced", Multitouch::update, Multitouch::view) + iced::application("Multitouch - Iced", Multitouch::update, Multitouch::view) .antialiasing(true) .centered() .run() diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 6b5bd332..db9f7a05 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -7,7 +7,7 @@ use iced::widget::{ use iced::{Color, Element, Length, Size, Subscription}; pub fn main() -> iced::Result { - iced::program("Pane Grid - Iced", Example::update, Example::view) + iced::application("Pane Grid - Iced", Example::update, Example::view) .subscription(Example::subscription) .run() } diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index e62ed70b..b22ffe7f 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -3,7 +3,7 @@ use iced::widget::{self, center, column, image, row, text}; use iced::{Alignment, Element, Length, Task}; pub fn main() -> iced::Result { - iced::program(Pokedex::title, Pokedex::update, Pokedex::view) + iced::application(Pokedex::title, Pokedex::update, Pokedex::view) .load(Pokedex::search) .run() } diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index c6a90458..b30ecf15 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -2,7 +2,7 @@ use iced::widget::{center, column, pick_list, qr_code, row, text, text_input}; use iced::{Alignment, Element, Theme}; pub fn main() -> iced::Result { - iced::program( + iced::application( "QR Code Generator - Iced", QRGenerator::update, QRGenerator::view, diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 78d3e9ff..1ea53e8f 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -13,7 +13,7 @@ use ::image::ColorType; fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program("Screenshot - Iced", Example::update, Example::view) + iced::application("Screenshot - Iced", Example::update, Example::view) .subscription(Example::subscription) .run() } diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index a0dcf82c..f2a853e1 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<scrollable::Id> = Lazy::new(scrollable::Id::unique); pub fn main() -> iced::Result { - iced::program( + iced::application( "Scrollable - Iced", ScrollableDemo::update, ScrollableDemo::view, diff --git a/examples/sierpinski_triangle/src/main.rs b/examples/sierpinski_triangle/src/main.rs index 7dd7be5e..4c751937 100644 --- a/examples/sierpinski_triangle/src/main.rs +++ b/examples/sierpinski_triangle/src/main.rs @@ -8,7 +8,7 @@ use rand::Rng; use std::fmt::Debug; fn main() -> iced::Result { - iced::program( + iced::application( "Sierpinski Triangle - Iced", SierpinskiEmulator::update, SierpinskiEmulator::view, diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index deb211d8..2a67e23e 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -22,7 +22,7 @@ use std::time::Instant; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program( + iced::application( "Solar System - Iced", SolarSystem::update, SolarSystem::view, diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index a8149753..bd56785a 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -7,7 +7,7 @@ use iced::{Alignment, Element, Subscription, Theme}; use std::time::{Duration, Instant}; pub fn main() -> iced::Result { - iced::program("Stopwatch - Iced", Stopwatch::update, Stopwatch::view) + iced::application("Stopwatch - Iced", Stopwatch::update, Stopwatch::view) .subscription(Stopwatch::subscription) .theme(Stopwatch::theme) .run() diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 57e8f47e..3124493b 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -6,7 +6,7 @@ use iced::widget::{ use iced::{Alignment, Element, Length, Theme}; pub fn main() -> iced::Result { - iced::program("Styling - Iced", Styling::update, Styling::view) + iced::application("Styling - Iced", Styling::update, Styling::view) .theme(Styling::theme) .run() } diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index e2808edd..363df590 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -2,8 +2,12 @@ use iced::widget::{button, center, column, text}; use iced::{system, Element, Task}; pub fn main() -> iced::Result { - iced::program("System Information - Iced", Example::update, Example::view) - .run() + iced::application( + "System Information - Iced", + Example::update, + Example::view, + ) + .run() } #[derive(Default)] diff --git a/examples/the_matrix/src/main.rs b/examples/the_matrix/src/main.rs index f3a67ac8..2ae1cc3a 100644 --- a/examples/the_matrix/src/main.rs +++ b/examples/the_matrix/src/main.rs @@ -11,7 +11,7 @@ use std::cell::RefCell; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program("The Matrix - Iced", TheMatrix::update, TheMatrix::view) + iced::application("The Matrix - Iced", TheMatrix::update, TheMatrix::view) .subscription(TheMatrix::subscription) .antialiasing(true) .run() diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index aee2479e..232133b1 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -9,7 +9,7 @@ use iced::{Alignment, Element, Length, Subscription, Task}; use toast::{Status, Toast}; pub fn main() -> iced::Result { - iced::program("Toast - Iced", App::update, App::view) + iced::application("Toast - Iced", App::update, App::view) .subscription(App::subscription) .run() } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index c21e1a96..a834c946 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -17,7 +17,7 @@ pub fn main() -> iced::Result { #[cfg(not(target_arch = "wasm32"))] tracing_subscriber::fmt::init(); - iced::program(Todos::title, Todos::update, Todos::view) + iced::application(Todos::title, Todos::update, Todos::view) .load(Todos::load) .subscription(Todos::subscription) .font(include_bytes!("../fonts/icons.ttf").as_slice()) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 78086ce9..94ba78ee 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -16,7 +16,7 @@ pub fn main() -> iced::Result { #[cfg(not(target_arch = "wasm32"))] tracing_subscriber::fmt::init(); - iced::program(Tour::title, Tour::update, Tour::view) + iced::application(Tour::title, Tour::update, Tour::view) .centered() .run() } diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs index 3ab19252..50a055f3 100644 --- a/examples/url_handler/src/main.rs +++ b/examples/url_handler/src/main.rs @@ -3,7 +3,7 @@ use iced::widget::{center, text}; use iced::{Element, Subscription}; pub fn main() -> iced::Result { - iced::program("URL Handler - Iced", App::update, App::view) + iced::application("URL Handler - Iced", App::update, App::view) .subscription(App::subscription) .run() } diff --git a/examples/vectorial_text/src/main.rs b/examples/vectorial_text/src/main.rs index 1ed7a2b1..6dd3273a 100644 --- a/examples/vectorial_text/src/main.rs +++ b/examples/vectorial_text/src/main.rs @@ -6,7 +6,7 @@ use iced::widget::{ use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector}; pub fn main() -> iced::Result { - iced::program( + iced::application( "Vectorial Text - Iced", VectorialText::update, VectorialText::view, diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs index b43c0cca..e46d1ff0 100644 --- a/examples/visible_bounds/src/main.rs +++ b/examples/visible_bounds/src/main.rs @@ -10,7 +10,7 @@ use iced::{ }; pub fn main() -> iced::Result { - iced::program("Visible Bounds - Iced", Example::update, Example::view) + iced::application("Visible Bounds - Iced", Example::update, Example::view) .subscription(Example::subscription) .theme(|_| Theme::Dark) .run() diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index 8c0fa1d0..8422ce16 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -8,7 +8,7 @@ use iced::{color, Element, Length, Subscription, Task}; use once_cell::sync::Lazy; pub fn main() -> iced::Result { - iced::program("WebSocket - Iced", WebSocket::update, WebSocket::view) + iced::application("WebSocket - Iced", WebSocket::update, WebSocket::view) .load(WebSocket::load) .subscription(WebSocket::subscription) .run() |