Skip to content

Commit

Permalink
feat: add about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Musco committed Dec 2, 2023
1 parent bbf7868 commit ddcedda
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion lact-gui/src/app/headerbar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use super::{apply_box::ApplyBox, gpu_selector::GpuSelector};
use gtk::{
gio::ActionEntry,
glib::{self, clone, IsA},
prelude::{ActionMapExtManual, GtkWindowExt},
};

#[derive(Debug, Clone)]
pub struct Headerbar {
Expand All @@ -13,7 +18,7 @@ pub struct Headerbar {
}

impl Headerbar {
pub fn new() -> Self {
pub fn new(app: &impl IsA<gtk::Application>, root_win: &gtk::ApplicationWindow) -> Self {
#[cfg(feature = "adw")]
let container = adw::HeaderBar::builder().show_title(false).build();

Expand All @@ -25,7 +30,56 @@ impl Headerbar {
let gpu_selector = GpuSelector::new();
let apply_box = ApplyBox::new();

#[cfg(not(feature = "adw"))]
let about_dialog = gtk::AboutDialog::builder()
.hide_on_close(true)
.modal(true)
.transient_for(root_win)
.program_name("LACT")
.icon_name("io.github.lact-linux")
.version(std::env!("CARGO_PKG_VERSION"))
.license_type(gtk::License::MitX11)
.copyright("The LACT Developers")
.authors(
std::env!("CARGO_PKG_AUTHORS")
.split(':')
.collect::<Vec<&str>>(),
)
.build();

#[cfg(feature = "adw")]
let about_dialog = adw::AboutWindow::builder()
.hide_on_close(true)
.modal(true)
.transient_for(root_win)
.application_name("LACT")
.application_icon("io.github.lact-linux")
.version(std::env!("CARGO_PKG_VERSION"))
.license_type(gtk::License::MitX11)
.copyright("The LACT Developers")
.developers(
std::env!("CARGO_PKG_AUTHORS")
.split(':')
.collect::<Vec<&str>>(),
)
.build();

let menu = gtk::gio::Menu::new();
menu.append_item(&gtk::gio::MenuItem::new(Some("About"), Some("win.about")));

root_win.add_action_entries([ActionEntry::builder("about")
.activate(clone!(@weak about_dialog => move |_, _, _| {
about_dialog.present();
}))
.build()]);

container.pack_start(&gpu_selector.dropdown);
container.pack_end(
&gtk::MenuButton::builder()
.icon_name("open-menu-symbolic")
.menu_model(&menu)
.build(),
);
container.pack_end(&apply_box.container);

Self {
Expand Down
2 changes: 1 addition & 1 deletion lact-gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl App {

let root_stack = RootStack::new(&window, system_info, daemon_client.embedded);

let headerbar = Headerbar::new();
let headerbar = Headerbar::new(&application, &window.clone().upcast::<ApplicationWindow>());

#[cfg(feature = "adw")]
{
Expand Down

0 comments on commit ddcedda

Please sign in to comment.