mycitadel/view/about/
component.rs

1// MyCitadel desktop wallet: bitcoin & RGB wallet based on GTK framework.
2//
3// Written in 2022 by
4//     Dr. Maxim Orlovsky <orlovsky@pandoraprime.ch>
5//
6// Copyright (C) 2022 by Pandora Prime SA, Switzerland.
7//
8// This software is distributed without any warranty. You should have received
9// a copy of the AGPL-3.0 License along with this software. If not, see
10// <https://www.gnu.org/licenses/agpl-3.0-standalone.html>.
11
12use gladis::Gladis;
13use gtk::Dialog;
14use relm::{Relm, Update, Widget};
15
16use super::{Msg, ViewModel, Widgets};
17
18pub struct Component {
19    model: ViewModel,
20    widgets: Widgets,
21}
22
23impl Component {}
24
25impl Update for Component {
26    // Specify the model used for this widget.
27    type Model = ViewModel;
28    // Specify the model parameter used to init the model.
29    type ModelParam = ();
30    // Specify the type of the messages sent to the update function.
31    type Msg = Msg;
32
33    fn model(_relm: &Relm<Self>, _param: Self::ModelParam) -> Self::Model { ViewModel::default() }
34
35    fn update(&mut self, event: Msg) {
36        match event {
37            Msg::Show => {
38                self.widgets.init_ui(&self.model);
39                self.widgets.show();
40            }
41            Msg::Response(_) => {
42                self.widgets.hide();
43            }
44        }
45    }
46}
47
48impl Widget for Component {
49    // Specify the type of the root widget.
50    type Root = Dialog;
51
52    // Return the root widget.
53    fn root(&self) -> Self::Root { self.widgets.to_root() }
54
55    fn view(relm: &Relm<Self>, model: Self::Model) -> Self {
56        let glade_src = include_str!("about.glade");
57        let widgets = Widgets::from_string(glade_src).expect("glade file broken");
58
59        widgets.connect(relm);
60        widgets.init_ui(&model);
61        widgets.show();
62
63        Component { model, widgets }
64    }
65}