1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::super::{super::Rotation, style, IcedRenderer, Primitive};
use iced::{checkbox, mouse, Rectangle};

impl checkbox::Renderer for IcedRenderer {
    // TODO: what if this gets large enough to not be copied around?
    type Style = style::checkbox::Style;

    const DEFAULT_SIZE: u16 = 20;
    const DEFAULT_SPACING: u16 = 15;

    fn draw(
        &mut self,
        bounds: Rectangle,
        is_checked: bool,
        is_mouse_over: bool,
        (label, _): Self::Output,
        style: &Self::Style,
    ) -> Self::Output {
        let default_rect = || Primitive::Rectangle {
            bounds,
            linear_color: vek::Rgba::broadcast(1.0),
        };

        let background_image = match (is_checked, is_mouse_over) {
            (true, true) => style.bg_hover_checked(),
            (true, false) => style.bg_checked(),
            (false, true) => style.bg_hover(),
            (false, false) => style.bg_default(),
        };

        let background = background_image
            .map(|image| Primitive::Image {
                handle: (image, Rotation::None),
                bounds,
                color: vek::Rgba::broadcast(255),
                source_rect: None,
            })
            .unwrap_or_else(default_rect);

        (
            Primitive::Group {
                primitives: if is_checked {
                    let check = style
                        .check()
                        .map(|image| Primitive::Image {
                            handle: (image, Rotation::None),
                            bounds,
                            color: vek::Rgba::broadcast(255),
                            source_rect: None,
                        })
                        .unwrap_or_else(default_rect);

                    vec![background, check, label]
                } else {
                    vec![background, label]
                },
            },
            if is_mouse_over {
                mouse::Interaction::Pointer
            } else {
                mouse::Interaction::default()
            },
        )
    }
}