Move Application trait to advanced module
This commit is contained in:
parent
943b6c9657
commit
cdb18e610a
6 changed files with 48 additions and 51 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use iced::application;
|
||||
use iced::gradient;
|
||||
use iced::program;
|
||||
use iced::widget::{
|
||||
checkbox, column, container, horizontal_space, row, slider, text,
|
||||
};
|
||||
|
|
@ -95,14 +95,16 @@ impl Gradient {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn style(&self, theme: &Theme) -> application::Appearance {
|
||||
fn style(&self, theme: &Theme) -> program::Appearance {
|
||||
use program::DefaultStyle;
|
||||
|
||||
if self.transparent {
|
||||
application::Appearance {
|
||||
program::Appearance {
|
||||
background_color: Color::TRANSPARENT,
|
||||
text_color: theme.palette().text,
|
||||
}
|
||||
} else {
|
||||
application::default(theme)
|
||||
Theme::default_style(theme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
//! Leverage advanced concepts like custom widgets.
|
||||
pub use crate::application::Application;
|
||||
pub use crate::core::clipboard::{self, Clipboard};
|
||||
pub use crate::core::image;
|
||||
pub use crate::core::layout::{self, Layout};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
//! Build interactive cross-platform applications.
|
||||
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};
|
||||
pub use application::{Appearance, DefaultStyle};
|
||||
|
||||
/// An interactive cross-platform application.
|
||||
///
|
||||
|
|
@ -62,8 +58,9 @@ pub use application::{default, Appearance, DefaultStyle};
|
|||
/// says "Hello, world!":
|
||||
///
|
||||
/// ```no_run
|
||||
/// use iced::advanced::Application;
|
||||
/// use iced::executor;
|
||||
/// use iced::{Application, Command, Element, Settings, Theme};
|
||||
/// use iced::{Command, Element, Settings, Theme};
|
||||
///
|
||||
/// pub fn main() -> iced::Result {
|
||||
/// Hello::run(Settings::default())
|
||||
|
|
|
|||
25
src/lib.rs
25
src/lib.rs
|
|
@ -157,11 +157,11 @@
|
|||
//! 1. Draw the resulting user interface.
|
||||
//!
|
||||
//! # Usage
|
||||
//! You can either use the [`program`] builder or implement the [`Application`]
|
||||
//! trait directly.
|
||||
//! Use [`run`] or the [`program`] builder.
|
||||
//!
|
||||
//! [Elm]: https://elm-lang.org/
|
||||
//! [The Elm Architecture]: https://guide.elm-lang.org/architecture/
|
||||
//! [`program`]: program()
|
||||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||
)]
|
||||
|
|
@ -185,9 +185,10 @@ pub use iced_futures::futures;
|
|||
#[cfg(feature = "highlighter")]
|
||||
pub use iced_highlighter as highlighter;
|
||||
|
||||
mod application;
|
||||
mod error;
|
||||
|
||||
pub mod application;
|
||||
pub mod program;
|
||||
pub mod settings;
|
||||
pub mod time;
|
||||
pub mod window;
|
||||
|
|
@ -315,12 +316,12 @@ pub mod widget {
|
|||
mod runtime {}
|
||||
}
|
||||
|
||||
pub use application::Application;
|
||||
pub use command::Command;
|
||||
pub use error::Error;
|
||||
pub use event::Event;
|
||||
pub use executor::Executor;
|
||||
pub use font::Font;
|
||||
pub use program::Program;
|
||||
pub use renderer::Renderer;
|
||||
pub use settings::Settings;
|
||||
pub use subscription::Subscription;
|
||||
|
|
@ -335,9 +336,7 @@ pub type Element<
|
|||
Renderer = crate::Renderer,
|
||||
> = crate::core::Element<'a, Message, Theme, Renderer>;
|
||||
|
||||
/// The result of running an [`Application`].
|
||||
///
|
||||
/// [`Application`]: crate::Application
|
||||
/// The result of running a [`Program`].
|
||||
pub type Result = std::result::Result<(), Error>;
|
||||
|
||||
/// Runs a basic iced application with default [`Settings`] given its title,
|
||||
|
|
@ -345,7 +344,7 @@ pub type Result = std::result::Result<(), Error>;
|
|||
///
|
||||
/// This is equivalent to chaining [`program`] with [`Program::run`].
|
||||
///
|
||||
/// [`Program::run`]: application::Program::run
|
||||
/// [`program`]: program()
|
||||
///
|
||||
/// # Example
|
||||
/// ```no_run
|
||||
|
|
@ -374,17 +373,17 @@ pub type Result = std::result::Result<(), Error>;
|
|||
/// }
|
||||
/// ```
|
||||
pub fn run<State, Message, Theme>(
|
||||
title: impl application::Title<State> + 'static,
|
||||
update: impl application::Update<State, Message> + 'static,
|
||||
view: impl for<'a> application::View<'a, State, Message, Theme> + 'static,
|
||||
title: impl program::Title<State> + 'static,
|
||||
update: impl program::Update<State, Message> + 'static,
|
||||
view: impl for<'a> program::View<'a, State, Message, Theme> + 'static,
|
||||
) -> Result
|
||||
where
|
||||
State: Default + 'static,
|
||||
Message: std::fmt::Debug + Send + 'static,
|
||||
Theme: Default + application::DefaultStyle + 'static,
|
||||
Theme: Default + program::DefaultStyle + 'static,
|
||||
{
|
||||
program(title, update, view).run()
|
||||
}
|
||||
|
||||
#[doc(inline)]
|
||||
pub use application::program;
|
||||
pub use program::program;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//! Create and run iced applications step by step.
|
||||
//!
|
||||
//! # Example
|
||||
//! ```no_run
|
||||
|
|
@ -29,11 +30,13 @@
|
|||
//! ]
|
||||
//! }
|
||||
//! ```
|
||||
use crate::application::{self, Application};
|
||||
use crate::application::Application;
|
||||
use crate::executor::{self, Executor};
|
||||
use crate::window;
|
||||
use crate::{Command, Element, Font, Result, Settings, Size, Subscription};
|
||||
|
||||
pub use crate::application::{Appearance, DefaultStyle};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Creates an iced [`Program`] given its title, update, and view logic.
|
||||
|
|
@ -72,7 +75,7 @@ pub fn program<State, Message, Theme>(
|
|||
where
|
||||
State: 'static,
|
||||
Message: Send + std::fmt::Debug,
|
||||
Theme: Default + application::DefaultStyle,
|
||||
Theme: Default + DefaultStyle,
|
||||
{
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
|
@ -88,7 +91,7 @@ where
|
|||
for Application<State, Message, Theme, Update, View>
|
||||
where
|
||||
Message: Send + std::fmt::Debug,
|
||||
Theme: Default + application::DefaultStyle,
|
||||
Theme: Default + DefaultStyle,
|
||||
Update: self::Update<State, Message>,
|
||||
View: for<'a> self::View<'a, State, Message, Theme>,
|
||||
{
|
||||
|
|
@ -130,15 +133,12 @@ where
|
|||
.title(title)
|
||||
}
|
||||
|
||||
/// The underlying definition and configuration of an 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.
|
||||
///
|
||||
/// This API is meant to be a more convenient—although less
|
||||
/// powerful—alternative to the [`Application`] trait.
|
||||
///
|
||||
/// You can create a [`Program`] with the [`program`] helper.
|
||||
///
|
||||
/// [`run`]: Program::run
|
||||
|
|
@ -229,7 +229,7 @@ impl<P: Definition> Program<P> {
|
|||
self.program.theme(&self.state)
|
||||
}
|
||||
|
||||
fn style(&self, theme: &Self::Theme) -> application::Appearance {
|
||||
fn style(&self, theme: &Self::Theme) -> Appearance {
|
||||
self.program.style(&self.state, theme)
|
||||
}
|
||||
}
|
||||
|
|
@ -391,7 +391,7 @@ impl<P: Definition> Program<P> {
|
|||
/// Sets the style logic of the [`Program`].
|
||||
pub fn style(
|
||||
self,
|
||||
f: impl Fn(&P::State, &P::Theme) -> application::Appearance,
|
||||
f: impl Fn(&P::State, &P::Theme) -> Appearance,
|
||||
) -> Program<
|
||||
impl Definition<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||
> {
|
||||
|
|
@ -415,7 +415,7 @@ pub trait Definition: Sized {
|
|||
type Message: Send + std::fmt::Debug;
|
||||
|
||||
/// The theme of the program.
|
||||
type Theme: Default + application::DefaultStyle;
|
||||
type Theme: Default + DefaultStyle;
|
||||
|
||||
/// The executor of the program.
|
||||
type Executor: Executor;
|
||||
|
|
@ -448,12 +448,8 @@ pub trait Definition: Sized {
|
|||
Self::Theme::default()
|
||||
}
|
||||
|
||||
fn style(
|
||||
&self,
|
||||
_state: &Self::State,
|
||||
theme: &Self::Theme,
|
||||
) -> application::Appearance {
|
||||
application::DefaultStyle::default_style(theme)
|
||||
fn style(&self, _state: &Self::State, theme: &Self::Theme) -> Appearance {
|
||||
DefaultStyle::default_style(theme)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -514,7 +510,7 @@ fn with_title<P: Definition>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Self::Theme,
|
||||
) -> application::Appearance {
|
||||
) -> Appearance {
|
||||
self.program.style(state, theme)
|
||||
}
|
||||
}
|
||||
|
|
@ -578,7 +574,7 @@ fn with_load<P: Definition>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Self::Theme,
|
||||
) -> application::Appearance {
|
||||
) -> Appearance {
|
||||
self.program.style(state, theme)
|
||||
}
|
||||
}
|
||||
|
|
@ -642,7 +638,7 @@ fn with_subscription<P: Definition>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Self::Theme,
|
||||
) -> application::Appearance {
|
||||
) -> Appearance {
|
||||
self.program.style(state, theme)
|
||||
}
|
||||
}
|
||||
|
|
@ -709,7 +705,7 @@ fn with_theme<P: Definition>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Self::Theme,
|
||||
) -> application::Appearance {
|
||||
) -> Appearance {
|
||||
self.program.style(state, theme)
|
||||
}
|
||||
}
|
||||
|
|
@ -719,7 +715,7 @@ fn with_theme<P: Definition>(
|
|||
|
||||
fn with_style<P: Definition>(
|
||||
program: P,
|
||||
f: impl Fn(&P::State, &P::Theme) -> application::Appearance,
|
||||
f: impl Fn(&P::State, &P::Theme) -> Appearance,
|
||||
) -> impl Definition<State = P::State, Message = P::Message, Theme = P::Theme> {
|
||||
struct WithStyle<P, F> {
|
||||
program: P,
|
||||
|
|
@ -728,7 +724,7 @@ fn with_style<P: Definition>(
|
|||
|
||||
impl<P: Definition, F> Definition for WithStyle<P, F>
|
||||
where
|
||||
F: Fn(&P::State, &P::Theme) -> application::Appearance,
|
||||
F: Fn(&P::State, &P::Theme) -> Appearance,
|
||||
{
|
||||
type State = P::State;
|
||||
type Message = P::Message;
|
||||
|
|
@ -739,7 +735,7 @@ fn with_style<P: Definition>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Self::Theme,
|
||||
) -> application::Appearance {
|
||||
) -> Appearance {
|
||||
(self.style)(state, theme)
|
||||
}
|
||||
|
||||
|
|
@ -4,7 +4,9 @@ use crate::{Font, Pixels};
|
|||
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// The settings of an application.
|
||||
/// The settings of an iced [`Program`].
|
||||
///
|
||||
/// [`Program`]: crate::Program
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Settings<Flags = ()> {
|
||||
/// The identifier of the application.
|
||||
|
|
@ -18,9 +20,9 @@ pub struct Settings<Flags = ()> {
|
|||
/// They will be ignored on the Web.
|
||||
pub window: window::Settings,
|
||||
|
||||
/// The data needed to initialize the [`Application`].
|
||||
/// The data needed to initialize the [`Program`].
|
||||
///
|
||||
/// [`Application`]: crate::Application
|
||||
/// [`Program`]: crate::Program
|
||||
pub flags: Flags,
|
||||
|
||||
/// The fonts to load on boot.
|
||||
|
|
@ -49,9 +51,9 @@ pub struct Settings<Flags = ()> {
|
|||
}
|
||||
|
||||
impl<Flags> Settings<Flags> {
|
||||
/// Initialize [`Application`] settings using the given data.
|
||||
/// Initialize [`Program`] settings using the given data.
|
||||
///
|
||||
/// [`Application`]: crate::Application
|
||||
/// [`Program`]: crate::Program
|
||||
pub fn with_flags(flags: Flags) -> Self {
|
||||
let default_settings = Settings::<()>::default();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue