From 03b34931383e701c39c653a7662a616fe21a0947 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 14 Oct 2021 16:07:22 +0700 Subject: Remove trait-specific draw logic in `iced_native` --- graphics/src/widget/toggler.rs | 80 +----------------------------------------- 1 file changed, 1 insertion(+), 79 deletions(-) (limited to 'graphics/src/widget/toggler.rs') diff --git a/graphics/src/widget/toggler.rs b/graphics/src/widget/toggler.rs index 852d18ee..cd072f7c 100644 --- a/graphics/src/widget/toggler.rs +++ b/graphics/src/widget/toggler.rs @@ -1,19 +1,10 @@ //! Show toggle controls using togglers. use crate::backend::{self, Backend}; -use crate::{Primitive, Renderer}; -use iced_native::mouse; +use crate::Renderer; use iced_native::toggler; -use iced_native::Rectangle; pub use iced_style::toggler::{Style, StyleSheet}; -/// Makes sure that the border radius of the toggler looks good at every size. -const BORDER_RADIUS_RATIO: f32 = 32.0 / 13.0; - -/// The space ratio between the background Quad and the Toggler bounds, and -/// between the background Quad and foreground Quad. -const SPACE_RATIO: f32 = 0.05; - /// A toggler that can be toggled. /// /// This is an alias of an `iced_native` toggler with an `iced_wgpu::Renderer`. @@ -27,73 +18,4 @@ where type Style = Box; const DEFAULT_SIZE: u16 = 20; - - fn draw( - &mut self, - bounds: Rectangle, - is_active: bool, - is_mouse_over: bool, - label: Option, - style_sheet: &Self::Style, - ) -> Self::Output { - let style = if is_mouse_over { - style_sheet.hovered(is_active) - } else { - style_sheet.active(is_active) - }; - - let border_radius = bounds.height as f32 / BORDER_RADIUS_RATIO; - let space = SPACE_RATIO * bounds.height as f32; - - let toggler_background_bounds = Rectangle { - x: bounds.x + space, - y: bounds.y + space, - width: bounds.width - (2.0 * space), - height: bounds.height - (2.0 * space), - }; - - let toggler_background = Primitive::Quad { - bounds: toggler_background_bounds, - background: style.background.into(), - border_radius, - border_width: 1.0, - border_color: style.background_border.unwrap_or(style.background), - }; - - let toggler_foreground_bounds = Rectangle { - x: bounds.x - + if is_active { - bounds.width - 2.0 * space - (bounds.height - (4.0 * space)) - } else { - 2.0 * space - }, - y: bounds.y + (2.0 * space), - width: bounds.height - (4.0 * space), - height: bounds.height - (4.0 * space), - }; - - let toggler_foreground = Primitive::Quad { - bounds: toggler_foreground_bounds, - background: style.foreground.into(), - border_radius, - border_width: 1.0, - border_color: style.foreground_border.unwrap_or(style.foreground), - }; - - ( - Primitive::Group { - primitives: match label { - Some((l, _)) => { - vec![l, toggler_background, toggler_foreground] - } - None => vec![toggler_background, toggler_foreground], - }, - }, - if is_mouse_over { - mouse::Interaction::Pointer - } else { - mouse::Interaction::default() - }, - ) - } } -- cgit From 1c2792c0a0dc565f9dd9183ca8948331ec467590 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 28 Oct 2021 18:17:47 +0700 Subject: Implement `Widget::draw` for `Toggler` --- graphics/src/widget/toggler.rs | 9 --------- 1 file changed, 9 deletions(-) (limited to 'graphics/src/widget/toggler.rs') diff --git a/graphics/src/widget/toggler.rs b/graphics/src/widget/toggler.rs index cd072f7c..166f3877 100644 --- a/graphics/src/widget/toggler.rs +++ b/graphics/src/widget/toggler.rs @@ -10,12 +10,3 @@ pub use iced_style::toggler::{Style, StyleSheet}; /// This is an alias of an `iced_native` toggler with an `iced_wgpu::Renderer`. pub type Toggler = iced_native::Toggler>; - -impl toggler::Renderer for Renderer -where - B: Backend + backend::Text, -{ - type Style = Box; - - const DEFAULT_SIZE: u16 = 20; -} -- cgit From 4889a95e592033a4ef3ae05210220a6679711832 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 28 Oct 2021 20:17:49 +0700 Subject: Remove unused imports for `toggler` in `iced_graphics` --- graphics/src/widget/toggler.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'graphics/src/widget/toggler.rs') diff --git a/graphics/src/widget/toggler.rs b/graphics/src/widget/toggler.rs index 166f3877..60d8a347 100644 --- a/graphics/src/widget/toggler.rs +++ b/graphics/src/widget/toggler.rs @@ -1,7 +1,5 @@ //! Show toggle controls using togglers. -use crate::backend::{self, Backend}; use crate::Renderer; -use iced_native::toggler; pub use iced_style::toggler::{Style, StyleSheet}; -- cgit From 0aafcde0ef1533c9eeba0379de8c0082e30c7504 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 15:35:12 +0700 Subject: Remove `widget` module re-exports in `iced_native` --- graphics/src/widget/toggler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/widget/toggler.rs') diff --git a/graphics/src/widget/toggler.rs b/graphics/src/widget/toggler.rs index 60d8a347..0cabd027 100644 --- a/graphics/src/widget/toggler.rs +++ b/graphics/src/widget/toggler.rs @@ -7,4 +7,4 @@ pub use iced_style::toggler::{Style, StyleSheet}; /// /// This is an alias of an `iced_native` toggler with an `iced_wgpu::Renderer`. pub type Toggler = - iced_native::Toggler>; + iced_native::widget::Toggler>; -- cgit From c9ed15782c3a62fcbfe56a141837b384ada82aaa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 17:48:23 +0700 Subject: Introduce state lifetime for `style_sheet` in `Toggler` --- graphics/src/widget/toggler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'graphics/src/widget/toggler.rs') diff --git a/graphics/src/widget/toggler.rs b/graphics/src/widget/toggler.rs index 0cabd027..9053e6ed 100644 --- a/graphics/src/widget/toggler.rs +++ b/graphics/src/widget/toggler.rs @@ -6,5 +6,5 @@ pub use iced_style::toggler::{Style, StyleSheet}; /// A toggler that can be toggled. /// /// This is an alias of an `iced_native` toggler with an `iced_wgpu::Renderer`. -pub type Toggler = - iced_native::widget::Toggler>; +pub type Toggler<'a, Message, Backend> = + iced_native::widget::Toggler<'a, Message, Renderer>; -- cgit