From 65eb218d3d7ba52b2869a586a1480eeb3c8f84e4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 Nov 2019 13:47:20 +0100 Subject: Move widgets from `core` to `native` and `web` Also made fields private and improved `Renderer` traits. --- native/src/renderer/null.rs | 143 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 native/src/renderer/null.rs (limited to 'native/src/renderer') diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs new file mode 100644 index 00000000..8933b09b --- /dev/null +++ b/native/src/renderer/null.rs @@ -0,0 +1,143 @@ +use crate::{ + button, checkbox, column, radio, row, scrollable, text, text_input, + Background, Color, Element, Font, HorizontalAlignment, Layout, Point, + Rectangle, Renderer, Size, VerticalAlignment, +}; + +pub struct Null; + +impl Renderer for Null { + type Output = (); +} + +impl column::Renderer for Null { + fn draw( + &mut self, + _content: &[Element<'_, Message, Self>], + _layout: Layout<'_>, + _cursor_position: Point, + ) { + } +} + +impl row::Renderer for Null { + fn draw( + &mut self, + _content: &[Element<'_, Message, Self>], + _layout: Layout<'_>, + _cursor_position: Point, + ) { + } +} + +impl text::Renderer for Null { + fn default_size(&self) -> u16 { + 20 + } + + fn measure( + &self, + _content: &str, + _size: u16, + _font: Font, + _bounds: Size, + ) -> (f32, f32) { + (0.0, 20.0) + } + + fn draw( + &mut self, + _bounds: Rectangle, + _content: &str, + _size: u16, + _font: Font, + _color: Option, + _horizontal_alignment: HorizontalAlignment, + _vertical_alignment: VerticalAlignment, + ) { + } +} + +impl scrollable::Renderer for Null { + fn is_mouse_over_scrollbar( + &self, + _bounds: Rectangle, + _content_bounds: Rectangle, + _cursor_position: Point, + ) -> bool { + false + } + + fn draw( + &mut self, + _scrollable: &scrollable::State, + _bounds: Rectangle, + _content_bounds: Rectangle, + _is_mouse_over: bool, + _is_mouse_over_scrollbar: bool, + _offset: u32, + _content: Self::Output, + ) { + } +} + +impl text_input::Renderer for Null { + fn default_size(&self) -> u16 { + 20 + } + + fn draw( + &mut self, + _bounds: Rectangle, + _text_bounds: Rectangle, + _cursor_position: Point, + _size: u16, + _placeholder: &str, + _value: &text_input::Value, + _state: &text_input::State, + ) -> Self::Output { + } +} + +impl button::Renderer for Null { + fn draw( + &mut self, + _bounds: Rectangle, + _cursor_position: Point, + _is_pressed: bool, + _background: Option, + _border_radius: u16, + _content: Self::Output, + ) -> Self::Output { + } +} + +impl radio::Renderer for Null { + fn default_size(&self) -> u32 { + 20 + } + + fn draw( + &mut self, + _bounds: Rectangle, + _is_selected: bool, + _is_mouse_over: bool, + _label: Self::Output, + ) { + } +} + +impl checkbox::Renderer for Null { + fn default_size(&self) -> u32 { + 20 + } + + fn draw( + &mut self, + _bounds: Rectangle, + _is_checked: bool, + _is_mouse_over: bool, + _label: Self::Output, + ) { + } +} -- cgit From a7dba612f03e58d7bd9527499d893987986b347c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Nov 2019 19:36:57 +0100 Subject: Write docs for `iced` and `iced_native` --- native/src/renderer/null.rs | 1 + native/src/renderer/windowed.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'native/src/renderer') diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index 8933b09b..3334e6b6 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -4,6 +4,7 @@ use crate::{ Rectangle, Renderer, Size, VerticalAlignment, }; +/// A renderer that does nothing. pub struct Null; impl Renderer for Null { diff --git a/native/src/renderer/windowed.rs b/native/src/renderer/windowed.rs index 6d0419d2..813a03f2 100644 --- a/native/src/renderer/windowed.rs +++ b/native/src/renderer/windowed.rs @@ -2,11 +2,21 @@ use crate::MouseCursor; use raw_window_handle::HasRawWindowHandle; +/// A renderer that can target windows. pub trait Windowed: super::Renderer + Sized { + /// The type of target. type Target: Target; + /// Creates a new [`Windowed`] renderer. + /// + /// [`Windowed`]: trait.Windowed.html fn new() -> Self; + /// Performs the drawing operations described in the output on the given + /// target. + /// + /// The overlay can be a bunch of debug text logs. It should be rendered on + /// top of the GUI on most scenarios. fn draw>( &mut self, output: &Self::Output, @@ -15,9 +25,15 @@ pub trait Windowed: super::Renderer + Sized { ) -> MouseCursor; } +/// A rendering target. pub trait Target { + /// The renderer of this target. type Renderer; + /// Creates a new rendering [`Target`] from the given window handle, width, + /// height and dpi factor. + /// + /// [`Target`]: trait.Target.html fn new( window: &W, width: u16, @@ -26,6 +42,9 @@ pub trait Target { renderer: &Self::Renderer, ) -> Self; + /// Resizes the current [`Target`]. + /// + /// [`Target`]: trait.Target.html fn resize( &mut self, width: u16, -- cgit From d136b7ce648cde0dcdcc5388d8cb82b3e7e0fc58 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Nov 2019 21:16:40 +0100 Subject: Uncomment missing debug implementations rule --- native/src/renderer/null.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'native/src/renderer') diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index 3334e6b6..182f033a 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -5,6 +5,7 @@ use crate::{ }; /// A renderer that does nothing. +#[derive(Debug, Clone, Copy)] pub struct Null; impl Renderer for Null { -- cgit