diff options
author | 2019-12-29 10:57:01 +0100 | |
---|---|---|
committer | 2019-12-29 10:57:01 +0100 | |
commit | c7b170da6d180f80e539910cccb543720fa3713c (patch) | |
tree | 6ef48d17104173f0ac7182d3647bd461e5581bd2 /wgpu/src/renderer/widget/button.rs | |
parent | 4b86c2ff987e334c3454540828c6f8d16d27c670 (diff) | |
download | iced-c7b170da6d180f80e539910cccb543720fa3713c.tar.gz iced-c7b170da6d180f80e539910cccb543720fa3713c.tar.bz2 iced-c7b170da6d180f80e539910cccb543720fa3713c.zip |
Draft `Style` and `StyleSheet` for `Button`
Diffstat (limited to 'wgpu/src/renderer/widget/button.rs')
-rw-r--r-- | wgpu/src/renderer/widget/button.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs index 86963053..f3817374 100644 --- a/wgpu/src/renderer/widget/button.rs +++ b/wgpu/src/renderer/widget/button.rs @@ -1,50 +1,50 @@ -use crate::{Primitive, Renderer}; -use iced_native::{button, Background, MouseCursor, Point, Rectangle}; +use crate::{button::StyleSheet, Primitive, Renderer}; +use iced_native::{Background, MouseCursor, Point, Rectangle}; + +impl iced_native::button::Renderer for Renderer { + type Style = Box<dyn StyleSheet>; -impl button::Renderer for Renderer { fn draw( &mut self, bounds: Rectangle, cursor_position: Point, is_pressed: bool, - background: Option<Background>, - border_radius: u16, + style: &Box<dyn StyleSheet>, (content, _): Self::Output, ) -> Self::Output { let is_mouse_over = bounds.contains(cursor_position); // TODO: Render proper shadows - // TODO: Make hovering and pressed styles configurable - let shadow_offset = if is_mouse_over { + let styling = if is_mouse_over { if is_pressed { - 0.0 + style.pressed() } else { - 2.0 + style.hovered() } } else { - 1.0 + style.active() }; ( - match background { + match styling.background { None => content, Some(background) => Primitive::Group { primitives: vec![ Primitive::Quad { bounds: Rectangle { x: bounds.x + 1.0, - y: bounds.y + shadow_offset, + y: bounds.y + styling.shadow_offset, ..bounds }, background: Background::Color( [0.0, 0.0, 0.0, 0.5].into(), ), - border_radius, + border_radius: styling.border_radius, }, Primitive::Quad { bounds, background, - border_radius, + border_radius: styling.border_radius, }, content, ], |