iced-yoda/wgpu/src/renderer/widget/checkbox.rs

64 lines
1.9 KiB
Rust
Raw Normal View History

2020-01-07 02:54:54 +01:00
use crate::{checkbox::StyleSheet, Primitive, Renderer};
2019-10-11 23:30:53 +02:00
use iced_native::{
checkbox, mouse, HorizontalAlignment, Rectangle, VerticalAlignment,
2019-10-11 23:30:53 +02:00
};
2019-10-05 19:22:51 +02:00
impl checkbox::Renderer for Renderer {
2020-01-07 02:54:54 +01:00
type Style = Box<dyn StyleSheet>;
const DEFAULT_SIZE: u16 = 20;
const DEFAULT_SPACING: u16 = 15;
2019-10-05 19:22:51 +02:00
fn draw(
2019-10-05 19:22:51 +02:00
&mut self,
bounds: Rectangle,
is_checked: bool,
is_mouse_over: bool,
(label, _): Self::Output,
2020-01-07 02:54:54 +01:00
style_sheet: &Self::Style,
) -> Self::Output {
2020-01-07 02:54:54 +01:00
let style = if is_mouse_over {
style_sheet.hovered(is_checked)
2020-01-07 02:54:54 +01:00
} else {
style_sheet.active(is_checked)
2020-01-07 02:54:54 +01:00
};
let checkbox = Primitive::Quad {
bounds,
2020-01-07 02:54:54 +01:00
background: style.background,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
};
2019-10-13 18:10:12 +02:00
(
Primitive::Group {
primitives: if is_checked {
let check = Primitive::Text {
content: crate::text::CHECKMARK_ICON.to_string(),
font: crate::text::BUILTIN_ICONS,
size: bounds.height * 0.7,
bounds: Rectangle {
x: bounds.center_x(),
y: bounds.center_y(),
..bounds
},
2020-01-07 02:54:54 +01:00
color: style.checkmark_color,
horizontal_alignment: HorizontalAlignment::Center,
vertical_alignment: VerticalAlignment::Center,
};
2019-10-13 18:10:12 +02:00
vec![checkbox, check, label]
2019-10-13 18:10:12 +02:00
} else {
vec![checkbox, label]
2019-10-13 18:10:12 +02:00
},
},
if is_mouse_over {
mouse::Interaction::Pointer
2019-10-13 18:10:12 +02:00
} else {
mouse::Interaction::default()
2019-10-13 18:10:12 +02:00
},
)
2019-10-05 19:22:51 +02:00
}
}