mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
* Propose an explicit .rustfnt.toml Use 2024 style, 4 spaces for tabs and epand the default width a tad * Auto-format the existing code with new rules
69 lines
1.8 KiB
Rust
69 lines
1.8 KiB
Rust
use std::cell::RefCell;
|
|
|
|
use adw::subclass::prelude::*;
|
|
use adw::{ActionRow, prelude::*};
|
|
use glib::{Binding, subclass::InitializingObject};
|
|
use gtk::glib::clone;
|
|
use gtk::glib::subclass::Signal;
|
|
use gtk::{Button, CompositeTemplate, glib};
|
|
use std::sync::OnceLock;
|
|
|
|
#[derive(CompositeTemplate, Default)]
|
|
#[template(resource = "/de/feschber/LanMouse/key_row.ui")]
|
|
pub struct KeyRow {
|
|
#[template_child]
|
|
pub delete_button: TemplateChild<gtk::Button>,
|
|
pub bindings: RefCell<Vec<Binding>>,
|
|
}
|
|
|
|
#[glib::object_subclass]
|
|
impl ObjectSubclass for KeyRow {
|
|
// `NAME` needs to match `class` attribute of template
|
|
const NAME: &'static str = "KeyRow";
|
|
const ABSTRACT: bool = false;
|
|
|
|
type Type = super::KeyRow;
|
|
type ParentType = ActionRow;
|
|
|
|
fn class_init(klass: &mut Self::Class) {
|
|
klass.bind_template();
|
|
klass.bind_template_callbacks();
|
|
}
|
|
|
|
fn instance_init(obj: &InitializingObject<Self>) {
|
|
obj.init_template();
|
|
}
|
|
}
|
|
|
|
impl ObjectImpl for KeyRow {
|
|
fn constructed(&self) {
|
|
self.parent_constructed();
|
|
self.delete_button.connect_clicked(clone!(
|
|
#[weak(rename_to = row)]
|
|
self,
|
|
move |button| {
|
|
row.handle_delete(button);
|
|
}
|
|
));
|
|
}
|
|
|
|
fn signals() -> &'static [glib::subclass::Signal] {
|
|
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
|
|
SIGNALS.get_or_init(|| vec![Signal::builder("request-delete").build()])
|
|
}
|
|
}
|
|
|
|
#[gtk::template_callbacks]
|
|
impl KeyRow {
|
|
#[template_callback]
|
|
fn handle_delete(&self, _button: &Button) {
|
|
self.obj().emit_by_name::<()>("request-delete", &[]);
|
|
}
|
|
}
|
|
|
|
impl WidgetImpl for KeyRow {}
|
|
impl BoxImpl for KeyRow {}
|
|
impl ListBoxRowImpl for KeyRow {}
|
|
impl PreferencesRowImpl for KeyRow {}
|
|
impl ActionRowImpl for KeyRow {}
|