summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/checkbox.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-01-09 18:46:06 +0100
committerLibravatar GitHub <noreply@github.com>2020-01-09 18:46:06 +0100
commit0a8302450557877cb667b51fc84383aaf0a11b02 (patch)
treefe3a8a6b0ae82f7fd1fa0c0de34b4b09d0b9edda /wgpu/src/renderer/widget/checkbox.rs
parent6699329d3f91c5b9d8e8e55ad88de24bd3894955 (diff)
parent7b278755fc7929633b5771824beac4d39b16e82e (diff)
downloadiced-0a8302450557877cb667b51fc84383aaf0a11b02.tar.gz
iced-0a8302450557877cb667b51fc84383aaf0a11b02.tar.bz2
iced-0a8302450557877cb667b51fc84383aaf0a11b02.zip
Merge pull request #146 from hecrj/feature/custom-styling
Custom styling
Diffstat (limited to 'wgpu/src/renderer/widget/checkbox.rs')
-rw-r--r--wgpu/src/renderer/widget/checkbox.rs51
1 files changed, 21 insertions, 30 deletions
diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs
index 54b4b1cc..17121eea 100644
--- a/wgpu/src/renderer/widget/checkbox.rs
+++ b/wgpu/src/renderer/widget/checkbox.rs
@@ -1,12 +1,13 @@
-use crate::{Primitive, Renderer};
+use crate::{checkbox::StyleSheet, Primitive, Renderer};
use iced_native::{
- checkbox, Background, HorizontalAlignment, MouseCursor, Rectangle,
- VerticalAlignment,
+ checkbox, HorizontalAlignment, MouseCursor, Rectangle, VerticalAlignment,
};
const SIZE: f32 = 28.0;
impl checkbox::Renderer for Renderer {
+ type Style = Box<dyn StyleSheet>;
+
fn default_size(&self) -> u32 {
SIZE as u32
}
@@ -17,31 +18,21 @@ impl checkbox::Renderer for Renderer {
is_checked: bool,
is_mouse_over: bool,
(label, _): Self::Output,
+ style_sheet: &Self::Style,
) -> Self::Output {
- let (checkbox_border, checkbox_box) = (
- Primitive::Quad {
- bounds,
- background: Background::Color([0.6, 0.6, 0.6].into()),
- border_radius: 6,
- },
- Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x + 1.0,
- y: bounds.y + 1.0,
- width: bounds.width - 2.0,
- height: bounds.height - 2.0,
- },
- background: Background::Color(
- if is_mouse_over {
- [0.90, 0.90, 0.90]
- } else {
- [0.95, 0.95, 0.95]
- }
- .into(),
- ),
- border_radius: 5,
- },
- );
+ let style = if is_mouse_over {
+ style_sheet.hovered(is_checked)
+ } else {
+ style_sheet.active(is_checked)
+ };
+
+ let checkbox = Primitive::Quad {
+ bounds,
+ background: style.background,
+ border_radius: style.border_radius,
+ border_width: style.border_width,
+ border_color: style.border_color,
+ };
(
Primitive::Group {
@@ -51,14 +42,14 @@ impl checkbox::Renderer for Renderer {
font: crate::text::BUILTIN_ICONS,
size: bounds.height * 0.7,
bounds: bounds,
- color: [0.3, 0.3, 0.3].into(),
+ color: style.checkmark_color,
horizontal_alignment: HorizontalAlignment::Center,
vertical_alignment: VerticalAlignment::Center,
};
- vec![checkbox_border, checkbox_box, check, label]
+ vec![checkbox, check, label]
} else {
- vec![checkbox_border, checkbox_box, label]
+ vec![checkbox, label]
},
},
if is_mouse_over {