Skip to content

Commit

Permalink
Merge pull request #2469 from iced-rs/unify-shell-runtimes
Browse files Browse the repository at this point in the history
`Daemon` API and Shell Runtime Unification
  • Loading branch information
hecrj committed Jun 19, 2024
2 parents 19db068 + c5f4beb commit 714d450
Show file tree
Hide file tree
Showing 57 changed files with 1,531 additions and 2,714 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
3 changes: 0 additions & 3 deletions core/src/window/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ pub struct Id(u64);
static COUNT: AtomicU64 = AtomicU64::new(1);

impl Id {
/// The reserved window [`Id`] for the first window in an Iced application.
pub const MAIN: Self = Id(0);

/// Creates a new unique window [`Id`].
pub fn unique() -> Id {
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
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
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -38,7 +38,7 @@ impl Events {
}
Message::EventOccurred(event) => {
if let Event::Window(window::Event::CloseRequested) = event {
window::close(window::Id::MAIN)
window::get_latest().and_then(window::close)
} else {
Task::none()
}
Expand All @@ -48,7 +48,7 @@ impl Events {

Task::none()
}
Message::Exit => window::close(window::Id::MAIN),
Message::Exit => window::get_latest().and_then(window::close),
}
}

Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -20,7 +20,7 @@ enum Message {
impl Exit {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Confirm => window::close(window::Id::MAIN),
Message::Confirm => window::get_latest().and_then(window::close),
Message::Exit => {
self.show_confirm = true;

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
41 changes: 17 additions & 24 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 All @@ -68,7 +57,7 @@ impl multi_window::Application for Example {
return Task::none();
};

window::fetch_position(*last_window)
window::get_position(*last_window)
.then(|last_position| {
let position = last_position.map_or(
window::Position::Default,
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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -47,7 +47,8 @@ impl Example {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Screenshot => {
return iced::window::screenshot(window::Id::MAIN)
return window::get_latest()
.and_then(window::screenshot)
.map(Message::Screenshotted);
}
Message::Screenshotted(screenshot) => {
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
Loading

0 comments on commit 714d450

Please sign in to comment.