Rename theme::Definition to application::StyleSheet

This commit is contained in:
Héctor Ramón Jiménez 2022-05-26 19:02:15 +02:00
parent 3e8f4cdd13
commit 7f3b7075db
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
12 changed files with 37 additions and 27 deletions

View file

@ -2,6 +2,7 @@
use crate::mouse; use crate::mouse;
use crate::{Error, Executor, Runtime}; use crate::{Error, Executor, Runtime};
pub use iced_winit::application::StyleSheet;
pub use iced_winit::Application; pub use iced_winit::Application;
use iced_graphics::window; use iced_graphics::window;
@ -9,7 +10,6 @@ use iced_winit::application;
use iced_winit::conversion; use iced_winit::conversion;
use iced_winit::futures; use iced_winit::futures;
use iced_winit::futures::channel::mpsc; use iced_winit::futures::channel::mpsc;
use iced_winit::theme::{self, Definition as _};
use iced_winit::user_interface; use iced_winit::user_interface;
use iced_winit::{Clipboard, Debug, Proxy, Settings}; use iced_winit::{Clipboard, Debug, Proxy, Settings};
@ -26,7 +26,7 @@ where
A: Application + 'static, A: Application + 'static,
E: Executor + 'static, E: Executor + 'static,
C: window::GLCompositor<Renderer = A::Renderer> + 'static, C: window::GLCompositor<Renderer = A::Renderer> + 'static,
<A::Renderer as iced_native::Renderer>::Theme: theme::Definition, <A::Renderer as iced_native::Renderer>::Theme: StyleSheet,
{ {
use futures::task; use futures::task;
use futures::Future; use futures::Future;
@ -205,7 +205,7 @@ async fn run_instance<A, E, C>(
A: Application + 'static, A: Application + 'static,
E: Executor + 'static, E: Executor + 'static,
C: window::GLCompositor<Renderer = A::Renderer> + 'static, C: window::GLCompositor<Renderer = A::Renderer> + 'static,
<A::Renderer as iced_native::Renderer>::Theme: theme::Definition, <A::Renderer as iced_native::Renderer>::Theme: StyleSheet,
{ {
use glutin::event; use glutin::event;
use iced_winit::futures::stream::StreamExt; use iced_winit::futures::stream::StreamExt;

View file

@ -76,6 +76,7 @@ pub use iced_core::{
Rectangle, Size, Vector, Rectangle, Size, Vector,
}; };
pub use iced_futures::{executor, futures}; pub use iced_futures::{executor, futures};
pub use iced_style::application;
pub use iced_style::theme; pub use iced_style::theme;
#[doc(no_inline)] #[doc(no_inline)]

View file

@ -1,5 +1,5 @@
use crate::application;
use crate::mouse; use crate::mouse;
use crate::theme;
use crate::user_interface::{self, UserInterface}; use crate::user_interface::{self, UserInterface};
use crate::{Clipboard, Command, Debug, Event, Point, Program, Size}; use crate::{Clipboard, Command, Debug, Event, Point, Program, Size};
@ -20,7 +20,7 @@ where
impl<P> State<P> impl<P> State<P>
where where
P: Program + 'static, P: Program + 'static,
<P::Renderer as crate::Renderer>::Theme: theme::Definition, <P::Renderer as crate::Renderer>::Theme: application::StyleSheet,
{ {
/// Creates a new [`State`] with the provided [`Program`], initializing its /// Creates a new [`State`] with the provided [`Program`], initializing its
/// primitive with the given logical bounds and renderer. /// primitive with the given logical bounds and renderer.
@ -168,7 +168,7 @@ fn build_user_interface<'a, P: Program>(
debug: &mut Debug, debug: &mut Debug,
) -> UserInterface<'a, P::Message, P::Renderer> ) -> UserInterface<'a, P::Message, P::Renderer>
where where
<P::Renderer as crate::Renderer>::Theme: theme::Definition, <P::Renderer as crate::Renderer>::Theme: application::StyleSheet,
{ {
debug.view_started(); debug.view_started();
let view = program.view(); let view = program.view();

View file

@ -1,9 +1,9 @@
//! Implement your own event loop to drive a user interface. //! Implement your own event loop to drive a user interface.
use crate::application;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::theme::{self, Definition as _};
use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size}; use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
/// A set of interactive graphical elements with a specific [`Layout`]. /// A set of interactive graphical elements with a specific [`Layout`].
@ -29,7 +29,7 @@ pub struct UserInterface<'a, Message, Renderer> {
impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer> impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer>
where where
Renderer: crate::Renderer, Renderer: crate::Renderer,
Renderer::Theme: theme::Definition, Renderer::Theme: application::StyleSheet,
{ {
/// Builds a user interface for an [`Element`]. /// Builds a user interface for an [`Element`].
/// ///
@ -373,7 +373,10 @@ where
renderer, renderer,
theme, theme,
&renderer::Style { &renderer::Style {
text_color: theme.text_color(), text_color: {
use application::StyleSheet;
theme.text_color()
},
}, },
Layout::new(&self.base), Layout::new(&self.base),
base_cursor, base_cursor,

View file

@ -1,7 +1,8 @@
use crate::theme;
use crate::window; use crate::window;
use crate::{Command, Element, Executor, Settings, Subscription}; use crate::{Command, Element, Executor, Settings, Subscription};
pub use iced_native::application::StyleSheet;
/// An interactive cross-platform application. /// An interactive cross-platform application.
/// ///
/// This trait is the main entrypoint of Iced. Once implemented, you can run /// 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; type Message: std::fmt::Debug + Send;
/// The theme of your [`Application`]. /// The theme of your [`Application`].
type Theme: Default + theme::Definition; type Theme: Default + StyleSheet;
/// The data needed to initialize your [`Application`]. /// The data needed to initialize your [`Application`].
type Flags; type Flags;

View file

@ -174,18 +174,18 @@
#![doc( #![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" 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(missing_debug_implementations)]
#![deny(unused_results)] #![deny(unused_results)]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)] #![forbid(rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
mod application;
mod element; mod element;
mod error; mod error;
mod result; mod result;
mod sandbox; mod sandbox;
pub mod application;
pub mod clipboard; pub mod clipboard;
pub mod executor; pub mod executor;
pub mod keyboard; pub mod keyboard;

View file

@ -95,9 +95,9 @@
//! [the original widgets]: crate::widget //! [the original widgets]: crate::widget
//! [`button::State`]: crate::widget::button::State //! [`button::State`]: crate::widget::button::State
//! [impure `Application`]: crate::Application //! [impure `Application`]: crate::Application
pub mod application;
pub mod widget; pub mod widget;
mod application;
mod sandbox; mod sandbox;
pub use application::Application; pub use application::Application;

View file

@ -1,8 +1,9 @@
use crate::pure::{self, Pure}; use crate::pure::{self, Pure};
use crate::theme;
use crate::window; use crate::window;
use crate::{Command, Executor, Settings, Subscription}; use crate::{Command, Executor, Settings, Subscription};
pub use iced_native::application::StyleSheet;
/// A pure version of [`Application`]. /// A pure version of [`Application`].
/// ///
/// Unlike the impure version, the `view` method of this trait takes an /// 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; type Message: std::fmt::Debug + Send;
/// The theme of your [`Application`]. /// The theme of your [`Application`].
type Theme: Default + theme::Definition; type Theme: Default + StyleSheet;
/// The data needed to initialize your [`Application`]. /// The data needed to initialize your [`Application`].
type Flags; type Flags;

7
style/src/application.rs Normal file
View file

@ -0,0 +1,7 @@
use iced_core::Color;
pub trait StyleSheet {
fn background_color(&self) -> Color;
fn text_color(&self) -> Color;
}

View file

@ -9,6 +9,7 @@
)] )]
pub use iced_core::{Background, Color}; pub use iced_core::{Background, Color};
pub mod application;
pub mod button; pub mod button;
pub mod checkbox; pub mod checkbox;
pub mod container; pub mod container;

View file

@ -2,6 +2,7 @@ mod palette;
pub use self::palette::Palette; pub use self::palette::Palette;
use crate::application;
use crate::button; use crate::button;
use crate::slider; use crate::slider;
@ -35,13 +36,7 @@ impl Default for Theme {
} }
} }
pub trait Definition { impl application::StyleSheet for Theme {
fn background_color(&self) -> Color;
fn text_color(&self) -> Color;
}
impl Definition for Theme {
fn background_color(&self) -> Color { fn background_color(&self) -> Color {
let palette = self.extended_palette(); let palette = self.extended_palette();

View file

@ -6,7 +6,6 @@ pub use state::State;
use crate::clipboard::{self, Clipboard}; use crate::clipboard::{self, Clipboard};
use crate::conversion; use crate::conversion;
use crate::mouse; use crate::mouse;
use crate::theme::{self, Definition as _};
use crate::{ use crate::{
Command, Debug, Error, Executor, Mode, Proxy, Runtime, Settings, Size, Command, Debug, Error, Executor, Mode, Proxy, Runtime, Settings, Size,
Subscription, Subscription,
@ -19,6 +18,8 @@ use iced_graphics::window;
use iced_native::program::Program; use iced_native::program::Program;
use iced_native::user_interface::{self, UserInterface}; use iced_native::user_interface::{self, UserInterface};
pub use iced_native::application::StyleSheet;
use std::mem::ManuallyDrop; use std::mem::ManuallyDrop;
/// An interactive, native cross-platform application. /// An interactive, native cross-platform application.
@ -109,7 +110,7 @@ where
A: Application + 'static, A: Application + 'static,
E: Executor + 'static, E: Executor + 'static,
C: window::Compositor<Renderer = A::Renderer> + 'static, C: window::Compositor<Renderer = A::Renderer> + 'static,
<A::Renderer as iced_native::Renderer>::Theme: theme::Definition, <A::Renderer as iced_native::Renderer>::Theme: StyleSheet,
{ {
use futures::task; use futures::task;
use futures::Future; use futures::Future;
@ -245,7 +246,7 @@ async fn run_instance<A, E, C>(
A: Application + 'static, A: Application + 'static,
E: Executor + 'static, E: Executor + 'static,
C: window::Compositor<Renderer = A::Renderer> + 'static, C: window::Compositor<Renderer = A::Renderer> + 'static,
<A::Renderer as iced_native::Renderer>::Theme: theme::Definition, <A::Renderer as iced_native::Renderer>::Theme: StyleSheet,
{ {
use iced_futures::futures::stream::StreamExt; use iced_futures::futures::stream::StreamExt;
use winit::event; use winit::event;
@ -506,7 +507,7 @@ pub fn build_user_interface<'a, A: Application>(
debug: &mut Debug, debug: &mut Debug,
) -> UserInterface<'a, A::Message, A::Renderer> ) -> UserInterface<'a, A::Message, A::Renderer>
where where
<A::Renderer as crate::Renderer>::Theme: theme::Definition, <A::Renderer as crate::Renderer>::Theme: StyleSheet,
{ {
debug.view_started(); debug.view_started();
let view = application.view(); let view = application.view();