embedded_logo/
embedded_logo.rs

1use gtk::prelude::*;
2use relm4::prelude::*;
3
4use gtk::glib;
5use relm4::gtk::gdk::Texture;
6
7struct App {}
8
9/// embedded logo as paintable texture
10///
11/// The bytes from PNG are included during build time and shipped
12/// within the executable.
13fn embedded_logo() -> Texture {
14    let bytes = include_bytes!(".././assets/Relm_logo.png");
15    let g_bytes = glib::Bytes::from(&bytes.to_vec());
16    Texture::from_bytes(&g_bytes).expect(
17        "Failed to create Texture of embedded logo from bytes of .././assets/Relm_logo.png file",
18    )
19}
20
21#[derive(Debug)]
22enum Msg {}
23
24#[relm4::component]
25impl SimpleComponent for App {
26    type Init = u8;
27    type Input = Msg;
28    type Output = ();
29
30    view! {
31        gtk::Window {
32            set_title: Some("Embedded Logo app "),
33            set_default_size: (200, 200),
34
35            gtk::Box {
36                set_orientation: gtk::Orientation::Vertical,
37                set_spacing: 5,
38                set_margin_all: 5,
39
40                gtk::Image {
41                    set_vexpand: true,
42                    set_hexpand: true,
43                    set_paintable: Some(&embedded_logo()),
44                },
45            }
46        }
47    }
48
49    // Initialize the component.
50    fn init(
51        _: Self::Init,
52        _root: Self::Root,
53        _sender: ComponentSender<Self>,
54    ) -> ComponentParts<Self> {
55        let model = App {};
56
57        // Insert the code generation of the view! macro here
58        let widgets = view_output!();
59
60        ComponentParts { model, widgets }
61    }
62
63    fn update(&mut self, _msg: Self::Input, _sender: ComponentSender<Self>) {}
64}
65
66fn main() {
67    let app = RelmApp::new("relm4.example.embedded_logo");
68    app.run::<App>(0);
69}