From 664251f3f5c7b76f69a97683af1468094bba887f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 May 2022 01:47:55 +0200 Subject: Draft first-class `Theme` support RFC: https://github.com/iced-rs/rfcs/pull/6 --- src/application.rs | 33 ++++++++++++++++-------- src/element.rs | 4 +-- src/lib.rs | 3 +++ src/pure.rs | 4 +-- src/pure/application.rs | 25 +++++++++++++----- src/pure/sandbox.rs | 25 ++++++++++++++---- src/pure/widget.rs | 67 ++++++++++++++++++++++++++++--------------------- src/sandbox.rs | 25 ++++++++++++++---- src/widget.rs | 67 ++++++++++++++++++++++++++++--------------------- 9 files changed, 165 insertions(+), 88 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 11735b93..f05d2c4b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -57,7 +57,7 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription}; /// says "Hello, world!": /// /// ```no_run -/// use iced::{executor, Application, Command, Element, Settings, Text}; +/// use iced::{executor, Application, Command, Element, Settings, Text, Theme}; /// /// pub fn main() -> iced::Result { /// Hello::run(Settings::default()) @@ -67,8 +67,9 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription}; /// /// impl Application for Hello { /// type Executor = executor::Default; -/// type Message = (); /// type Flags = (); +/// type Message = (); +/// type Theme = Theme; /// /// fn new(_flags: ()) -> (Hello, Command) { /// (Hello, Command::none()) @@ -99,6 +100,9 @@ pub trait Application: Sized { /// The type of __messages__ your [`Application`] will produce. type Message: std::fmt::Debug + Send; + /// The theme of your [`Application`]. + type Theme: Default; + /// The data needed to initialize your [`Application`]. type Flags; @@ -129,6 +133,16 @@ pub trait Application: Sized { /// Any [`Command`] returned will be executed immediately in the background. fn update(&mut self, message: Self::Message) -> Command; + /// Returns the widgets to display in the [`Application`]. + /// + /// These widgets can produce __messages__ based on user interaction. + fn view(&mut self) -> Element<'_, Self::Message, Self::Theme>; + + /// Returns the current [`Theme`] of the [`Application`]. + fn theme(&self) -> Self::Theme { + Self::Theme::default() + } + /// Returns the event [`Subscription`] for the current state of the /// application. /// @@ -141,11 +155,6 @@ pub trait Application: Sized { Subscription::none() } - /// Returns the widgets to display in the [`Application`]. - /// - /// These widgets can produce __messages__ based on user interaction. - fn view(&mut self) -> Element<'_, Self::Message>; - /// Returns the current [`Application`] mode. /// /// The runtime will automatically transition your application if a new mode @@ -213,7 +222,7 @@ pub trait Application: Sized { Ok(crate::runtime::application::run::< Instance, Self::Executor, - crate::renderer::window::Compositor, + crate::renderer::window::Compositor, >(settings.into(), renderer_settings)?) } } @@ -224,14 +233,14 @@ impl iced_winit::Program for Instance where A: Application, { - type Renderer = crate::renderer::Renderer; + type Renderer = crate::renderer::Renderer; type Message = A::Message; fn update(&mut self, message: Self::Message) -> Command { self.0.update(message) } - fn view(&mut self) -> Element<'_, Self::Message> { + fn view(&mut self) -> Element<'_, Self::Message, A::Theme> { self.0.view() } } @@ -252,6 +261,10 @@ where self.0.title() } + fn theme(&self) -> A::Theme { + self.0.theme() + } + fn mode(&self) -> iced_winit::Mode { match self.0.mode() { window::Mode::Windowed => iced_winit::Mode::Windowed, diff --git a/src/element.rs b/src/element.rs index 8bad18c1..439a4508 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,5 +1,5 @@ /// A generic widget. /// /// This is an alias of an `iced_native` element with a default `Renderer`. -pub type Element<'a, Message> = - crate::runtime::Element<'a, Message, crate::renderer::Renderer>; +pub type Element<'a, Message, Theme = iced_native::Theme> = + crate::runtime::Element<'a, Message, crate::Renderer>; diff --git a/src/lib.rs b/src/lib.rs index 298beae3..df40ad3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,6 +211,8 @@ use iced_wgpu as renderer; #[cfg(feature = "glow")] use iced_glow as renderer; +pub use iced_native::theme; + #[doc(no_inline)] pub use widget::*; @@ -222,6 +224,7 @@ pub use renderer::Renderer; pub use result::Result; pub use sandbox::Sandbox; pub use settings::Settings; +pub use theme::Theme; pub use runtime::alignment; pub use runtime::futures; diff --git a/src/pure.rs b/src/pure.rs index 7785a104..b2b3ade7 100644 --- a/src/pure.rs +++ b/src/pure.rs @@ -108,5 +108,5 @@ pub use iced_pure::Widget; pub use iced_pure::{Pure, State}; /// A generic, pure [`Widget`]. -pub type Element<'a, Message> = - iced_pure::Element<'a, Message, crate::Renderer>; +pub type Element<'a, Message, Theme = crate::Theme> = + iced_pure::Element<'a, Message, crate::Renderer>; diff --git a/src/pure/application.rs b/src/pure/application.rs index 5f400bea..77f68c9e 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -21,6 +21,9 @@ pub trait Application: Sized { /// The type of __messages__ your [`Application`] will produce. type Message: std::fmt::Debug + Send; + /// The theme of your [`Application`]. + type Theme: Default; + /// The data needed to initialize your [`Application`]. type Flags; @@ -51,6 +54,16 @@ pub trait Application: Sized { /// Any [`Command`] returned will be executed immediately in the background. fn update(&mut self, message: Self::Message) -> Command; + /// Returns the widgets to display in the [`Application`]. + /// + /// These widgets can produce __messages__ based on user interaction. + fn view(&self) -> pure::Element<'_, Self::Message, Self::Theme>; + + /// Returns the current [`Theme`] of the [`Application`]. + fn theme(&self) -> Self::Theme { + Self::Theme::default() + } + /// Returns the event [`Subscription`] for the current state of the /// application. /// @@ -63,11 +76,6 @@ pub trait Application: Sized { Subscription::none() } - /// Returns the widgets to display in the [`Application`]. - /// - /// These widgets can produce __messages__ based on user interaction. - fn view(&self) -> pure::Element<'_, Self::Message>; - /// Returns the current [`Application`] mode. /// /// The runtime will automatically transition your application if a new mode @@ -137,6 +145,7 @@ where type Executor = A::Executor; type Message = A::Message; type Flags = A::Flags; + type Theme = A::Theme; fn new(flags: Self::Flags) -> (Self, Command) { let (application, command) = A::new(flags); @@ -162,12 +171,16 @@ where A::subscription(&self.application) } - fn view(&mut self) -> crate::Element<'_, Self::Message> { + fn view(&mut self) -> crate::Element<'_, Self::Message, Self::Theme> { let content = A::view(&self.application); Pure::new(&mut self.state, content).into() } + fn theme(&self) -> Self::Theme { + A::theme(&self.application) + } + fn mode(&self) -> window::Mode { A::mode(&self.application) } diff --git a/src/pure/sandbox.rs b/src/pure/sandbox.rs index fbd1d7a8..207a32bd 100644 --- a/src/pure/sandbox.rs +++ b/src/pure/sandbox.rs @@ -1,5 +1,5 @@ use crate::pure; -use crate::{Color, Command, Error, Settings, Subscription}; +use crate::{Color, Command, Error, Settings, Subscription, Theme}; /// A pure version of [`Sandbox`]. /// @@ -34,6 +34,16 @@ pub trait Sandbox { /// These widgets can produce __messages__ based on user interaction. fn view(&self) -> pure::Element<'_, Self::Message>; + /// Returns the current [`Theme`] of the [`Sandbox`]. + /// + /// If you want to use your own custom theme type, you will have to use an + /// [`Application`]. + /// + /// By default, it returns [`Theme::default`]. + fn theme(&self) -> Theme { + Theme::default() + } + /// Returns the background color of the [`Sandbox`]. /// /// By default, it returns [`Color::WHITE`]. @@ -82,6 +92,7 @@ where type Executor = iced_futures::backend::null::Executor; type Flags = (); type Message = T::Message; + type Theme = Theme; fn new(_flags: ()) -> (Self, Command) { (T::new(), Command::none()) @@ -97,14 +108,18 @@ where Command::none() } - fn subscription(&self) -> Subscription { - Subscription::none() - } - fn view(&self) -> pure::Element<'_, T::Message> { T::view(self) } + fn theme(&self) -> Self::Theme { + T::theme(self) + } + + fn subscription(&self) -> Subscription { + Subscription::none() + } + fn background_color(&self) -> Color { T::background_color(self) } diff --git a/src/pure/widget.rs b/src/pure/widget.rs index c84edde3..1c0a32a6 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -1,23 +1,24 @@ //! Pure versions of the widgets. /// A container that distributes its contents vertically. -pub type Column<'a, Message> = - iced_pure::widget::Column<'a, Message, crate::Renderer>; +pub type Column<'a, Message, Theme = crate::Theme> = + iced_pure::widget::Column<'a, Message, crate::Renderer>; /// A container that distributes its contents horizontally. -pub type Row<'a, Message> = - iced_pure::widget::Row<'a, Message, crate::Renderer>; +pub type Row<'a, Message, Theme = crate::Theme> = + iced_pure::widget::Row<'a, Message, crate::Renderer>; /// A paragraph of text. -pub type Text = iced_pure::widget::Text; +pub type Text = + iced_pure::widget::Text>; pub mod button { //! Allow your users to perform actions by pressing a button. pub use iced_pure::widget::button::{Style, StyleSheet}; /// A widget that produces a message when clicked. - pub type Button<'a, Message> = - iced_pure::widget::Button<'a, Message, crate::Renderer>; + pub type Button<'a, Message, Theme = crate::Theme> = + iced_pure::widget::Button<'a, Message, crate::Renderer>; } pub mod checkbox { @@ -25,8 +26,8 @@ pub mod checkbox { pub use iced_pure::widget::checkbox::{Style, StyleSheet}; /// A box that can be checked. - pub type Checkbox<'a, Message> = - iced_native::widget::Checkbox<'a, Message, crate::Renderer>; + pub type Checkbox<'a, Message, Theme> = + iced_native::widget::Checkbox<'a, Message, crate::Renderer>; } pub mod container { @@ -34,8 +35,8 @@ pub mod container { pub use iced_pure::widget::container::{Style, StyleSheet}; /// An element decorating some content. - pub type Container<'a, Message> = - iced_pure::widget::Container<'a, Message, crate::Renderer>; + pub type Container<'a, Message, Theme = crate::Theme> = + iced_pure::widget::Container<'a, Message, crate::Renderer>; } pub mod pane_grid { @@ -57,16 +58,24 @@ pub mod pane_grid { /// to completely fill the space available. /// /// [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish) - pub type PaneGrid<'a, Message> = - iced_pure::widget::PaneGrid<'a, Message, crate::Renderer>; + pub type PaneGrid<'a, Message, Theme> = + iced_pure::widget::PaneGrid<'a, Message, crate::Renderer>; /// The content of a [`Pane`]. - pub type Content<'a, Message> = - iced_pure::widget::pane_grid::Content<'a, Message, crate::Renderer>; + pub type Content<'a, Message, Theme> = + iced_pure::widget::pane_grid::Content< + 'a, + Message, + crate::Renderer, + >; /// The title bar of a [`Pane`]. - pub type TitleBar<'a, Message> = - iced_pure::widget::pane_grid::TitleBar<'a, Message, crate::Renderer>; + pub type TitleBar<'a, Message, Theme> = + iced_pure::widget::pane_grid::TitleBar< + 'a, + Message, + crate::Renderer, + >; } pub mod pick_list { @@ -75,8 +84,8 @@ pub mod pick_list { pub use iced_pure::widget::pick_list::{Style, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. - pub type PickList<'a, T, Message> = - iced_pure::widget::PickList<'a, T, Message, crate::Renderer>; + pub type PickList<'a, T, Message, Theme> = + iced_pure::widget::PickList<'a, T, Message, crate::Renderer>; } pub mod radio { @@ -84,8 +93,8 @@ pub mod radio { pub use iced_pure::widget::radio::{Style, StyleSheet}; /// A circular button representing a choice. - pub type Radio<'a, Message> = - iced_pure::widget::Radio<'a, Message, crate::Renderer>; + pub type Radio<'a, Message, Theme> = + iced_pure::widget::Radio<'a, Message, crate::Renderer>; } pub mod scrollable { @@ -94,8 +103,8 @@ pub mod scrollable { /// A widget that can vertically display an infinite amount of content /// with a scrollbar. - pub type Scrollable<'a, Message> = - iced_pure::widget::Scrollable<'a, Message, crate::Renderer>; + pub type Scrollable<'a, Message, Theme> = + iced_pure::widget::Scrollable<'a, Message, crate::Renderer>; } pub mod toggler { @@ -103,8 +112,8 @@ pub mod toggler { pub use iced_pure::widget::toggler::{Style, StyleSheet}; /// A toggler widget. - pub type Toggler<'a, Message> = - iced_pure::widget::Toggler<'a, Message, crate::Renderer>; + pub type Toggler<'a, Message, Theme> = + iced_pure::widget::Toggler<'a, Message, crate::Renderer>; } pub mod text_input { @@ -114,8 +123,8 @@ pub mod text_input { pub use iced_pure::widget::text_input::{Style, StyleSheet}; /// A field that can be filled with text. - pub type TextInput<'a, Message> = - iced_pure::widget::TextInput<'a, Message, Renderer>; + pub type TextInput<'a, Message, Theme> = + iced_pure::widget::TextInput<'a, Message, Renderer>; } pub mod tooltip { @@ -123,8 +132,8 @@ pub mod tooltip { pub use iced_pure::widget::tooltip::Position; /// A widget allowing the selection of a single value from a list of options. - pub type Tooltip<'a, Message> = - iced_pure::widget::Tooltip<'a, Message, crate::Renderer>; + pub type Tooltip<'a, Message, Theme> = + iced_pure::widget::Tooltip<'a, Message, crate::Renderer>; } pub use iced_pure::widget::progress_bar; diff --git a/src/sandbox.rs b/src/sandbox.rs index e7e97920..16819569 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,5 +1,5 @@ use crate::{ - Application, Color, Command, Element, Error, Settings, Subscription, + Application, Color, Command, Element, Error, Settings, Subscription, Theme, }; /// A sandboxed [`Application`]. @@ -111,6 +111,16 @@ pub trait Sandbox { /// These widgets can produce __messages__ based on user interaction. fn view(&mut self) -> Element<'_, Self::Message>; + /// Returns the current [`Theme`] of the [`Sandbox`]. + /// + /// If you want to use your own custom theme type, you will have to use an + /// [`Application`]. + /// + /// By default, it returns [`Theme::default`]. + fn theme(&self) -> Theme { + Theme::default() + } + /// Returns the background color of the [`Sandbox`]. /// /// By default, it returns [`Color::WHITE`]. @@ -159,6 +169,7 @@ where type Executor = iced_futures::backend::null::Executor; type Flags = (); type Message = T::Message; + type Theme = Theme; fn new(_flags: ()) -> (Self, Command) { (T::new(), Command::none()) @@ -174,14 +185,18 @@ where Command::none() } - fn subscription(&self) -> Subscription { - Subscription::none() - } - fn view(&mut self) -> Element<'_, T::Message> { T::view(self) } + fn theme(&self) -> Self::Theme { + T::theme(self) + } + + fn subscription(&self) -> Subscription { + Subscription::none() + } + fn background_color(&self) -> Color { T::background_color(self) } diff --git a/src/widget.rs b/src/widget.rs index 5e2b63fc..e40ed108 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -15,15 +15,16 @@ //! [`TextInput`] has some [`text_input::State`]. /// A container that distributes its contents vertically. -pub type Column<'a, Message> = - iced_native::widget::Column<'a, Message, crate::Renderer>; +pub type Column<'a, Message, Theme = crate::Theme> = + iced_native::widget::Column<'a, Message, crate::Renderer>; /// A container that distributes its contents horizontally. -pub type Row<'a, Message> = - iced_native::widget::Row<'a, Message, crate::Renderer>; +pub type Row<'a, Message, Theme = crate::Theme> = + iced_native::widget::Row<'a, Message, crate::Renderer>; /// A paragraph of text. -pub type Text = iced_native::widget::Text; +pub type Text = + iced_native::widget::Text>; pub mod button { //! Allow your users to perform actions by pressing a button. @@ -32,8 +33,8 @@ pub mod button { pub use iced_native::widget::button::{State, Style, StyleSheet}; /// A widget that produces a message when clicked. - pub type Button<'a, Message> = - iced_native::widget::Button<'a, Message, crate::Renderer>; + pub type Button<'a, Message, Theme = crate::Theme> = + iced_native::widget::Button<'a, Message, crate::Renderer>; } pub mod checkbox { @@ -41,8 +42,8 @@ pub mod checkbox { pub use iced_native::widget::checkbox::{Style, StyleSheet}; /// A box that can be checked. - pub type Checkbox<'a, Message> = - iced_native::widget::Checkbox<'a, Message, crate::Renderer>; + pub type Checkbox<'a, Message, Theme> = + iced_native::widget::Checkbox<'a, Message, crate::Renderer>; } pub mod container { @@ -50,8 +51,8 @@ pub mod container { pub use iced_native::widget::container::{Style, StyleSheet}; /// An element decorating some content. - pub type Container<'a, Message> = - iced_native::widget::Container<'a, Message, crate::Renderer>; + pub type Container<'a, Message, Theme = crate::Theme> = + iced_native::widget::Container<'a, Message, crate::Renderer>; } pub mod pane_grid { @@ -73,16 +74,24 @@ pub mod pane_grid { /// to completely fill the space available. /// /// [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish) - pub type PaneGrid<'a, Message> = - iced_native::widget::PaneGrid<'a, Message, crate::Renderer>; + pub type PaneGrid<'a, Message, Theme> = + iced_native::widget::PaneGrid<'a, Message, crate::Renderer>; /// The content of a [`Pane`]. - pub type Content<'a, Message> = - iced_native::widget::pane_grid::Content<'a, Message, crate::Renderer>; + pub type Content<'a, Message, Theme> = + iced_native::widget::pane_grid::Content< + 'a, + Message, + crate::Renderer, + >; /// The title bar of a [`Pane`]. - pub type TitleBar<'a, Message> = - iced_native::widget::pane_grid::TitleBar<'a, Message, crate::Renderer>; + pub type TitleBar<'a, Message, Theme> = + iced_native::widget::pane_grid::TitleBar< + 'a, + Message, + crate::Renderer, + >; } pub mod pick_list { @@ -91,8 +100,8 @@ pub mod pick_list { pub use iced_native::widget::pick_list::{State, Style, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. - pub type PickList<'a, T, Message> = - iced_native::widget::PickList<'a, T, Message, crate::Renderer>; + pub type PickList<'a, T, Message, Theme> = + iced_native::widget::PickList<'a, T, Message, crate::Renderer>; } pub mod radio { @@ -100,8 +109,8 @@ pub mod radio { pub use iced_native::widget::radio::{Style, StyleSheet}; /// A circular button representing a choice. - pub type Radio<'a, Message> = - iced_native::widget::Radio<'a, Message, crate::Renderer>; + pub type Radio<'a, Message, Theme> = + iced_native::widget::Radio<'a, Message, crate::Renderer>; } pub mod scrollable { @@ -112,8 +121,8 @@ pub mod scrollable { /// A widget that can vertically display an infinite amount of content /// with a scrollbar. - pub type Scrollable<'a, Message> = - iced_native::widget::Scrollable<'a, Message, crate::Renderer>; + pub type Scrollable<'a, Message, Theme> = + iced_native::widget::Scrollable<'a, Message, crate::Renderer>; } pub mod toggler { @@ -121,8 +130,8 @@ pub mod toggler { pub use iced_native::widget::toggler::{Style, StyleSheet}; /// A toggler widget. - pub type Toggler<'a, Message> = - iced_native::widget::Toggler<'a, Message, crate::Renderer>; + pub type Toggler<'a, Message, Theme> = + iced_native::widget::Toggler<'a, Message, crate::Renderer>; } pub mod text_input { @@ -134,8 +143,8 @@ pub mod text_input { pub use iced_native::widget::text_input::{State, Style, StyleSheet}; /// A field that can be filled with text. - pub type TextInput<'a, Message> = - iced_native::widget::TextInput<'a, Message, Renderer>; + pub type TextInput<'a, Message, Theme> = + iced_native::widget::TextInput<'a, Message, Renderer>; } pub mod tooltip { @@ -143,8 +152,8 @@ pub mod tooltip { pub use iced_native::widget::tooltip::Position; /// A widget allowing the selection of a single value from a list of options. - pub type Tooltip<'a, Message> = - iced_native::widget::Tooltip<'a, Message, crate::Renderer>; + pub type Tooltip<'a, Message, Theme> = + iced_native::widget::Tooltip<'a, Message, crate::Renderer>; } pub use iced_native::widget::progress_bar; -- cgit From 03eda9b162012c503ead649e5ccb95b7ef1d10ed Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 25 May 2022 05:01:18 +0200 Subject: Let a `Theme` control the background color of an application ... and remove `Application::background_color` --- src/application.rs | 16 +++------------- src/pure/application.rs | 16 +++------------- src/pure/sandbox.rs | 13 +------------ src/sandbox.rs | 13 +------------ 4 files changed, 8 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index f05d2c4b..01571b56 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,5 +1,6 @@ +use crate::theme; use crate::window; -use crate::{Color, Command, Element, Executor, Settings, Subscription}; +use crate::{Command, Element, Executor, Settings, Subscription}; /// An interactive cross-platform application. /// @@ -101,7 +102,7 @@ pub trait Application: Sized { type Message: std::fmt::Debug + Send; /// The theme of your [`Application`]. - type Theme: Default; + type Theme: Default + theme::Definition; /// The data needed to initialize your [`Application`]. type Flags; @@ -167,13 +168,6 @@ pub trait Application: Sized { window::Mode::Windowed } - /// Returns the background color of the [`Application`]. - /// - /// By default, it returns [`Color::WHITE`]. - fn background_color(&self) -> Color { - Color::WHITE - } - /// Returns the scale factor of the [`Application`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -277,10 +271,6 @@ where self.0.subscription() } - fn background_color(&self) -> Color { - self.0.background_color() - } - fn scale_factor(&self) -> f64 { self.0.scale_factor() } diff --git a/src/pure/application.rs b/src/pure/application.rs index 77f68c9e..1306ab6c 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -1,6 +1,7 @@ use crate::pure::{self, Pure}; +use crate::theme; use crate::window; -use crate::{Color, Command, Executor, Settings, Subscription}; +use crate::{Command, Executor, Settings, Subscription}; /// A pure version of [`Application`]. /// @@ -22,7 +23,7 @@ pub trait Application: Sized { type Message: std::fmt::Debug + Send; /// The theme of your [`Application`]. - type Theme: Default; + type Theme: Default + theme::Definition; /// The data needed to initialize your [`Application`]. type Flags; @@ -88,13 +89,6 @@ pub trait Application: Sized { window::Mode::Windowed } - /// Returns the background color of the [`Application`]. - /// - /// By default, it returns [`Color::WHITE`]. - fn background_color(&self) -> Color { - Color::WHITE - } - /// Returns the scale factor of the [`Application`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -185,10 +179,6 @@ where A::mode(&self.application) } - fn background_color(&self) -> Color { - A::background_color(&self.application) - } - fn scale_factor(&self) -> f64 { A::scale_factor(&self.application) } diff --git a/src/pure/sandbox.rs b/src/pure/sandbox.rs index 207a32bd..a58cace7 100644 --- a/src/pure/sandbox.rs +++ b/src/pure/sandbox.rs @@ -1,5 +1,5 @@ use crate::pure; -use crate::{Color, Command, Error, Settings, Subscription, Theme}; +use crate::{Command, Error, Settings, Subscription, Theme}; /// A pure version of [`Sandbox`]. /// @@ -44,13 +44,6 @@ pub trait Sandbox { Theme::default() } - /// Returns the background color of the [`Sandbox`]. - /// - /// By default, it returns [`Color::WHITE`]. - fn background_color(&self) -> Color { - Color::WHITE - } - /// Returns the scale factor of the [`Sandbox`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -120,10 +113,6 @@ where Subscription::none() } - fn background_color(&self) -> Color { - T::background_color(self) - } - fn scale_factor(&self) -> f64 { T::scale_factor(self) } diff --git a/src/sandbox.rs b/src/sandbox.rs index 16819569..f03562fb 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,5 +1,5 @@ use crate::{ - Application, Color, Command, Element, Error, Settings, Subscription, Theme, + Application, Command, Element, Error, Settings, Subscription, Theme, }; /// A sandboxed [`Application`]. @@ -121,13 +121,6 @@ pub trait Sandbox { Theme::default() } - /// Returns the background color of the [`Sandbox`]. - /// - /// By default, it returns [`Color::WHITE`]. - fn background_color(&self) -> Color { - Color::WHITE - } - /// Returns the scale factor of the [`Sandbox`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -197,10 +190,6 @@ where Subscription::none() } - fn background_color(&self) -> Color { - T::background_color(self) - } - fn scale_factor(&self) -> f64 { T::scale_factor(self) } -- cgit From 7f3b7075db68a215f4331b4bfba1c8ddd1c4d7f3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 May 2022 19:02:15 +0200 Subject: Rename `theme::Definition` to `application::StyleSheet` --- src/application.rs | 5 +++-- src/lib.rs | 4 ++-- src/pure.rs | 2 +- src/pure/application.rs | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 01571b56..b7c8cf9f 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,7 +1,8 @@ -use crate::theme; use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; +pub use iced_native::application::StyleSheet; + /// An interactive cross-platform application. /// /// This trait is the main entrypoint of Iced. Once implemented, you can run @@ -102,7 +103,7 @@ pub trait Application: Sized { type Message: std::fmt::Debug + Send; /// The theme of your [`Application`]. - type Theme: Default + theme::Definition; + type Theme: Default + StyleSheet; /// The data needed to initialize your [`Application`]. type Flags; diff --git a/src/lib.rs b/src/lib.rs index df40ad3e..277740f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,18 +174,18 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] -#![deny(missing_docs)] +//#![deny(missing_docs)] #![deny(missing_debug_implementations)] #![deny(unused_results)] #![forbid(unsafe_code)] #![forbid(rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg))] -mod application; mod element; mod error; mod result; mod sandbox; +pub mod application; pub mod clipboard; pub mod executor; pub mod keyboard; diff --git a/src/pure.rs b/src/pure.rs index b2b3ade7..1efacdf4 100644 --- a/src/pure.rs +++ b/src/pure.rs @@ -95,9 +95,9 @@ //! [the original widgets]: crate::widget //! [`button::State`]: crate::widget::button::State //! [impure `Application`]: crate::Application +pub mod application; pub mod widget; -mod application; mod sandbox; pub use application::Application; diff --git a/src/pure/application.rs b/src/pure/application.rs index 1306ab6c..4a7df13e 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -1,8 +1,9 @@ use crate::pure::{self, Pure}; -use crate::theme; use crate::window; use crate::{Command, Executor, Settings, Subscription}; +pub use iced_native::application::StyleSheet; + /// A pure version of [`Application`]. /// /// Unlike the impure version, the `view` method of this trait takes an @@ -23,7 +24,7 @@ pub trait Application: Sized { type Message: std::fmt::Debug + Send; /// The theme of your [`Application`]. - type Theme: Default + theme::Definition; + type Theme: Default + StyleSheet; /// The data needed to initialize your [`Application`]. type Flags; -- cgit From cf0230072c01ea9523f4d98a3656f5c975b3f347 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 May 2022 23:07:34 +0200 Subject: Rename `Variant` to `Style` and `Style` to `Appearance` --- src/pure/widget.rs | 2 +- src/widget.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index 1c0a32a6..e91cf56a 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -14,7 +14,7 @@ pub type Text = pub mod button { //! Allow your users to perform actions by pressing a button. - pub use iced_pure::widget::button::{Style, StyleSheet}; + pub use iced_pure::widget::button::{Appearance, StyleSheet}; /// A widget that produces a message when clicked. pub type Button<'a, Message, Theme = crate::Theme> = diff --git a/src/widget.rs b/src/widget.rs index e40ed108..51a498b0 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -30,7 +30,7 @@ pub mod button { //! Allow your users to perform actions by pressing a button. //! //! A [`Button`] has some local [`State`]. - pub use iced_native::widget::button::{State, Style, StyleSheet}; + pub use iced_native::widget::button::{Appearance, State, StyleSheet}; /// A widget that produces a message when clicked. pub type Button<'a, Message, Theme = crate::Theme> = -- cgit From 28d09bfff1dde55190986bab10d7aaeb0ceb49de Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 27 May 2022 01:26:57 +0200 Subject: Implement theme styling for `Radio` --- src/pure/widget.rs | 6 +++--- src/widget.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index e91cf56a..04975c0d 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -90,11 +90,11 @@ pub mod pick_list { pub mod radio { //! Create choices using radio buttons. - pub use iced_pure::widget::radio::{Style, StyleSheet}; + pub use iced_pure::widget::radio::{Appearance, StyleSheet}; /// A circular button representing a choice. - pub type Radio<'a, Message, Theme> = - iced_pure::widget::Radio<'a, Message, crate::Renderer>; + pub type Radio = + iced_pure::widget::Radio>; } pub mod scrollable { diff --git a/src/widget.rs b/src/widget.rs index 51a498b0..2f3600b6 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -106,11 +106,11 @@ pub mod pick_list { pub mod radio { //! Create choices using radio buttons. - pub use iced_native::widget::radio::{Style, StyleSheet}; + pub use iced_native::widget::radio::{Appearance, StyleSheet}; /// A circular button representing a choice. - pub type Radio<'a, Message, Theme> = - iced_native::widget::Radio<'a, Message, crate::Renderer>; + pub type Radio = + iced_native::widget::Radio>; } pub mod scrollable { -- cgit From 3e2b6247f72815b6e928237f242c2d66478cf15d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 31 May 2022 05:13:57 +0200 Subject: Implement theme styling for `Toggler` ... and wire up theming to the `styling` example. --- src/pure/widget.rs | 2 +- src/widget.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index 04975c0d..36226109 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -109,7 +109,7 @@ pub mod scrollable { pub mod toggler { //! Show toggle controls using togglers. - pub use iced_pure::widget::toggler::{Style, StyleSheet}; + pub use iced_pure::widget::toggler::{Appearance, StyleSheet}; /// A toggler widget. pub type Toggler<'a, Message, Theme> = diff --git a/src/widget.rs b/src/widget.rs index 2f3600b6..1634a1f2 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -127,7 +127,7 @@ pub mod scrollable { pub mod toggler { //! Show toggle controls using togglers. - pub use iced_native::widget::toggler::{Style, StyleSheet}; + pub use iced_native::widget::toggler::{Appearance, StyleSheet}; /// A toggler widget. pub type Toggler<'a, Message, Theme> = -- cgit From 835877fc636d71c1faaa4826cbfde8e09b3c82ba Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Jun 2022 03:26:53 +0200 Subject: Implement theme styling for `Checkbox` --- src/pure/widget.rs | 2 +- src/widget.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index 36226109..de460bec 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -23,7 +23,7 @@ pub mod button { pub mod checkbox { //! Show toggle controls using checkboxes. - pub use iced_pure::widget::checkbox::{Style, StyleSheet}; + pub use iced_pure::widget::checkbox::{Appearance, StyleSheet}; /// A box that can be checked. pub type Checkbox<'a, Message, Theme> = diff --git a/src/widget.rs b/src/widget.rs index 1634a1f2..4cbf02ef 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -39,7 +39,7 @@ pub mod button { pub mod checkbox { //! Show toggle controls using checkboxes. - pub use iced_native::widget::checkbox::{Style, StyleSheet}; + pub use iced_native::widget::checkbox::{Appearance, StyleSheet}; /// A box that can be checked. pub type Checkbox<'a, Message, Theme> = -- cgit From ce53d3933c860cd958636cce415ac97c04aee746 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 01:11:35 +0200 Subject: Implement theme styling for `TextInput` --- src/pure/widget.rs | 2 +- src/widget.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index de460bec..6ef9262f 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -120,7 +120,7 @@ pub mod text_input { //! Display fields that can be filled with text. use crate::Renderer; - pub use iced_pure::widget::text_input::{Style, StyleSheet}; + pub use iced_pure::widget::text_input::{Appearance, StyleSheet}; /// A field that can be filled with text. pub type TextInput<'a, Message, Theme> = diff --git a/src/widget.rs b/src/widget.rs index 4cbf02ef..8275f6e4 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -140,7 +140,7 @@ pub mod text_input { //! A [`TextInput`] has some local [`State`]. use crate::Renderer; - pub use iced_native::widget::text_input::{State, Style, StyleSheet}; + pub use iced_native::widget::text_input::{Appearance, State, StyleSheet}; /// A field that can be filled with text. pub type TextInput<'a, Message, Theme> = -- cgit From 97555e67af8b4bcc77df69c5e72156e14948150e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 04:11:24 +0200 Subject: Implement theme styling for `Container` --- src/pure/widget.rs | 2 +- src/widget.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index 6ef9262f..a16ff22b 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -32,7 +32,7 @@ pub mod checkbox { pub mod container { //! Decorate content and apply alignment. - pub use iced_pure::widget::container::{Style, StyleSheet}; + pub use iced_pure::widget::container::{Appearance, StyleSheet}; /// An element decorating some content. pub type Container<'a, Message, Theme = crate::Theme> = diff --git a/src/widget.rs b/src/widget.rs index 8275f6e4..5996f578 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -48,7 +48,7 @@ pub mod checkbox { pub mod container { //! Decorate content and apply alignment. - pub use iced_native::widget::container::{Style, StyleSheet}; + pub use iced_native::widget::container::{Appearance, StyleSheet}; /// An element decorating some content. pub type Container<'a, Message, Theme = crate::Theme> = -- cgit From 396735b682433928f52ba777891e14f2fbc703c7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 04:51:44 +0200 Subject: Implement theme styling for `PickList` and `Menu` --- src/pure/widget.rs | 3 +-- src/widget.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index a16ff22b..14cf3512 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -80,8 +80,7 @@ pub mod pane_grid { pub mod pick_list { //! Display a dropdown list of selectable values. - pub use iced_pure::overlay::menu::Style as Menu; - pub use iced_pure::widget::pick_list::{Style, StyleSheet}; + pub use iced_pure::widget::pick_list::{Appearance, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. pub type PickList<'a, T, Message, Theme> = diff --git a/src/widget.rs b/src/widget.rs index 5996f578..0c4ad224 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -96,8 +96,7 @@ pub mod pane_grid { pub mod pick_list { //! Display a dropdown list of selectable values. - pub use iced_native::overlay::menu::Style as Menu; - pub use iced_native::widget::pick_list::{State, Style, StyleSheet}; + pub use iced_native::widget::pick_list::{Appearance, State, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. pub type PickList<'a, T, Message, Theme> = -- cgit From bb07d017e8c8e43ac74f66bf649643bebdc5f71d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 20:07:33 +0200 Subject: Add `Style` variant support to `application::StyleSheet` --- src/application.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index b7c8cf9f..d4297eea 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,7 +1,7 @@ use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; -pub use iced_native::application::StyleSheet; +pub use iced_native::application::{Appearance, StyleSheet}; /// An interactive cross-platform application. /// @@ -141,10 +141,20 @@ pub trait Application: Sized { fn view(&mut self) -> Element<'_, Self::Message, Self::Theme>; /// Returns the current [`Theme`] of the [`Application`]. + /// + /// [`Theme`]: Self::Theme fn theme(&self) -> Self::Theme { Self::Theme::default() } + /// Returns the current [`Style`] of the [`Theme`]. + /// + /// [`Style`]: ::Style + /// [`Theme`]: Self::Theme + fn style(&self) -> ::Style { + ::Style::default() + } + /// Returns the event [`Subscription`] for the current state of the /// application. /// @@ -260,6 +270,10 @@ where self.0.theme() } + fn style(&self) -> ::Style { + self.0.style() + } + fn mode(&self) -> iced_winit::Mode { match self.0.mode() { window::Mode::Windowed => iced_winit::Mode::Windowed, -- cgit From 3514bd1535bc8421c746d981ca488883486de97f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 20:13:14 +0200 Subject: Add `theme::Application` styling support to `Sandbox` --- src/sandbox.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/sandbox.rs b/src/sandbox.rs index f03562fb..3ca3fe8f 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,6 +1,5 @@ -use crate::{ - Application, Command, Element, Error, Settings, Subscription, Theme, -}; +use crate::theme::{self, Theme}; +use crate::{Application, Command, Element, Error, Settings, Subscription}; /// A sandboxed [`Application`]. /// @@ -121,6 +120,13 @@ pub trait Sandbox { Theme::default() } + /// Returns the current style variant of [`theme::Application`]. + /// + /// By default, it returns [`theme::Application::default`]. + fn style(&self) -> theme::Application { + theme::Application::default() + } + /// Returns the scale factor of the [`Sandbox`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -186,6 +192,10 @@ where T::theme(self) } + fn style(&self) -> theme::Application { + T::style(self) + } + fn subscription(&self) -> Subscription { Subscription::none() } -- cgit From 2d6d26cef4e3963a59d4c58e4fc811f246e3e794 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 20:49:57 +0200 Subject: Make widget aliases in `iced` compatible with `iced_native` --- src/pure/widget.rs | 69 +++++++++++++++++++++++------------------------------- src/widget.rs | 69 +++++++++++++++++++++++------------------------------- 2 files changed, 58 insertions(+), 80 deletions(-) (limited to 'src') diff --git a/src/pure/widget.rs b/src/pure/widget.rs index 14cf3512..336f498f 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -1,24 +1,23 @@ //! Pure versions of the widgets. /// A container that distributes its contents vertically. -pub type Column<'a, Message, Theme = crate::Theme> = - iced_pure::widget::Column<'a, Message, crate::Renderer>; +pub type Column<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Column<'a, Message, Renderer>; /// A container that distributes its contents horizontally. -pub type Row<'a, Message, Theme = crate::Theme> = - iced_pure::widget::Row<'a, Message, crate::Renderer>; +pub type Row<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Row<'a, Message, Renderer>; /// A paragraph of text. -pub type Text = - iced_pure::widget::Text>; +pub type Text = iced_pure::widget::Text; pub mod button { //! Allow your users to perform actions by pressing a button. pub use iced_pure::widget::button::{Appearance, StyleSheet}; /// A widget that produces a message when clicked. - pub type Button<'a, Message, Theme = crate::Theme> = - iced_pure::widget::Button<'a, Message, crate::Renderer>; + pub type Button<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Button<'a, Message, Renderer>; } pub mod checkbox { @@ -26,8 +25,8 @@ pub mod checkbox { pub use iced_pure::widget::checkbox::{Appearance, StyleSheet}; /// A box that can be checked. - pub type Checkbox<'a, Message, Theme> = - iced_native::widget::Checkbox<'a, Message, crate::Renderer>; + pub type Checkbox<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Checkbox<'a, Message, Renderer>; } pub mod container { @@ -35,8 +34,8 @@ pub mod container { pub use iced_pure::widget::container::{Appearance, StyleSheet}; /// An element decorating some content. - pub type Container<'a, Message, Theme = crate::Theme> = - iced_pure::widget::Container<'a, Message, crate::Renderer>; + pub type Container<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Container<'a, Message, Renderer>; } pub mod pane_grid { @@ -58,24 +57,16 @@ pub mod pane_grid { /// to completely fill the space available. /// /// [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish) - pub type PaneGrid<'a, Message, Theme> = - iced_pure::widget::PaneGrid<'a, Message, crate::Renderer>; + pub type PaneGrid<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::PaneGrid<'a, Message, Renderer>; /// The content of a [`Pane`]. - pub type Content<'a, Message, Theme> = - iced_pure::widget::pane_grid::Content< - 'a, - Message, - crate::Renderer, - >; + pub type Content<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::pane_grid::Content<'a, Message, Renderer>; /// The title bar of a [`Pane`]. - pub type TitleBar<'a, Message, Theme> = - iced_pure::widget::pane_grid::TitleBar< - 'a, - Message, - crate::Renderer, - >; + pub type TitleBar<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::pane_grid::TitleBar<'a, Message, Renderer>; } pub mod pick_list { @@ -83,8 +74,8 @@ pub mod pick_list { pub use iced_pure::widget::pick_list::{Appearance, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. - pub type PickList<'a, T, Message, Theme> = - iced_pure::widget::PickList<'a, T, Message, crate::Renderer>; + pub type PickList<'a, T, Message, Renderer = crate::Renderer> = + iced_pure::widget::PickList<'a, T, Message, Renderer>; } pub mod radio { @@ -92,8 +83,8 @@ pub mod radio { pub use iced_pure::widget::radio::{Appearance, StyleSheet}; /// A circular button representing a choice. - pub type Radio = - iced_pure::widget::Radio>; + pub type Radio = + iced_pure::widget::Radio; } pub mod scrollable { @@ -102,8 +93,8 @@ pub mod scrollable { /// A widget that can vertically display an infinite amount of content /// with a scrollbar. - pub type Scrollable<'a, Message, Theme> = - iced_pure::widget::Scrollable<'a, Message, crate::Renderer>; + pub type Scrollable<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Scrollable<'a, Message, Renderer>; } pub mod toggler { @@ -111,19 +102,17 @@ pub mod toggler { pub use iced_pure::widget::toggler::{Appearance, StyleSheet}; /// A toggler widget. - pub type Toggler<'a, Message, Theme> = - iced_pure::widget::Toggler<'a, Message, crate::Renderer>; + pub type Toggler<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Toggler<'a, Message, Renderer>; } pub mod text_input { //! Display fields that can be filled with text. - use crate::Renderer; - pub use iced_pure::widget::text_input::{Appearance, StyleSheet}; /// A field that can be filled with text. - pub type TextInput<'a, Message, Theme> = - iced_pure::widget::TextInput<'a, Message, Renderer>; + pub type TextInput<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::TextInput<'a, Message, Renderer>; } pub mod tooltip { @@ -131,8 +120,8 @@ pub mod tooltip { pub use iced_pure::widget::tooltip::Position; /// A widget allowing the selection of a single value from a list of options. - pub type Tooltip<'a, Message, Theme> = - iced_pure::widget::Tooltip<'a, Message, crate::Renderer>; + pub type Tooltip<'a, Message, Renderer = crate::Renderer> = + iced_pure::widget::Tooltip<'a, Message, Renderer>; } pub use iced_pure::widget::progress_bar; diff --git a/src/widget.rs b/src/widget.rs index 0c4ad224..b8b5c493 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -15,16 +15,15 @@ //! [`TextInput`] has some [`text_input::State`]. /// A container that distributes its contents vertically. -pub type Column<'a, Message, Theme = crate::Theme> = - iced_native::widget::Column<'a, Message, crate::Renderer>; +pub type Column<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Column<'a, Message, Renderer>; /// A container that distributes its contents horizontally. -pub type Row<'a, Message, Theme = crate::Theme> = - iced_native::widget::Row<'a, Message, crate::Renderer>; +pub type Row<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Row<'a, Message, Renderer>; /// A paragraph of text. -pub type Text = - iced_native::widget::Text>; +pub type Text = iced_native::widget::Text; pub mod button { //! Allow your users to perform actions by pressing a button. @@ -33,8 +32,8 @@ pub mod button { pub use iced_native::widget::button::{Appearance, State, StyleSheet}; /// A widget that produces a message when clicked. - pub type Button<'a, Message, Theme = crate::Theme> = - iced_native::widget::Button<'a, Message, crate::Renderer>; + pub type Button<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Button<'a, Message, Renderer>; } pub mod checkbox { @@ -42,8 +41,8 @@ pub mod checkbox { pub use iced_native::widget::checkbox::{Appearance, StyleSheet}; /// A box that can be checked. - pub type Checkbox<'a, Message, Theme> = - iced_native::widget::Checkbox<'a, Message, crate::Renderer>; + pub type Checkbox<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Checkbox<'a, Message, Renderer>; } pub mod container { @@ -51,8 +50,8 @@ pub mod container { pub use iced_native::widget::container::{Appearance, StyleSheet}; /// An element decorating some content. - pub type Container<'a, Message, Theme = crate::Theme> = - iced_native::widget::Container<'a, Message, crate::Renderer>; + pub type Container<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Container<'a, Message, Renderer>; } pub mod pane_grid { @@ -74,24 +73,16 @@ pub mod pane_grid { /// to completely fill the space available. /// /// [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish) - pub type PaneGrid<'a, Message, Theme> = - iced_native::widget::PaneGrid<'a, Message, crate::Renderer>; + pub type PaneGrid<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::PaneGrid<'a, Message, Renderer>; /// The content of a [`Pane`]. - pub type Content<'a, Message, Theme> = - iced_native::widget::pane_grid::Content< - 'a, - Message, - crate::Renderer, - >; + pub type Content<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::pane_grid::Content<'a, Message, Renderer>; /// The title bar of a [`Pane`]. - pub type TitleBar<'a, Message, Theme> = - iced_native::widget::pane_grid::TitleBar< - 'a, - Message, - crate::Renderer, - >; + pub type TitleBar<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::pane_grid::TitleBar<'a, Message, Renderer>; } pub mod pick_list { @@ -99,8 +90,8 @@ pub mod pick_list { pub use iced_native::widget::pick_list::{Appearance, State, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. - pub type PickList<'a, T, Message, Theme> = - iced_native::widget::PickList<'a, T, Message, crate::Renderer>; + pub type PickList<'a, T, Message, Renderer = crate::Renderer> = + iced_native::widget::PickList<'a, T, Message, Renderer>; } pub mod radio { @@ -108,8 +99,8 @@ pub mod radio { pub use iced_native::widget::radio::{Appearance, StyleSheet}; /// A circular button representing a choice. - pub type Radio = - iced_native::widget::Radio>; + pub type Radio = + iced_native::widget::Radio; } pub mod scrollable { @@ -120,8 +111,8 @@ pub mod scrollable { /// A widget that can vertically display an infinite amount of content /// with a scrollbar. - pub type Scrollable<'a, Message, Theme> = - iced_native::widget::Scrollable<'a, Message, crate::Renderer>; + pub type Scrollable<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Scrollable<'a, Message, Renderer>; } pub mod toggler { @@ -129,21 +120,19 @@ pub mod toggler { pub use iced_native::widget::toggler::{Appearance, StyleSheet}; /// A toggler widget. - pub type Toggler<'a, Message, Theme> = - iced_native::widget::Toggler<'a, Message, crate::Renderer>; + pub type Toggler<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Toggler<'a, Message, Renderer>; } pub mod text_input { //! Display fields that can be filled with text. //! //! A [`TextInput`] has some local [`State`]. - use crate::Renderer; - pub use iced_native::widget::text_input::{Appearance, State, StyleSheet}; /// A field that can be filled with text. - pub type TextInput<'a, Message, Theme> = - iced_native::widget::TextInput<'a, Message, Renderer>; + pub type TextInput<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::TextInput<'a, Message, Renderer>; } pub mod tooltip { @@ -151,8 +140,8 @@ pub mod tooltip { pub use iced_native::widget::tooltip::Position; /// A widget allowing the selection of a single value from a list of options. - pub type Tooltip<'a, Message, Theme> = - iced_native::widget::Tooltip<'a, Message, crate::Renderer>; + pub type Tooltip<'a, Message, Renderer = crate::Renderer> = + iced_native::widget::Tooltip<'a, Message, Renderer>; } pub use iced_native::widget::progress_bar; -- cgit From 48bc505cb6fe85b6568715de4c8b4067603f8fb0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 23:20:25 +0200 Subject: Fix missing docs in `iced` crate --- src/application.rs | 1 + src/lib.rs | 2 +- src/pure/application.rs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index d4297eea..4edfb063 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,3 +1,4 @@ +//! Build interactive cross-platform applications. use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; diff --git a/src/lib.rs b/src/lib.rs index 277740f3..d64941f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,7 +174,7 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] -//#![deny(missing_docs)] +#![deny(missing_docs)] #![deny(missing_debug_implementations)] #![deny(unused_results)] #![forbid(unsafe_code)] diff --git a/src/pure/application.rs b/src/pure/application.rs index 4a7df13e..af9b078b 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -1,3 +1,4 @@ +//! Build interactive cross-platform applications. use crate::pure::{self, Pure}; use crate::window; use crate::{Command, Executor, Settings, Subscription}; -- cgit From 4407385fbe629eb079b0166649492da5f689ea95 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 23:38:34 +0200 Subject: Make `Element` aliases in `iced` compatible with `iced_native` and `iced_pure` --- src/application.rs | 8 +++++--- src/element.rs | 4 ++-- src/pure.rs | 4 ++-- src/pure/application.rs | 8 ++++++-- 4 files changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 4edfb063..e8d8e982 100644 --- a/src/application.rs +++ b/src/application.rs @@ -139,7 +139,9 @@ pub trait Application: Sized { /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. - fn view(&mut self) -> Element<'_, Self::Message, Self::Theme>; + fn view( + &mut self, + ) -> Element<'_, Self::Message, crate::Renderer>; /// Returns the current [`Theme`] of the [`Application`]. /// @@ -239,14 +241,14 @@ impl iced_winit::Program for Instance where A: Application, { - type Renderer = crate::renderer::Renderer; + type Renderer = crate::Renderer; type Message = A::Message; fn update(&mut self, message: Self::Message) -> Command { self.0.update(message) } - fn view(&mut self) -> Element<'_, Self::Message, A::Theme> { + fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer> { self.0.view() } } diff --git a/src/element.rs b/src/element.rs index 439a4508..6851bc4e 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,5 +1,5 @@ /// A generic widget. /// /// This is an alias of an `iced_native` element with a default `Renderer`. -pub type Element<'a, Message, Theme = iced_native::Theme> = - crate::runtime::Element<'a, Message, crate::Renderer>; +pub type Element<'a, Message, Renderer = crate::Renderer> = + crate::runtime::Element<'a, Message, Renderer>; diff --git a/src/pure.rs b/src/pure.rs index 1efacdf4..ca805ecc 100644 --- a/src/pure.rs +++ b/src/pure.rs @@ -108,5 +108,5 @@ pub use iced_pure::Widget; pub use iced_pure::{Pure, State}; /// A generic, pure [`Widget`]. -pub type Element<'a, Message, Theme = crate::Theme> = - iced_pure::Element<'a, Message, crate::Renderer>; +pub type Element<'a, Message, Renderer = crate::Renderer> = + iced_pure::Element<'a, Message, Renderer>; diff --git a/src/pure/application.rs b/src/pure/application.rs index af9b078b..396854ad 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -60,7 +60,9 @@ pub trait Application: Sized { /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. - fn view(&self) -> pure::Element<'_, Self::Message, Self::Theme>; + fn view( + &self, + ) -> pure::Element<'_, Self::Message, crate::Renderer>; /// Returns the current [`Theme`] of the [`Application`]. fn theme(&self) -> Self::Theme { @@ -167,7 +169,9 @@ where A::subscription(&self.application) } - fn view(&mut self) -> crate::Element<'_, Self::Message, Self::Theme> { + fn view( + &mut self, + ) -> crate::Element<'_, Self::Message, crate::Renderer> { let content = A::view(&self.application); Pure::new(&mut self.state, content).into() -- cgit From 7105db97a53d90adf429091298f31c90974d8f08 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 23:43:18 +0200 Subject: Remove redundant `crate::Theme` in alias of `Element` --- src/element.rs | 2 +- src/pure.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/element.rs b/src/element.rs index 6851bc4e..2eb1bb4d 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,5 +1,5 @@ /// A generic widget. /// /// This is an alias of an `iced_native` element with a default `Renderer`. -pub type Element<'a, Message, Renderer = crate::Renderer> = +pub type Element<'a, Message, Renderer = crate::Renderer> = crate::runtime::Element<'a, Message, Renderer>; diff --git a/src/pure.rs b/src/pure.rs index ca805ecc..23f56570 100644 --- a/src/pure.rs +++ b/src/pure.rs @@ -108,5 +108,5 @@ pub use iced_pure::Widget; pub use iced_pure::{Pure, State}; /// A generic, pure [`Widget`]. -pub type Element<'a, Message, Renderer = crate::Renderer> = +pub type Element<'a, Message, Renderer = crate::Renderer> = iced_pure::Element<'a, Message, Renderer>; -- cgit