fractal/identity_verification_view/
sas_emoji.rs

1use adw::subclass::prelude::*;
2use gtk::{glib, CompositeTemplate};
3
4mod imp {
5    use glib::subclass::InitializingObject;
6
7    use super::*;
8
9    #[derive(Debug, Default, CompositeTemplate)]
10    #[template(resource = "/org/gnome/Fractal/ui/identity_verification_view/sas_emoji.ui")]
11    pub struct SasEmoji {
12        #[template_child]
13        pub emoji: TemplateChild<gtk::Label>,
14        #[template_child]
15        pub emoji_name: TemplateChild<gtk::Label>,
16    }
17
18    #[glib::object_subclass]
19    impl ObjectSubclass for SasEmoji {
20        const NAME: &'static str = "IdentityVerificationSasEmoji";
21        type Type = super::SasEmoji;
22        type ParentType = adw::Bin;
23
24        fn class_init(klass: &mut Self::Class) {
25            Self::bind_template(klass);
26        }
27
28        fn instance_init(obj: &InitializingObject<Self>) {
29            obj.init_template();
30        }
31    }
32
33    impl ObjectImpl for SasEmoji {}
34    impl WidgetImpl for SasEmoji {}
35    impl BinImpl for SasEmoji {}
36}
37
38glib::wrapper! {
39    /// An emoji for SAS verification.
40    pub struct SasEmoji(ObjectSubclass<imp::SasEmoji>)
41        @extends gtk::Widget, adw::Bin, @implements gtk::Accessible;
42}
43
44impl SasEmoji {
45    pub fn new(symbol: &str, name: &str) -> Self {
46        let obj: Self = glib::Object::new();
47
48        obj.set_emoji(symbol, name);
49        obj
50    }
51
52    /// Set the emoji.
53    pub fn set_emoji(&self, symbol: &str, name: &str) {
54        let imp = self.imp();
55
56        imp.emoji.set_text(symbol);
57        imp.emoji_name.set_text(name);
58    }
59}