summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/container.rs
blob: 29c709f88928e5789fbf670230661acef6995709 (plain) (blame)
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
use crate::{container, defaults, Defaults, Primitive, Renderer};
use iced_native::{Element, Layout, Point, Rectangle};

impl iced_native::container::Renderer for Renderer {
    type Style = Box<dyn container::StyleSheet>;

    fn draw<Message>(
        &mut self,
        defaults: &Defaults,
        bounds: Rectangle,
        cursor_position: Point,
        style_sheet: &Self::Style,
        content: &Element<'_, Message, Self>,
        content_layout: Layout<'_>,
    ) -> Self::Output {
        let style = style_sheet.style();

        let defaults = Defaults {
            text: defaults::Text {
                color: style.text_color.unwrap_or(defaults.text.color),
            },
            ..*defaults
        };

        let (content, mouse_cursor) =
            content.draw(self, &defaults, content_layout, cursor_position);

        match style.background {
            Some(background) => {
                let quad = Primitive::Quad {
                    bounds,
                    background,
                    border_radius: style.border_radius,
                };

                (
                    Primitive::Group {
                        primitives: vec![quad, content],
                    },
                    mouse_cursor,
                )
            }
            None => (content, mouse_cursor),
        }
    }
}