Move Debugger and Windowed to a better location

We move `renderer::Debugger` to `layout::Debugger` and
`renderer::Windowed` to `window::Renderer`.
This commit is contained in:
Héctor Ramón Jiménez 2020-01-10 01:58:55 +01:00
parent d15d1156bd
commit e45497dfd6
10 changed files with 27 additions and 29 deletions

View File

@ -1,6 +1,5 @@
use crate::{ use crate::{
layout, renderer, Clipboard, Color, Event, Hasher, Layout, Length, Point, layout, Clipboard, Color, Event, Hasher, Layout, Length, Point, Widget,
Widget,
}; };
/// A generic [`Widget`]. /// A generic [`Widget`].
@ -195,7 +194,7 @@ where
) -> Element<'a, Message, Renderer> ) -> Element<'a, Message, Renderer>
where where
Message: 'static, Message: 'static,
Renderer: 'a + renderer::Debugger, Renderer: 'a + layout::Debugger,
{ {
Element { Element {
widget: Box::new(Explain::new(self, color.into())), widget: Box::new(Explain::new(self, color.into())),
@ -348,7 +347,7 @@ where
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Explain<'a, Message, Renderer> for Explain<'a, Message, Renderer>
where where
Renderer: crate::Renderer + renderer::Debugger, Renderer: crate::Renderer + layout::Debugger,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.element.widget.width() self.element.widget.width()

View File

@ -1,9 +1,11 @@
//! Position your widgets properly. //! Position your widgets properly.
mod debugger;
mod limits; mod limits;
mod node; mod node;
pub mod flex; pub mod flex;
pub use debugger::Debugger;
pub use limits::Limits; pub use limits::Limits;
pub use node::Node; pub use node::Node;

View File

@ -1,9 +1,9 @@
use crate::{Color, Layout, Point, Widget}; use crate::{Color, Layout, Point, Renderer, Widget};
/// A renderer able to graphically explain a [`Layout`]. /// A renderer able to graphically explain a [`Layout`].
/// ///
/// [`Layout`]: ../struct.Layout.html /// [`Layout`]: struct.Layout.html
pub trait Debugger: super::Renderer { pub trait Debugger: Renderer {
/// Explains the [`Layout`] of an [`Element`] for debugging purposes. /// Explains the [`Layout`] of an [`Element`] for debugging purposes.
/// ///
/// This will be called when [`Element::explain`] has been used. It should /// This will be called when [`Element::explain`] has been used. It should
@ -13,8 +13,8 @@ pub trait Debugger: super::Renderer {
/// [`Layout`] and its children. /// [`Layout`] and its children.
/// ///
/// [`Layout`]: struct.Layout.html /// [`Layout`]: struct.Layout.html
/// [`Element`]: struct.Element.html /// [`Element`]: ../struct.Element.html
/// [`Element::explain`]: struct.Element.html#method.explain /// [`Element::explain`]: ../struct.Element.html#method.explain
fn explain<Message>( fn explain<Message>(
&mut self, &mut self,
defaults: &Self::Defaults, defaults: &Self::Defaults,

View File

@ -14,7 +14,7 @@
//! - A [`Widget`] trait, which is used to implement new widgets: from layout //! - A [`Widget`] trait, which is used to implement new widgets: from layout
//! requirements to event and drawing logic. //! requirements to event and drawing logic.
//! - A bunch of `Renderer` traits, meant to keep the crate renderer-agnostic. //! - A bunch of `Renderer` traits, meant to keep the crate renderer-agnostic.
//! - A [`Windowed`] trait, leveraging [`raw-window-handle`], which can be //! - A [`window::Renderer`] trait, leveraging [`raw-window-handle`], which can be
//! implemented by graphical renderers that target _windows_. Window-based //! implemented by graphical renderers that target _windows_. Window-based
//! shells (like [`iced_winit`]) can use this trait to stay renderer-agnostic. //! shells (like [`iced_winit`]) can use this trait to stay renderer-agnostic.
//! //!
@ -31,7 +31,7 @@
//! [`druid`]: https://github.com/xi-editor/druid //! [`druid`]: https://github.com/xi-editor/druid
//! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle //! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle
//! [`Widget`]: widget/trait.Widget.html //! [`Widget`]: widget/trait.Widget.html
//! [`Windowed`]: renderer/trait.Windowed.html //! [`window::Renderer`]: window/trait.Renderer.html
//! [`UserInterface`]: struct.UserInterface.html //! [`UserInterface`]: struct.UserInterface.html
//! [renderer]: renderer/index.html //! [renderer]: renderer/index.html
#![deny(missing_docs)] #![deny(missing_docs)]

View File

@ -20,12 +20,6 @@
//! [`Checkbox`]: ../widget/checkbox/struct.Checkbox.html //! [`Checkbox`]: ../widget/checkbox/struct.Checkbox.html
//! [`checkbox::Renderer`]: ../widget/checkbox/trait.Renderer.html //! [`checkbox::Renderer`]: ../widget/checkbox/trait.Renderer.html
mod debugger;
mod windowed;
pub use debugger::Debugger;
pub use windowed::{Target, Windowed};
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
mod null; mod null;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]

View File

@ -1,4 +1,6 @@
//! Build window-based GUI applications. //! Build window-based GUI applications.
mod event; mod event;
mod renderer;
pub use event::Event; pub use event::Event;
pub use renderer::{Renderer, Target};

View File

@ -3,16 +3,16 @@ use crate::MouseCursor;
use raw_window_handle::HasRawWindowHandle; use raw_window_handle::HasRawWindowHandle;
/// A renderer that can target windows. /// A renderer that can target windows.
pub trait Windowed: super::Renderer + Sized { pub trait Renderer: crate::Renderer + Sized {
/// The settings of the renderer. /// The settings of the renderer.
type Settings: Default; type Settings: Default;
/// The type of target. /// The type of target.
type Target: Target<Renderer = Self>; type Target: Target<Renderer = Self>;
/// Creates a new [`Windowed`] renderer. /// Creates a new window [`Renderer`].
/// ///
/// [`Windowed`]: trait.Windowed.html /// [`Renderer`]: trait.Renderer.html
fn new(settings: Self::Settings) -> Self; fn new(settings: Self::Settings) -> Self;
/// Performs the drawing operations described in the output on the given /// Performs the drawing operations described in the output on the given

View File

@ -3,8 +3,8 @@ use crate::{
Transformation, Transformation,
}; };
use iced_native::{ use iced_native::{
renderer::{Debugger, Windowed}, layout, window, Background, Color, Layout, MouseCursor, Point, Rectangle,
Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget, Vector, Widget,
}; };
use std::sync::Arc; use std::sync::Arc;
use wgpu::{ use wgpu::{
@ -454,7 +454,7 @@ impl iced_native::Renderer for Renderer {
} }
} }
impl Windowed for Renderer { impl window::Renderer for Renderer {
type Settings = Settings; type Settings = Settings;
type Target = Target; type Target = Target;
@ -472,7 +472,7 @@ impl Windowed for Renderer {
} }
} }
impl Debugger for Renderer { impl layout::Debugger for Renderer {
fn explain<Message>( fn explain<Message>(
&mut self, &mut self,
defaults: &Defaults, defaults: &Defaults,

View File

@ -1,4 +1,5 @@
use crate::{Renderer, Transformation}; use crate::{Renderer, Transformation};
use iced_native::window;
use raw_window_handle::HasRawWindowHandle; use raw_window_handle::HasRawWindowHandle;
@ -31,7 +32,7 @@ impl Target {
} }
} }
impl iced_native::renderer::Target for Target { impl window::Target for Target {
type Renderer = Renderer; type Renderer = Renderer;
fn new<W: HasRawWindowHandle>( fn new<W: HasRawWindowHandle>(

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
container, conversion, container, conversion,
input::{keyboard, mouse}, input::{keyboard, mouse},
renderer::{Target, Windowed},
subscription, window, Cache, Clipboard, Command, Container, Debug, Element, subscription, window, Cache, Clipboard, Command, Container, Debug, Element,
Event, Length, MouseCursor, Settings, Subscription, UserInterface, Event, Length, MouseCursor, Settings, Subscription, UserInterface,
}; };
@ -18,7 +17,7 @@ pub trait Application: Sized {
/// The renderer to use to draw the [`Application`]. /// The renderer to use to draw the [`Application`].
/// ///
/// [`Application`]: trait.Application.html /// [`Application`]: trait.Application.html
type Renderer: Windowed + container::Renderer; type Renderer: window::Renderer + container::Renderer;
/// The type of __messages__ your [`Application`] will produce. /// The type of __messages__ your [`Application`] will produce.
/// ///
@ -83,10 +82,11 @@ pub trait Application: Sized {
/// [`Application`]: trait.Application.html /// [`Application`]: trait.Application.html
fn run( fn run(
settings: Settings, settings: Settings,
renderer_settings: <Self::Renderer as Windowed>::Settings, renderer_settings: <Self::Renderer as window::Renderer>::Settings,
) where ) where
Self: 'static, Self: 'static,
{ {
use window::{Renderer as _, Target as _};
use winit::{ use winit::{
event::{self, WindowEvent}, event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
@ -147,7 +147,7 @@ pub trait Application: Sized {
let mut target = { let mut target = {
let (width, height) = to_physical(size, dpi); let (width, height) = to_physical(size, dpi);
<Self::Renderer as Windowed>::Target::new( <Self::Renderer as window::Renderer>::Target::new(
&window, width, height, dpi as f32, &renderer, &window, width, height, dpi as f32, &renderer,
) )
}; };