From d09d5d45ae4697eef277dfe30756b91c7d802a94 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 3 Dec 2024 22:03:06 +0100 Subject: Draft `iced_test` crate and test `todos` example --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 8f526cfd..d7628ea1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -479,6 +479,7 @@ use iced_winit::runtime; pub use iced_futures::futures; pub use iced_futures::stream; +pub use iced_test as test; #[cfg(feature = "highlighter")] pub use iced_highlighter as highlighter; @@ -624,6 +625,7 @@ 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 task::Task; -- cgit From 1aeb317f2dbfb63215e6226073e67878ffa6503b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 6 Dec 2024 04:06:41 +0100 Subject: Add image and hash snapshot-based testing to `iced_test` --- src/application.rs | 9 ++++----- src/daemon.rs | 9 ++++----- src/lib.rs | 2 +- src/program.rs | 29 ++++++++++++++--------------- 4 files changed, 23 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 2ba764be..c79ed62b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -31,6 +31,7 @@ //! } //! ``` use crate::program::{self, Program}; +use crate::theme; use crate::window; use crate::{ Element, Executor, Font, Result, Settings, Size, Subscription, Task, @@ -38,8 +39,6 @@ use crate::{ use std::borrow::Cow; -pub use crate::shell::program::{Appearance, DefaultStyle}; - /// Creates an iced [`Application`] given its title, update, and view logic. /// /// # Example @@ -76,7 +75,7 @@ pub fn application( where State: 'static, Message: Send + std::fmt::Debug + 'static, - Theme: Default + DefaultStyle, + Theme: Default + theme::Base, Renderer: program::Renderer, { use std::marker::PhantomData; @@ -94,7 +93,7 @@ where for Instance where Message: Send + std::fmt::Debug + 'static, - Theme: Default + DefaultStyle, + Theme: Default + theme::Base, Renderer: program::Renderer, Update: self::Update, View: for<'a> self::View<'a, State, Message, Theme, Renderer>, @@ -352,7 +351,7 @@ impl Application

{ /// Sets the style logic of the [`Application`]. pub fn style( self, - f: impl Fn(&P::State, &P::Theme) -> Appearance, + f: impl Fn(&P::State, &P::Theme) -> theme::Style, ) -> Application< impl Program, > { diff --git a/src/daemon.rs b/src/daemon.rs index 81254bf9..fd6d0278 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -1,13 +1,12 @@ //! Create and run daemons that run in the background. use crate::application; use crate::program::{self, Program}; +use crate::theme; use crate::window; use crate::{Element, Executor, Font, Result, Settings, Subscription, Task}; use std::borrow::Cow; -pub use crate::shell::program::{Appearance, DefaultStyle}; - /// Creates an iced [`Daemon`] given its title, update, and view logic. /// /// A [`Daemon`] will not open a window by default, but will run silently @@ -26,7 +25,7 @@ pub fn daemon( where State: 'static, Message: Send + std::fmt::Debug + 'static, - Theme: Default + DefaultStyle, + Theme: Default + theme::Base, Renderer: program::Renderer, { use std::marker::PhantomData; @@ -44,7 +43,7 @@ where for Instance where Message: Send + std::fmt::Debug + 'static, - Theme: Default + DefaultStyle, + Theme: Default + theme::Base, Renderer: program::Renderer, Update: application::Update, View: for<'a> self::View<'a, State, Message, Theme, Renderer>, @@ -201,7 +200,7 @@ impl Daemon

{ /// Sets the style logic of the [`Daemon`]. pub fn style( self, - f: impl Fn(&P::State, &P::Theme) -> Appearance, + f: impl Fn(&P::State, &P::Theme) -> theme::Style, ) -> Daemon< impl Program, > { diff --git a/src/lib.rs b/src/lib.rs index d7628ea1..e7486909 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -688,7 +688,7 @@ pub fn run( where State: Default + 'static, Message: std::fmt::Debug + Send + 'static, - Theme: Default + program::DefaultStyle + 'static, + Theme: Default + theme::Base + 'static, Renderer: program::Renderer + 'static, { application(title, update, view).run() diff --git a/src/program.rs b/src/program.rs index 94cb9a7d..ace4da74 100644 --- a/src/program.rs +++ b/src/program.rs @@ -1,11 +1,10 @@ use crate::core::text; use crate::graphics::compositor; use crate::shell; +use crate::theme; use crate::window; use crate::{Element, Executor, Result, Settings, Subscription, Task}; -pub use crate::shell::program::{Appearance, DefaultStyle}; - /// The internal definition of a [`Program`]. /// /// You should not need to implement this trait directly. Instead, use the @@ -19,7 +18,7 @@ pub trait Program: Sized { type Message: Send + std::fmt::Debug + 'static; /// The theme of the program. - type Theme: Default + DefaultStyle; + type Theme: Default + theme::Base; /// The renderer of the program. type Renderer: Renderer; @@ -51,11 +50,11 @@ pub trait Program: Sized { } fn theme(&self, _state: &Self::State, _window: window::Id) -> Self::Theme { - Self::Theme::default() + ::default() } - fn style(&self, _state: &Self::State, theme: &Self::Theme) -> Appearance { - DefaultStyle::default_style(theme) + fn style(&self, _state: &Self::State, theme: &Self::Theme) -> theme::Style { + theme::Base::base(theme) } fn scale_factor(&self, _state: &Self::State, _window: window::Id) -> f64 { @@ -153,7 +152,7 @@ pub trait Program: Sized { self.program.theme(&self.state, window) } - fn style(&self, theme: &Self::Theme) -> Appearance { + fn style(&self, theme: &Self::Theme) -> theme::Style { self.program.style(&self.state, theme) } @@ -252,7 +251,7 @@ pub fn with_title( &self, state: &Self::State, theme: &Self::Theme, - ) -> Appearance { + ) -> theme::Style { self.program.style(state, theme) } @@ -322,7 +321,7 @@ pub fn with_subscription( &self, state: &Self::State, theme: &Self::Theme, - ) -> Appearance { + ) -> theme::Style { self.program.style(state, theme) } @@ -395,7 +394,7 @@ pub fn with_theme( &self, state: &Self::State, theme: &Self::Theme, - ) -> Appearance { + ) -> theme::Style { self.program.style(state, theme) } @@ -409,7 +408,7 @@ pub fn with_theme( pub fn with_style( program: P, - f: impl Fn(&P::State, &P::Theme) -> Appearance, + f: impl Fn(&P::State, &P::Theme) -> theme::Style, ) -> impl Program { struct WithStyle { program: P, @@ -418,7 +417,7 @@ pub fn with_style( impl Program for WithStyle where - F: Fn(&P::State, &P::Theme) -> Appearance, + F: Fn(&P::State, &P::Theme) -> theme::Style, { type State = P::State; type Message = P::Message; @@ -430,7 +429,7 @@ pub fn with_style( &self, state: &Self::State, theme: &Self::Theme, - ) -> Appearance { + ) -> theme::Style { (self.style)(state, theme) } @@ -535,7 +534,7 @@ pub fn with_scale_factor( &self, state: &Self::State, theme: &Self::Theme, - ) -> Appearance { + ) -> theme::Style { self.program.style(state, theme) } @@ -609,7 +608,7 @@ pub fn with_executor( &self, state: &Self::State, theme: &Self::Theme, - ) -> Appearance { + ) -> theme::Style { self.program.style(state, theme) } -- cgit From 1713ac49f2ae794f78f24c01d6c21625b2c2879c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 10 Dec 2024 04:56:37 +0100 Subject: Decouple `iced_test` from `iced` crate --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index e7486909..d13ee7d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -479,7 +479,6 @@ use iced_winit::runtime; pub use iced_futures::futures; pub use iced_futures::stream; -pub use iced_test as test; #[cfg(feature = "highlighter")] pub use iced_highlighter as highlighter; -- cgit From 2cf4abf25bb5702635c19a22353399db8cef7be3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Dec 2024 03:49:24 +0100 Subject: Support custom renderers in `iced_test` through `renderer::Headless` trait --- src/lib.rs | 6 ++---- src/settings.rs | 59 --------------------------------------------------------- 2 files changed, 2 insertions(+), 63 deletions(-) delete mode 100644 src/settings.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index d13ee7d0..427e789c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -491,7 +491,6 @@ mod program; pub mod application; pub mod daemon; -pub mod settings; pub mod time; pub mod window; @@ -506,8 +505,8 @@ pub use crate::core::padding; pub use crate::core::theme; pub use crate::core::{ Alignment, Background, Border, Color, ContentFit, Degrees, Gradient, - Length, Padding, Pixels, Point, Radians, Rectangle, Rotation, Shadow, Size, - Theme, Transformation, Vector, + Length, Padding, Pixels, Point, Radians, Rectangle, Rotation, Settings, + Shadow, Size, Theme, Transformation, Vector, }; pub use crate::runtime::exit; pub use iced_futures::Subscription; @@ -626,7 +625,6 @@ pub use executor::Executor; pub use font::Font; pub use program::Program; pub use renderer::Renderer; -pub use settings::Settings; pub use task::Task; #[doc(inline)] diff --git a/src/settings.rs b/src/settings.rs deleted file mode 100644 index ebac7a86..00000000 --- a/src/settings.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! Configure your application. -use crate::{Font, Pixels}; - -use std::borrow::Cow; - -/// The settings of an iced program. -#[derive(Debug, Clone)] -pub struct Settings { - /// The identifier of the application. - /// - /// If provided, this identifier may be used to identify the application or - /// communicate with it through the windowing system. - pub id: Option, - - /// The fonts to load on boot. - pub fonts: Vec>, - - /// The default [`Font`] to be used. - /// - /// By default, it uses [`Family::SansSerif`](crate::font::Family::SansSerif). - pub default_font: Font, - - /// The text size that will be used by default. - /// - /// The default value is `16.0`. - pub default_text_size: Pixels, - - /// If set to true, the renderer will try to perform antialiasing for some - /// primitives. - /// - /// Enabling it can produce a smoother result in some widgets, like the - /// [`Canvas`], at a performance cost. - /// - /// By default, it is disabled. - /// - /// [`Canvas`]: crate::widget::Canvas - pub antialiasing: bool, -} - -impl Default for Settings { - fn default() -> Self { - Self { - id: None, - fonts: Vec::new(), - default_font: Font::default(), - default_text_size: Pixels(16.0), - antialiasing: false, - } - } -} - -impl From for iced_winit::Settings { - fn from(settings: Settings) -> iced_winit::Settings { - iced_winit::Settings { - id: settings.id, - fonts: settings.fonts, - } - } -} -- cgit