Skip to content

Commit

Permalink
Introduce daemon API and unify shell runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jun 18, 2024
1 parent 368b15f commit 341c9a3
Show file tree
Hide file tree
Showing 54 changed files with 1,301 additions and 2,626 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ iced_core.workspace = true
iced_futures.workspace = true
iced_renderer.workspace = true
iced_widget.workspace = true
iced_winit.features = ["application"]
iced_winit.features = ["program"]
iced_winit.workspace = true

iced_highlighter.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion examples/arc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/bezier_tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/checkbox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/clock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/color_palette/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions examples/custom_shader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions examples/download_progress/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/events/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/exit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/ferris/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 10 additions & 6 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions examples/gradient/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iced::application;
use iced::gradient;
use iced::program;
use iced::widget::{
checkbox, column, container, horizontal_space, row, slider, text,
};
Expand All @@ -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()
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/layout/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/loading_spinners/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
39 changes: 16 additions & 23 deletions examples/multi_window/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/multitouch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/pane_grid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pokedex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/qr_code/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/screenshot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/scrollable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/sierpinski_triangle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/solar_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/stopwatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/styling/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
8 changes: 6 additions & 2 deletions examples/system_information/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/the_matrix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 341c9a3

Please sign in to comment.