the-honkers-railway-launcher/src/ui/mod.rs
Observer KRypt0n_ 178c45ae48
Preparations for loading page
- added `Adw.StatusPage` to the preferences
- made preparations for progress bar and launcher states system
- fixed toasts resizing window issue
2022-07-02 12:18:44 +02:00

51 lines
1.5 KiB
Rust

use gtk4::{self as gtk, prelude::*};
use libadwaita::{self as adw, prelude::*};
mod main;
mod preferences;
mod toast_error;
pub use main::{
App as MainApp,
AppState as MainAppState,
};
pub use toast_error::ToastError;
/// This function loads object from builder or panics if it doesn't exist
pub fn get_object<T: IsA<gtk::glib::Object>>(builder: &gtk::Builder, name: &str) -> Result<T, String> {
match builder.object::<T>(name) {
Some(object) => Ok(object),
None => Err(format!("Failed to parse object '{}'", name))
}
}
/// Add action to widget
///
/// All the actions needs to be in some group. This function creates new group with the name of the action.
/// This means that to add action to some widget you need to speify `name.name` as its name
///
/// ## Example:
///
/// ```
/// let toast = libadwaita::Toast::new("Example toast");
///
/// toast.set_button_label(Some("Example button"));
/// toast.set_action_name(Some("example-button.example-button"));
///
/// add_action(&toast, "example-button", || {
/// println!("Hello, World!");
/// });
/// ```
pub fn add_action<T: IsA<gtk::Widget>, F: Fn() + 'static>(obj: &T, name: &str, closure: F) {
let action_group = adw::gio::SimpleActionGroup::new();
let action = adw::gio::SimpleAction::new(name, None);
obj.insert_action_group(name, Some(&action_group));
action.connect_activate(move |_, _| {
closure();
});
action_group.add_action(&action);
}