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
use super::super::{
    super::{widget::compound_graphic, Rotation},
    IcedRenderer, Primitive,
};
use common::util::srgba_to_linear;
use compound_graphic::GraphicKind;
use iced::{mouse, Rectangle};

impl compound_graphic::Renderer for IcedRenderer {
    fn draw<I>(&mut self, graphics: I) -> Self::Output
    where
        I: Iterator<Item = (Rectangle, GraphicKind)>,
    {
        (
            Primitive::Group {
                primitives: graphics
                    .map(|(bounds, kind)| match kind {
                        GraphicKind::Image(handle, color) => Primitive::Image {
                            handle: (handle, Rotation::None),
                            bounds,
                            color,
                            source_rect: None,
                        },
                        GraphicKind::Color(color) => Primitive::Rectangle {
                            bounds,
                            linear_color: srgba_to_linear(color.map(|e| e as f32 / 255.0)),
                        },
                        GraphicKind::Gradient(top_color, bottom_color) => Primitive::Gradient {
                            bounds,
                            top_linear_color: srgba_to_linear(top_color.map(|e| e as f32 / 255.0)),
                            bottom_linear_color: srgba_to_linear(
                                bottom_color.map(|e| e as f32 / 255.0),
                            ),
                        },
                    })
                    .collect(),
            },
            mouse::Interaction::default(),
        )
    }
}