Rename compositor::Renderer to Default

This commit is contained in:
Héctor Ramón Jiménez 2024-03-22 19:35:19 +01:00
parent a2c897792c
commit 441e9237cd
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
9 changed files with 26 additions and 21 deletions

View file

@ -10,11 +10,11 @@ use std::borrow::Cow;
/// ///
/// [`Renderer`]: crate::Renderer /// [`Renderer`]: crate::Renderer
pub trait Backend: Sized { pub trait Backend: Sized {
/// The compositor of this [`Backend`].
type Compositor: Compositor<Renderer = Renderer<Self>>;
/// The custom kind of primitives this [`Backend`] supports. /// The custom kind of primitives this [`Backend`] supports.
type Primitive: TryFrom<Mesh, Error = &'static str>; type Primitive: TryFrom<Mesh, Error = &'static str>;
/// The default compositor of this [`Backend`].
type Compositor: Compositor<Renderer = Renderer<Self>>;
} }
/// A graphics backend that supports text rendering. /// A graphics backend that supports text rendering.

View file

@ -1,6 +1,5 @@
//! A compositor is responsible for initializing a renderer and managing window //! A compositor is responsible for initializing a renderer and managing window
//! surfaces. //! surfaces.
use crate::core;
use crate::core::Color; use crate::core::Color;
use crate::futures::{MaybeSend, MaybeSync}; use crate::futures::{MaybeSend, MaybeSync};
use crate::{Error, Settings, Viewport}; use crate::{Error, Settings, Viewport};
@ -90,8 +89,8 @@ impl<T> Window for T where
{ {
} }
/// A renderer that supports composition. /// Defines the default compositor of a renderer.
pub trait Renderer: core::Renderer { pub trait Default {
/// The compositor of the renderer. /// The compositor of the renderer.
type Compositor: Compositor<Renderer = Self>; type Compositor: Compositor<Renderer = Self>;
} }
@ -187,6 +186,6 @@ impl Compositor for () {
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
impl Renderer for () { impl Default for () {
type Compositor = (); type Compositor = ();
} }

View file

@ -261,7 +261,7 @@ where
} }
} }
impl<B> compositor::Renderer for Renderer<B> impl<B> compositor::Default for Renderer<B>
where where
B: Backend, B: Backend,
{ {

View file

@ -524,10 +524,10 @@ mod geometry {
} }
} }
impl<L, R> compositor::Renderer for Renderer<L, R> impl<L, R> compositor::Default for Renderer<L, R>
where where
L: compositor::Renderer, L: compositor::Default,
R: compositor::Renderer, R: compositor::Default,
{ {
type Compositor = Compositor<L::Compositor, R::Compositor>; type Compositor = Compositor<L::Compositor, R::Compositor>;
} }

View file

@ -113,7 +113,7 @@ where
type Theme: Default; type Theme: Default;
/// The renderer of your [`Application`]. /// The renderer of your [`Application`].
type Renderer: text::Renderer + compositor::Renderer; type Renderer: text::Renderer + compositor::Default;
/// The data needed to initialize your [`Application`]. /// The data needed to initialize your [`Application`].
type Flags; type Flags;
@ -215,7 +215,7 @@ where
let run = crate::shell::application::run::< let run = crate::shell::application::run::<
Instance<Self>, Instance<Self>,
Self::Executor, Self::Executor,
<Self::Renderer as compositor::Renderer>::Compositor, <Self::Renderer as compositor::Default>::Compositor,
>(settings.into(), renderer_settings); >(settings.into(), renderer_settings);
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]

View file

@ -381,7 +381,7 @@ where
State: Default + 'static, State: Default + 'static,
Message: std::fmt::Debug + Send + 'static, Message: std::fmt::Debug + Send + 'static,
Theme: Default + program::DefaultStyle + 'static, Theme: Default + program::DefaultStyle + 'static,
Renderer: graphics::compositor::Renderer + core::text::Renderer + 'static, Renderer: program::Renderer + 'static,
{ {
program(title, update, view).run() program(title, update, view).run()
} }

View file

@ -31,6 +31,7 @@
//! } //! }
//! ``` //! ```
use crate::application::Application; use crate::application::Application;
use crate::core::text;
use crate::executor::{self, Executor}; use crate::executor::{self, Executor};
use crate::graphics::compositor; use crate::graphics::compositor;
use crate::window; use crate::window;
@ -77,7 +78,7 @@ where
State: 'static, State: 'static,
Message: Send + std::fmt::Debug, Message: Send + std::fmt::Debug,
Theme: Default + DefaultStyle, Theme: Default + DefaultStyle,
Renderer: compositor::Renderer + crate::core::text::Renderer, Renderer: self::Renderer,
{ {
use std::marker::PhantomData; use std::marker::PhantomData;
@ -95,7 +96,7 @@ where
where where
Message: Send + std::fmt::Debug, Message: Send + std::fmt::Debug,
Theme: Default + DefaultStyle, Theme: Default + DefaultStyle,
Renderer: compositor::Renderer + crate::core::text::Renderer, Renderer: self::Renderer,
Update: self::Update<State, Message>, Update: self::Update<State, Message>,
View: for<'a> self::View<'a, State, Message, Theme, Renderer>, View: for<'a> self::View<'a, State, Message, Theme, Renderer>,
{ {
@ -425,7 +426,7 @@ pub trait Definition: Sized {
type Theme: Default + DefaultStyle; type Theme: Default + DefaultStyle;
/// The renderer of the program. /// The renderer of the program.
type Renderer: compositor::Renderer + crate::core::text::Renderer; type Renderer: Renderer + crate::core::text::Renderer;
/// The executor of the program. /// The executor of the program.
type Executor: Executor; type Executor: Executor;
@ -871,3 +872,8 @@ where
self(state) self(state)
} }
} }
/// The renderer of some [`Program`].
pub trait Renderer: text::Renderer + compositor::Default {}
impl<T> Renderer for T where T: text::Renderer + compositor::Default {}

View file

@ -990,9 +990,9 @@ fn rounded_box_sdf(
(x.powf(2.0) + y.powf(2.0)).sqrt() - radius (x.powf(2.0) + y.powf(2.0)).sqrt() - radius
} }
impl iced_graphics::Backend for Backend { impl backend::Backend for Backend {
type Compositor = window::Compositor;
type Primitive = primitive::Custom; type Primitive = primitive::Custom;
type Compositor = window::Compositor;
} }
impl backend::Text for Backend { impl backend::Text for Backend {

View file

@ -372,9 +372,9 @@ impl Backend {
} }
} }
impl crate::graphics::Backend for Backend { impl backend::Backend for Backend {
type Compositor = window::Compositor;
type Primitive = primitive::Custom; type Primitive = primitive::Custom;
type Compositor = window::Compositor;
} }
impl backend::Text for Backend { impl backend::Text for Backend {