summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/button.rs
blob: b9dfb9ac921e15950c11353e7bee557b8627cc6d (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
use crate::{Background, Primitive, Renderer};
use iced_native::{button, Button, Color, Layout, Length, Node, Point, Style};

impl button::Renderer for Renderer {
    fn node<Message>(&self, button: &Button<Message>) -> Node {
        let style = Style::default()
            .width(button.width)
            .min_height(Length::Units(30))
            .min_width(Length::Units(100))
            .align_self(button.align_self);

        Node::new(style)
    }

    fn draw<Message>(
        &mut self,
        button: &Button<Message>,
        layout: Layout<'_>,
        _cursor_position: Point,
    ) -> Self::Primitive {
        Primitive::Group {
            primitives: vec![
                Primitive::Box {
                    bounds: layout.bounds(),
                    background: Background::Color(Color {
                        r: 0.0,
                        b: 1.0,
                        g: 0.0,
                        a: 1.0,
                    }),
                },
                Primitive::Text {
                    content: button.label.clone(),
                    size: 20.0,
                    bounds: layout.bounds(),
                },
            ],
        }
    }
}