summaryrefslogtreecommitdiffstats
path: root/examples/svg_style/src/main.rs
blob: 0a1fa039c5bdf969d0404d218e4fef65fbff4c1d (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use iced::widget::{container, svg};
use iced::{Color, Element, Length, Sandbox, Settings};
use iced_style::svg::Appearance;
use iced_style::theme::{self, Theme};

pub fn main() -> iced::Result {
    SvgStyleExample::run(Settings::default())
}

struct SvgStyleExample;

impl Sandbox for SvgStyleExample {
    type Message = ();

    fn new() -> Self {
        SvgStyleExample
    }

    fn theme(&self) -> Theme {
        Theme::Light
    }

    fn title(&self) -> String {
        String::from("SVG - Iced")
    }

    fn update(&mut self, _message: ()) {}

    fn view(&self) -> Element<()> {
        let svg1: Element<_> = svg(svg::Handle::from_path(format!(
            "{}/resources/go-next-symbolic.svg",
            env!("CARGO_MANIFEST_DIR")
        )))
        .width(Length::Fill)
        .height(Length::Fill)
        .into();

        let svg2: Element<_> = svg(svg::Handle::from_path(format!(
            "{}/resources/go-next-symbolic.svg",
            env!("CARGO_MANIFEST_DIR")
        )))
        .style(theme::Svg::custom_fn(|_theme| Appearance {
            color: Some(Color {
                r: 0.0,
                g: 0.28627452,
                b: 0.42745098,
                a: 1.0,
            }),
        }))
        .width(Length::Fill)
        .height(Length::Fill)
        .into();

        let svg3: Element<_> = svg(svg::Handle::from_path(format!(
            "{}/resources/go-next-symbolic.svg",
            env!("CARGO_MANIFEST_DIR")
        )))
        .style(theme::Svg::custom_fn(|_theme| Appearance {
            color: Some(Color {
                r: 0.5803922,
                g: 0.92156863,
                b: 0.92156863,
                a: 1.0,
            }),
        }))
        .width(Length::Fill)
        .height(Length::Fill)
        .into();

        container(iced::widget::row!(svg1, svg2, svg3))
            .width(Length::Fill)
            .height(Length::Fill)
            .padding(20)
            .center_x()
            .center_y()
            .into()
    }
}