Skip to content

Commit 54f4475

Browse files
committed
Move Program to application module
1 parent 7e1ef7d commit 54f4475

File tree

29 files changed

+58
-80
lines changed

29 files changed

+58
-80
lines changed

examples/arc/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iced::widget::canvas::{
77
use iced::{Element, Length, Point, Rectangle, Renderer, Subscription, Theme};
88

99
pub fn main() -> iced::Result {
10-
iced::application("Arc - Iced", Arc::update, Arc::view)
10+
iced::program("Arc - Iced", Arc::update, Arc::view)
1111
.subscription(Arc::subscription)
1212
.theme(|_| Theme::Dark)
1313
.antialiasing(true)

examples/bezier_tool/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use iced::widget::{button, column, text};
33
use iced::{Alignment, Element, Length};
44

55
pub fn main() -> iced::Result {
6-
iced::application("Bezier Tool - Iced", Example::update, Example::view)
6+
iced::program("Bezier Tool - Iced", Example::update, Example::view)
77
.antialiasing(true)
88
.run()
99
}

examples/checkbox/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use iced::{Element, Font, Length};
44
const ICON_FONT: Font = Font::with_name("icons");
55

66
pub fn main() -> iced::Result {
7-
iced::application("Checkbox - Iced", Example::update, Example::view)
7+
iced::program("Checkbox - Iced", Example::update, Example::view)
88
.font(include_bytes!("../fonts/icons.ttf").as_slice())
99
.run()
1010
}

examples/clock/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iced::{
88
};
99

1010
pub fn main() -> iced::Result {
11-
iced::application("Clock - Iced", Clock::update, Clock::view)
11+
iced::program("Clock - Iced", Clock::update, Clock::view)
1212
.subscription(Clock::subscription)
1313
.theme(Clock::theme)
1414
.antialiasing(true)

examples/color_palette/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::marker::PhantomData;
1313
use std::ops::RangeInclusive;
1414

1515
pub fn main() -> iced::Result {
16-
iced::application(
16+
iced::program(
1717
"Color Palette - Iced",
1818
ColorPalette::update,
1919
ColorPalette::view,

examples/custom_shader/src/main.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ use iced::window;
99
use iced::{Alignment, Color, Element, Length, Subscription};
1010

1111
fn main() -> iced::Result {
12-
iced::application(
13-
"Custom Shader - Iced",
14-
IcedCubes::update,
15-
IcedCubes::view,
16-
)
17-
.subscription(IcedCubes::subscription)
18-
.run()
12+
iced::program("Custom Shader - Iced", IcedCubes::update, IcedCubes::view)
13+
.subscription(IcedCubes::subscription)
14+
.run()
1915
}
2016

2117
struct IcedCubes {

examples/download_progress/src/main.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ use iced::widget::{button, column, container, progress_bar, text, Column};
44
use iced::{Alignment, Element, Length, Subscription};
55

66
pub fn main() -> iced::Result {
7-
iced::application(
8-
"Download Progress - Iced",
9-
Example::update,
10-
Example::view,
11-
)
12-
.subscription(Example::subscription)
13-
.run()
7+
iced::program("Download Progress - Iced", Example::update, Example::view)
8+
.subscription(Example::subscription)
9+
.run()
1410
}
1511

1612
#[derive(Debug)]

examples/events/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use iced::window;
55
use iced::{Alignment, Command, Element, Length, Subscription};
66

77
pub fn main() -> iced::Result {
8-
iced::application("Events - Iced", Events::update, Events::view)
8+
iced::program("Events - Iced", Events::update, Events::view)
99
.subscription(Events::subscription)
1010
.exit_on_close_request(false)
1111
.run()

examples/exit/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use iced::window;
33
use iced::{Alignment, Command, Element, Length};
44

55
pub fn main() -> iced::Result {
6-
iced::application("Exit - Iced", Exit::update, Exit::view).run()
6+
iced::program("Exit - Iced", Exit::update, Exit::view).run()
77
}
88

99
#[derive(Default)]

examples/gradient/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iced::{Alignment, Color, Element, Length, Radians, Theme};
88
pub fn main() -> iced::Result {
99
tracing_subscriber::fmt::init();
1010

11-
iced::application("Gradient - Iced", Gradient::update, Gradient::view)
11+
iced::program("Gradient - Iced", Gradient::update, Gradient::view)
1212
.style(Gradient::style)
1313
.transparent(true)
1414
.run()

examples/layout/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use iced::{
1010
};
1111

1212
pub fn main() -> iced::Result {
13-
iced::application(Layout::title, Layout::update, Layout::view)
13+
iced::program(Layout::title, Layout::update, Layout::view)
1414
.subscription(Layout::subscription)
1515
.theme(Layout::theme)
1616
.run()

examples/loading_spinners/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use circular::Circular;
1111
use linear::Linear;
1212

1313
pub fn main() -> iced::Result {
14-
iced::application(
14+
iced::program(
1515
"Loading Spinners - Iced",
1616
LoadingSpinners::update,
1717
LoadingSpinners::view,

examples/multitouch/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::collections::HashMap;
1313
pub fn main() -> iced::Result {
1414
tracing_subscriber::fmt::init();
1515

16-
iced::application("Multitouch - Iced", Multitouch::update, Multitouch::view)
16+
iced::program("Multitouch - Iced", Multitouch::update, Multitouch::view)
1717
.antialiasing(true)
1818
.centered()
1919
.run()

examples/pane_grid/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iced::widget::{
77
use iced::{Color, Element, Length, Size, Subscription};
88

99
pub fn main() -> iced::Result {
10-
iced::application("Pane Grid - Iced", Example::update, Example::view)
10+
iced::program("Pane Grid - Iced", Example::update, Example::view)
1111
.subscription(Example::subscription)
1212
.run()
1313
}

examples/pokedex/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use iced::widget::{self, column, container, image, row, text};
33
use iced::{Alignment, Command, Element, Length};
44

55
pub fn main() -> iced::Result {
6-
iced::application(Pokedex::title, Pokedex::update, Pokedex::view)
6+
iced::program(Pokedex::title, Pokedex::update, Pokedex::view)
77
.load(Pokedex::search)
88
.run()
99
}

examples/qr_code/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use iced::widget::{
44
use iced::{Alignment, Element, Length, Theme};
55

66
pub fn main() -> iced::Result {
7-
iced::application(
7+
iced::program(
88
"QR Code Generator - Iced",
99
QRGenerator::update,
1010
QRGenerator::view,

examples/screenshot/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ::image::ColorType;
1313
fn main() -> iced::Result {
1414
tracing_subscriber::fmt::init();
1515

16-
iced::application("Screenshot - Iced", Example::update, Example::view)
16+
iced::program("Screenshot - Iced", Example::update, Example::view)
1717
.subscription(Example::subscription)
1818
.run()
1919
}

examples/scrollable/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use once_cell::sync::Lazy;
1010
static SCROLLABLE_ID: Lazy<scrollable::Id> = Lazy::new(scrollable::Id::unique);
1111

1212
pub fn main() -> iced::Result {
13-
iced::application(
13+
iced::program(
1414
"Scrollable - Iced",
1515
ScrollableDemo::update,
1616
ScrollableDemo::view,

examples/sierpinski_triangle/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rand::Rng;
88
use std::fmt::Debug;
99

1010
fn main() -> iced::Result {
11-
iced::application(
11+
iced::program(
1212
"Sierpinski Triangle - Iced",
1313
SierpinskiEmulator::update,
1414
SierpinskiEmulator::view,

examples/solar_system/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::time::Instant;
2222
pub fn main() -> iced::Result {
2323
tracing_subscriber::fmt::init();
2424

25-
iced::application(
25+
iced::program(
2626
"Solar System - Iced",
2727
SolarSystem::update,
2828
SolarSystem::view,

examples/stopwatch/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iced::{Alignment, Element, Length, Subscription, Theme};
77
use std::time::{Duration, Instant};
88

99
pub fn main() -> iced::Result {
10-
iced::application("Stopwatch - Iced", Stopwatch::update, Stopwatch::view)
10+
iced::program("Stopwatch - Iced", Stopwatch::update, Stopwatch::view)
1111
.subscription(Stopwatch::subscription)
1212
.theme(Stopwatch::theme)
1313
.run()

examples/styling/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use iced::widget::{
66
use iced::{Alignment, Element, Length, Theme};
77

88
pub fn main() -> iced::Result {
9-
iced::application("Styling - Iced", Styling::update, Styling::view)
9+
iced::program("Styling - Iced", Styling::update, Styling::view)
1010
.theme(Styling::theme)
1111
.run()
1212
}

examples/system_information/src/main.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ use iced::widget::{button, column, container, text};
22
use iced::{system, Command, Element, Length};
33

44
pub fn main() -> iced::Result {
5-
iced::application(
6-
"System Information - Iced",
7-
Example::update,
8-
Example::view,
9-
)
10-
.run()
5+
iced::program("System Information - Iced", Example::update, Example::view)
6+
.run()
117
}
128

139
#[derive(Default)]

examples/tour/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn main() -> iced::Result {
1616
#[cfg(not(target_arch = "wasm32"))]
1717
tracing_subscriber::fmt::init();
1818

19-
iced::application(Tour::title, Tour::update, Tour::view)
19+
iced::program(Tour::title, Tour::update, Tour::view)
2020
.centered()
2121
.run()
2222
}

examples/url_handler/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use iced::widget::{container, text};
33
use iced::{Element, Length, Subscription};
44

55
pub fn main() -> iced::Result {
6-
iced::application("URL Handler - Iced", App::update, App::view)
6+
iced::program("URL Handler - Iced", App::update, App::view)
77
.subscription(App::subscription)
88
.run()
99
}

examples/vectorial_text/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use iced::widget::{
66
use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector};
77

88
pub fn main() -> iced::Result {
9-
iced::application(
9+
iced::program(
1010
"Vectorial Text - Iced",
1111
VectorialText::update,
1212
VectorialText::view,

src/application.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Build interactive cross-platform applications.
2-
use crate::{Command, Element, Executor, Settings, Subscription};
2+
mod program;
3+
4+
pub use program::{program, Definition, Program, Title, Update, View};
35

46
use crate::shell::application;
7+
use crate::{Command, Element, Executor, Settings, Subscription};
58

69
pub use application::{default, Appearance, DefaultStyle};
710

src/program.rs src/application/program.rs

+17-27
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
//! Create iced applications out of simple functions.
2-
//!
3-
//! You can use this API to create and run iced applications
4-
//! step by step—without coupling your logic to a trait
5-
//! or a specific type.
6-
//!
7-
//! This API is meant to be a more convenient—although less
8-
//! powerful—alternative to the [`Application`] traits.
9-
//!
10-
//! [`Sandbox`]: crate::Sandbox
111
//!
122
//! # Example
133
//! ```no_run
144
//! use iced::widget::{button, column, text, Column};
155
//! use iced::Theme;
166
//!
177
//! pub fn main() -> iced::Result {
18-
//! iced::application("A counter", update, view)
8+
//! iced::program("A counter", update, view)
199
//! .theme(|_| Theme::Dark)
2010
//! .centered()
2111
//! .run()
@@ -53,7 +43,7 @@ use std::borrow::Cow;
5343
/// use iced::widget::{button, column, text, Column};
5444
///
5545
/// pub fn main() -> iced::Result {
56-
/// iced::application("A counter", update, view).run()
46+
/// iced::program("A counter", update, view).run()
5747
/// }
5848
///
5949
/// #[derive(Debug, Clone)]
@@ -74,7 +64,7 @@ use std::borrow::Cow;
7464
/// ]
7565
/// }
7666
/// ```
77-
pub fn application<State, Message>(
67+
pub fn program<State, Message>(
7868
title: impl Title<State>,
7969
update: impl Update<State, Message>,
8070
view: impl for<'a> self::View<'a, State, Message>,
@@ -139,22 +129,26 @@ where
139129
.title(title)
140130
}
141131

142-
/// A fully functioning and configured iced application.
132+
/// The underlying definition and configuration of an iced [`Application`].
133+
///
134+
/// You can use this API to create and run iced applications
135+
/// step by step—without coupling your logic to a trait
136+
/// or a specific type.
143137
///
144-
/// It can be [`run`]!
138+
/// This API is meant to be a more convenient—although less
139+
/// powerful—alternative to the [`Application`] trait.
145140
///
146-
/// Create one with the [`application`] helper.
141+
/// You can create a [`Program`] with the [`program`] helper.
147142
///
148143
/// [`run`]: Program::run
149-
/// [`application`]: self::application()
150144
#[derive(Debug)]
151145
pub struct Program<P: Definition> {
152146
raw: P,
153147
settings: Settings,
154148
}
155149

156150
impl<P: Definition> Program<P> {
157-
/// Runs the [`Program`].
151+
/// Runs the underlying [`Application`] of the [`Program`].
158152
pub fn run(self) -> Result
159153
where
160154
Self: 'static,
@@ -364,9 +358,7 @@ impl<P: Definition> Program<P> {
364358
/// The internal definition of a [`Program`].
365359
///
366360
/// You should not need to implement this trait directly. Instead, use the
367-
/// helper functions available in the [`program`] module and the [`Program`] struct.
368-
///
369-
/// [`program`]: crate::program
361+
/// methods available in the [`Program`] struct.
370362
#[allow(missing_docs)]
371363
pub trait Definition: Sized {
372364
/// The state of the program.
@@ -748,6 +740,8 @@ fn with_style<P: Definition>(
748740
///
749741
/// This trait is implemented both for `&static str` and
750742
/// any closure `Fn(&State) -> String`.
743+
///
744+
/// This trait allows the [`program`] builder to take any of them.
751745
pub trait Title<State> {
752746
/// Produces the title of the [`Program`].
753747
fn title(&self, state: &State) -> String;
@@ -770,10 +764,8 @@ where
770764

771765
/// The update logic of some [`Program`].
772766
///
773-
/// This trait allows [`application`] to take any closure that
767+
/// This trait allows the [`program`] builder to take any closure that
774768
/// returns any `Into<Command<Message>>`.
775-
///
776-
/// [`application`]: self::application()
777769
pub trait Update<State, Message> {
778770
/// Processes the message and updates the state of the [`Program`].
779771
fn update(
@@ -799,10 +791,8 @@ where
799791

800792
/// The view logic of some [`Program`].
801793
///
802-
/// This trait allows [`application`] to take any closure that
794+
/// This trait allows the [`program`] builder to take any closure that
803795
/// returns any `Into<Element<'_, Message>>`.
804-
///
805-
/// [`application`]: self::application()
806796
pub trait View<'a, State, Message> {
807797
/// Produces the widget of the [`Program`].
808798
fn view(&self, state: &'a State) -> impl Into<Element<'a, Message>>;

0 commit comments

Comments
 (0)