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::{
|
2020-04-30 08:16:38 +02:00
|
|
|
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>;
|
|
|
|
|
|
2020-02-18 02:28:15 +01:00
|
|
|
const DEFAULT_SIZE: u16 = 20;
|
|
|
|
|
const DEFAULT_SPACING: u16 = 15;
|
2019-10-05 19:22:51 +02:00
|
|
|
|
2019-11-21 13:47:20 +01:00
|
|
|
fn draw(
|
2019-10-05 19:22:51 +02:00
|
|
|
&mut self,
|
2019-11-21 13:47:20 +01:00
|
|
|
bounds: Rectangle,
|
|
|
|
|
is_checked: bool,
|
|
|
|
|
is_mouse_over: bool,
|
|
|
|
|
(label, _): Self::Output,
|
2020-01-07 02:54:54 +01:00
|
|
|
style_sheet: &Self::Style,
|
2019-10-11 22:15:39 +02:00
|
|
|
) -> Self::Output {
|
2020-01-07 02:54:54 +01:00
|
|
|
let style = if is_mouse_over {
|
2020-01-08 03:30:15 +01:00
|
|
|
style_sheet.hovered(is_checked)
|
2020-01-07 02:54:54 +01:00
|
|
|
} else {
|
2020-01-08 03:30:15 +01:00
|
|
|
style_sheet.active(is_checked)
|
2020-01-07 02:54:54 +01:00
|
|
|
};
|
|
|
|
|
|
2019-12-31 21:35:42 +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-12-31 21:35:42 +01:00
|
|
|
};
|
2019-10-13 18:10:12 +02:00
|
|
|
|
|
|
|
|
(
|
|
|
|
|
Primitive::Group {
|
2019-11-21 13:47:20 +01:00
|
|
|
primitives: if is_checked {
|
2019-11-14 03:34:41 +01:00
|
|
|
let check = Primitive::Text {
|
|
|
|
|
content: crate::text::CHECKMARK_ICON.to_string(),
|
|
|
|
|
font: crate::text::BUILTIN_ICONS,
|
2019-11-21 13:47:20 +01:00
|
|
|
size: bounds.height * 0.7,
|
2020-04-10 01:34:22 +02:00
|
|
|
bounds: Rectangle {
|
|
|
|
|
x: bounds.center_x(),
|
|
|
|
|
y: bounds.center_y(),
|
|
|
|
|
..bounds
|
|
|
|
|
},
|
2020-01-07 02:54:54 +01:00
|
|
|
color: style.checkmark_color,
|
2019-11-14 03:34:41 +01:00
|
|
|
horizontal_alignment: HorizontalAlignment::Center,
|
|
|
|
|
vertical_alignment: VerticalAlignment::Center,
|
|
|
|
|
};
|
2019-10-13 18:10:12 +02:00
|
|
|
|
2019-12-31 21:35:42 +01:00
|
|
|
vec![checkbox, check, label]
|
2019-10-13 18:10:12 +02:00
|
|
|
} else {
|
2019-12-31 21:35:42 +01:00
|
|
|
vec![checkbox, label]
|
2019-10-13 18:10:12 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
if is_mouse_over {
|
2020-04-30 08:16:38 +02:00
|
|
|
mouse::Interaction::Pointer
|
2019-10-13 18:10:12 +02:00
|
|
|
} else {
|
2020-04-30 08:16:38 +02:00
|
|
|
mouse::Interaction::default()
|
2019-10-13 18:10:12 +02:00
|
|
|
},
|
|
|
|
|
)
|
2019-10-05 19:22:51 +02:00
|
|
|
}
|
|
|
|
|
}
|