diff options
Diffstat (limited to 'native/src/renderer')
-rw-r--r-- | native/src/renderer/debugger.rs | 25 | ||||
-rw-r--r-- | native/src/renderer/null.rs | 113 | ||||
-rw-r--r-- | native/src/renderer/windowed.rs | 55 |
3 files changed, 97 insertions, 96 deletions
diff --git a/native/src/renderer/debugger.rs b/native/src/renderer/debugger.rs deleted file mode 100644 index 4cc50661..00000000 --- a/native/src/renderer/debugger.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::{Color, Layout, Point, Widget}; - -/// A renderer able to graphically explain a [`Layout`]. -/// -/// [`Layout`]: ../struct.Layout.html -pub trait Debugger: super::Renderer { - /// Explains the [`Layout`] of an [`Element`] for debugging purposes. - /// - /// This will be called when [`Element::explain`] has been used. It should - /// _explain_ the given [`Layout`] graphically. - /// - /// A common approach consists in recursively rendering the bounds of the - /// [`Layout`] and its children. - /// - /// [`Layout`]: struct.Layout.html - /// [`Element`]: struct.Element.html - /// [`Element::explain`]: struct.Element.html#method.explain - fn explain<Message>( - &mut self, - widget: &dyn Widget<Message, Self>, - layout: Layout<'_>, - cursor_position: Point, - color: Color, - ) -> Self::Output; -} diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index 182f033a..0fcce5ad 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -1,20 +1,33 @@ use crate::{ - button, checkbox, column, radio, row, scrollable, text, text_input, - Background, Color, Element, Font, HorizontalAlignment, Layout, Point, + button, checkbox, column, progress_bar, radio, row, scrollable, slider, + text, text_input, Color, Element, Font, HorizontalAlignment, Layout, Point, Rectangle, Renderer, Size, VerticalAlignment, }; /// A renderer that does nothing. +/// +/// It can be useful if you are writing tests! #[derive(Debug, Clone, Copy)] pub struct Null; +impl Null { + /// Creates a new [`Null`] renderer. + /// + /// [`Null`]: struct.Null.html + pub fn new() -> Null { + Null + } +} + impl Renderer for Null { type Output = (); + type Defaults = (); } impl column::Renderer for Null { fn draw<Message>( &mut self, + _defaults: &Self::Defaults, _content: &[Element<'_, Message, Self>], _layout: Layout<'_>, _cursor_position: Point, @@ -25,6 +38,7 @@ impl column::Renderer for Null { impl row::Renderer for Null { fn draw<Message>( &mut self, + _defaults: &Self::Defaults, _content: &[Element<'_, Message, Self>], _layout: Layout<'_>, _cursor_position: Point, @@ -33,9 +47,7 @@ impl row::Renderer for Null { } impl text::Renderer for Null { - fn default_size(&self) -> u16 { - 20 - } + const DEFAULT_SIZE: u16 = 20; fn measure( &self, @@ -49,6 +61,7 @@ impl text::Renderer for Null { fn draw( &mut self, + _defaults: &Self::Defaults, _bounds: Rectangle, _content: &str, _size: u16, @@ -61,13 +74,15 @@ impl text::Renderer for Null { } impl scrollable::Renderer for Null { - fn is_mouse_over_scrollbar( + type Style = (); + + fn scrollbar( &self, _bounds: Rectangle, _content_bounds: Rectangle, - _cursor_position: Point, - ) -> bool { - false + _offset: u32, + ) -> Option<scrollable::Scrollbar> { + None } fn draw( @@ -77,44 +92,73 @@ impl scrollable::Renderer for Null { _content_bounds: Rectangle, _is_mouse_over: bool, _is_mouse_over_scrollbar: bool, + _scrollbar: Option<scrollable::Scrollbar>, _offset: u32, + _style: &Self::Style, _content: Self::Output, ) { } } impl text_input::Renderer for Null { + type Style = (); + fn default_size(&self) -> u16 { 20 } + fn measure_value(&self, _value: &str, _size: u16, _font: Font) -> f32 { + 0.0 + } + + fn offset( + &self, + _text_bounds: Rectangle, + _size: u16, + _value: &text_input::Value, + _state: &text_input::State, + _font: Font, + ) -> f32 { + 0.0 + } + fn draw( &mut self, _bounds: Rectangle, _text_bounds: Rectangle, _cursor_position: Point, _size: u16, + _font: Font, _placeholder: &str, _value: &text_input::Value, _state: &text_input::State, + _style: &Self::Style, ) -> Self::Output { } } impl button::Renderer for Null { - fn draw( + const DEFAULT_PADDING: u16 = 0; + + type Style = (); + + fn draw<Message>( &mut self, + _defaults: &Self::Defaults, _bounds: Rectangle, _cursor_position: Point, + _is_disabled: bool, _is_pressed: bool, - _background: Option<Background>, - _border_radius: u16, - _content: Self::Output, + _style: &Self::Style, + _content: &Element<'_, Message, Self>, + _content_layout: Layout<'_>, ) -> Self::Output { } } impl radio::Renderer for Null { + type Style = (); + fn default_size(&self) -> u32 { 20 } @@ -125,14 +169,16 @@ impl radio::Renderer for Null { _is_selected: bool, _is_mouse_over: bool, _label: Self::Output, + _style: &Self::Style, ) { } } impl checkbox::Renderer for Null { - fn default_size(&self) -> u32 { - 20 - } + type Style = (); + + const DEFAULT_SIZE: u16 = 20; + const DEFAULT_SPACING: u16 = 15; fn draw( &mut self, @@ -140,6 +186,41 @@ impl checkbox::Renderer for Null { _is_checked: bool, _is_mouse_over: bool, _label: Self::Output, + _style: &Self::Style, + ) { + } +} + +impl slider::Renderer for Null { + type Style = (); + + fn height(&self) -> u32 { + 30 + } + + fn draw( + &mut self, + _bounds: Rectangle, + _cursor_position: Point, + _range: std::ops::RangeInclusive<f32>, + _value: f32, + _is_dragging: bool, + _style_sheet: &Self::Style, + ) { + } +} + +impl progress_bar::Renderer for Null { + type Style = (); + + const DEFAULT_HEIGHT: u16 = 30; + + fn draw( + &self, + _bounds: Rectangle, + _range: std::ops::RangeInclusive<f32>, + _value: f32, + _style: &Self::Style, ) { } } diff --git a/native/src/renderer/windowed.rs b/native/src/renderer/windowed.rs deleted file mode 100644 index 813a03f2..00000000 --- a/native/src/renderer/windowed.rs +++ /dev/null @@ -1,55 +0,0 @@ -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<Renderer = Self>; - - /// 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<T: AsRef<str>>( - &mut self, - output: &Self::Output, - overlay: &[T], - target: &mut Self::Target, - ) -> 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<W: HasRawWindowHandle>( - window: &W, - width: u16, - height: u16, - dpi: f32, - renderer: &Self::Renderer, - ) -> Self; - - /// Resizes the current [`Target`]. - /// - /// [`Target`]: trait.Target.html - fn resize( - &mut self, - width: u16, - height: u16, - dpi: f32, - renderer: &Self::Renderer, - ); -} |