59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use adw::prelude::*;
|
|
use adw::subclass::prelude::AdwApplicationWindowImpl;
|
|
use adw::subclass::prelude::*;
|
|
use adw::EntryRow;
|
|
use gio::Settings;
|
|
use glib::subclass::InitializingObject;
|
|
use gtk::{gio, glib, CompositeTemplate};
|
|
use once_cell::sync::OnceCell;
|
|
|
|
// Object holding the state
|
|
#[derive(CompositeTemplate, Default)]
|
|
#[template(resource = "/space/midnightthoughts/matrix_client/window.ui")]
|
|
pub struct Window {
|
|
#[template_child]
|
|
pub entry: TemplateChild<EntryRow>,
|
|
pub settings: OnceCell<Settings>,
|
|
}
|
|
|
|
// The central trait for subclassing a GObject
|
|
#[glib::object_subclass]
|
|
impl ObjectSubclass for Window {
|
|
// `NAME` needs to match `class` attribute of template
|
|
const NAME: &'static str = "MainWindow";
|
|
type Type = super::Window;
|
|
type ParentType = adw::ApplicationWindow;
|
|
|
|
fn class_init(klass: &mut Self::Class) {
|
|
klass.bind_template();
|
|
}
|
|
|
|
fn instance_init(obj: &InitializingObject<Self>) {
|
|
obj.init_template();
|
|
}
|
|
}
|
|
|
|
// Trait shared by all GObjects
|
|
impl ObjectImpl for Window {
|
|
fn constructed(&self) {
|
|
let obj = self.instance();
|
|
// Call "constructed" on parent
|
|
self.parent_constructed();
|
|
|
|
// Setup
|
|
obj.setup_settings();
|
|
}
|
|
}
|
|
|
|
// Trait shared by all widgets
|
|
impl WidgetImpl for Window {}
|
|
|
|
// Trait shared by all windows
|
|
impl WindowImpl for Window {}
|
|
|
|
// Trait shared by all application windows
|
|
impl ApplicationWindowImpl for Window {}
|
|
|
|
// Trait shared by all adwaita application windows
|
|
impl AdwApplicationWindowImpl for Window {}
|