Skip to content

Commit

Permalink
Move Program to application module
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Mar 17, 2024
1 parent 7e1ef7d commit 9cfeebb
Show file tree
Hide file tree
Showing 29 changed files with 53 additions and 63 deletions.
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::application("Arc - Iced", Arc::update, Arc::view)
iced::program("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 @@ -3,7 +3,7 @@ use iced::widget::{button, column, text};
use iced::{Alignment, Element, Length};

pub fn main() -> iced::Result {
iced::application("Bezier Tool - Iced", Example::update, Example::view)
iced::program("Bezier Tool - Iced", Example::update, Example::view)
.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, Length};
const ICON_FONT: Font = Font::with_name("icons");

pub fn main() -> iced::Result {
iced::application("Checkbox - Iced", Example::update, Example::view)
iced::program("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 @@ -8,7 +8,7 @@ use iced::{
};

pub fn main() -> iced::Result {
iced::application("Clock - Iced", Clock::update, Clock::view)
iced::program("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 @@ -13,7 +13,7 @@ use std::marker::PhantomData;
use std::ops::RangeInclusive;

pub fn main() -> iced::Result {
iced::application(
iced::program(
"Color Palette - Iced",
ColorPalette::update,
ColorPalette::view,
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_shader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iced::window;
use iced::{Alignment, Color, Element, Length, Subscription};

Check failure on line 9 in examples/custom_shader/src/main.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/examples/custom_shader/src/main.rs

fn main() -> iced::Result {
iced::application(
iced::program(
"Custom Shader - Iced",
IcedCubes::update,
IcedCubes::view,
Expand Down
2 changes: 1 addition & 1 deletion examples/download_progress/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iced::widget::{button, column, container, progress_bar, text, Column};
use iced::{Alignment, Element, Length, Subscription};

Check failure on line 4 in examples/download_progress/src/main.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/examples/download_progress/src/main.rs

pub fn main() -> iced::Result {
iced::application(
iced::program(
"Download Progress - Iced",
Example::update,
Example::view,
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, Command, Element, Length, Subscription};

pub fn main() -> iced::Result {
iced::application("Events - Iced", Events::update, Events::view)
iced::program("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, Command, Element, Length};

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

#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion examples/gradient/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iced::{Alignment, Color, Element, Length, Radians, Theme};
pub fn main() -> iced::Result {
tracing_subscriber::fmt::init();

iced::application("Gradient - Iced", Gradient::update, Gradient::view)
iced::program("Gradient - Iced", Gradient::update, Gradient::view)
.style(Gradient::style)
.transparent(true)
.run()
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::application(Layout::title, Layout::update, Layout::view)
iced::program(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::application(
iced::program(
"Loading Spinners - Iced",
LoadingSpinners::update,
LoadingSpinners::view,
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::application("Multitouch - Iced", Multitouch::update, Multitouch::view)
iced::program("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::application("Pane Grid - Iced", Example::update, Example::view)
iced::program("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, column, container, image, row, text};
use iced::{Alignment, Command, Element, Length};

pub fn main() -> iced::Result {
iced::application(Pokedex::title, Pokedex::update, Pokedex::view)
iced::program(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 @@ -4,7 +4,7 @@ use iced::widget::{
use iced::{Alignment, Element, Length, Theme};

pub fn main() -> iced::Result {
iced::application(
iced::program(
"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::application("Screenshot - Iced", Example::update, Example::view)
iced::program("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::application(
iced::program(
"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::application(
iced::program(
"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::application(
iced::program(
"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, Length, Subscription, Theme};
use std::time::{Duration, Instant};

pub fn main() -> iced::Result {
iced::application("Stopwatch - Iced", Stopwatch::update, Stopwatch::view)
iced::program("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::application("Styling - Iced", Styling::update, Styling::view)
iced::program("Styling - Iced", Styling::update, Styling::view)
.theme(Styling::theme)
.run()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/system_information/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use iced::widget::{button, column, container, text};
use iced::{system, Command, Element, Length};

Check failure on line 2 in examples/system_information/src/main.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/examples/system_information/src/main.rs

pub fn main() -> iced::Result {
iced::application(
iced::program(
"System Information - Iced",
Example::update,
Example::view,
Expand Down
2 changes: 1 addition & 1 deletion examples/tour/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn main() -> iced::Result {
#[cfg(not(target_arch = "wasm32"))]
tracing_subscriber::fmt::init();

iced::application(Tour::title, Tour::update, Tour::view)
iced::program(Tour::title, Tour::update, Tour::view)
.centered()
.run()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/url_handler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use iced::widget::{container, text};
use iced::{Element, Length, Subscription};

pub fn main() -> iced::Result {
iced::application("URL Handler - Iced", App::update, App::view)
iced::program("URL Handler - Iced", App::update, App::view)
.subscription(App::subscription)
.run()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vectorial_text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iced::widget::{
use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector};

pub fn main() -> iced::Result {
iced::application(
iced::program(
"Vectorial Text - Iced",
VectorialText::update,
VectorialText::view,
Expand Down
5 changes: 4 additions & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Build interactive cross-platform applications.
use crate::{Command, Element, Executor, Settings, Subscription};
mod program;

pub use program::{program, Definition, Program, Title, Update, View};

use crate::shell::application;
use crate::{Command, Element, Executor, Settings, Subscription};

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

Expand Down
44 changes: 17 additions & 27 deletions src/program.rs → src/application/program.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
//! Create iced applications out of simple functions.
//!
//! You can use this API to create and run iced applications
//! step by step—without coupling your logic to a trait
//! or a specific type.
//!
//! This API is meant to be a more convenient—although less
//! powerful—alternative to the [`Application`] traits.
//!
//! [`Sandbox`]: crate::Sandbox
//!
//! # Example
//! ```no_run
//! use iced::widget::{button, column, text, Column};
//! use iced::Theme;
//!
//! pub fn main() -> iced::Result {
//! iced::application("A counter", update, view)
//! iced::program("A counter", update, view)
//! .theme(|_| Theme::Dark)
//! .centered()
//! .run()
Expand Down Expand Up @@ -53,7 +43,7 @@ use std::borrow::Cow;
/// use iced::widget::{button, column, text, Column};
///
/// pub fn main() -> iced::Result {
/// iced::application("A counter", update, view).run()
/// iced::program("A counter", update, view).run()
/// }
///
/// #[derive(Debug, Clone)]
Expand All @@ -74,7 +64,7 @@ use std::borrow::Cow;
/// ]
/// }
/// ```
pub fn application<State, Message>(
pub fn program<State, Message>(
title: impl Title<State>,
update: impl Update<State, Message>,
view: impl for<'a> self::View<'a, State, Message>,
Expand Down Expand Up @@ -139,22 +129,26 @@ where
.title(title)
}

/// A fully functioning and configured iced application.
/// The underlying definition and configuration of an iced [`Application`].
///
/// You can use this API to create and run iced applications
/// step by step—without coupling your logic to a trait
/// or a specific type.
///
/// It can be [`run`]!
/// This API is meant to be a more convenient—although less
/// powerful—alternative to the [`Application`] trait.
///
/// Create one with the [`application`] helper.
/// You can create a [`Program`] with the [`program`] helper.
///
/// [`run`]: Program::run
/// [`application`]: self::application()
#[derive(Debug)]
pub struct Program<P: Definition> {
raw: P,
settings: Settings,
}

impl<P: Definition> Program<P> {
/// Runs the [`Program`].
/// Runs the underlying [`Application`] of the [`Program`].
pub fn run(self) -> Result
where
Self: 'static,
Expand Down Expand Up @@ -364,9 +358,7 @@ impl<P: Definition> Program<P> {
/// The internal definition of a [`Program`].
///
/// You should not need to implement this trait directly. Instead, use the
/// helper functions available in the [`program`] module and the [`Program`] struct.
///
/// [`program`]: crate::program
/// methods available in the [`Program`] struct.
#[allow(missing_docs)]
pub trait Definition: Sized {
/// The state of the program.
Expand Down Expand Up @@ -748,6 +740,8 @@ fn with_style<P: Definition>(
///
/// This trait is implemented both for `&static str` and
/// any closure `Fn(&State) -> String`.
///
/// This trait allows the [`program`] builder to take any of them.
pub trait Title<State> {
/// Produces the title of the [`Program`].
fn title(&self, state: &State) -> String;
Expand All @@ -770,10 +764,8 @@ where

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

/// The view logic of some [`Program`].
///
/// This trait allows [`application`] to take any closure that
/// This trait allows the [`program`] builder to take any closure that
/// returns any `Into<Element<'_, Message>>`.
///
/// [`application`]: self::application()
pub trait View<'a, State, Message> {
/// Produces the widget of the [`Program`].
fn view(&self, state: &'a State) -> impl Into<Element<'a, Message>>;
Expand Down
Loading

0 comments on commit 9cfeebb

Please sign in to comment.