34 lines
1.0 KiB
Rust
Raw Normal View History

2024-12-13 00:36:45 +02:00
use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::ActionExt};
2024-12-13 00:03:33 +02:00
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Focus` action of `Browser` group
pub struct Focus {
2024-12-14 06:50:30 +02:00
pub simple_action: SimpleAction,
2024-12-13 00:03:33 +02:00
}
impl Focus {
// Constructors
/// Create new `Self`
pub fn new() -> Self {
Self {
2024-12-14 06:50:30 +02:00
simple_action: SimpleAction::new(&uuid_string_random(), None),
2024-12-13 00:03:33 +02:00
}
}
2024-12-13 00:36:45 +02:00
// Actions
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
/// with formatted for this action [Variant](https://docs.gtk.org/glib/struct.Variant.html) value
pub fn activate(&self) {
2024-12-14 06:50:30 +02:00
self.simple_action.activate(None); // @TODO custom value
2024-12-13 00:36:45 +02:00
}
2024-12-13 00:03:33 +02:00
// Events
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn() + 'static) {
2024-12-14 06:50:30 +02:00
self.simple_action.connect_activate(move |_, _| callback());
2024-12-13 00:03:33 +02:00
}
}