mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-07-13 12:31:33 +00:00
feat: use regular windows for profile and fbt config editors; use headerbar for save and add buttons
This commit is contained in:
parent
e4114225f5
commit
40f2538d16
2 changed files with 278 additions and 243 deletions
|
@ -14,7 +14,7 @@ pub struct FbtConfigEditor {
|
|||
monado_config_v0: MonadoConfigV0,
|
||||
|
||||
#[tracker::do_not_track]
|
||||
win: Option<adw::PreferencesWindow>,
|
||||
win: Option<adw::Window>,
|
||||
|
||||
#[tracker::do_not_track]
|
||||
tracker_role_groups: FactoryVecDeque<TrackerRoleModel>,
|
||||
|
@ -41,12 +41,30 @@ impl SimpleComponent for FbtConfigEditor {
|
|||
|
||||
view! {
|
||||
#[name(win)]
|
||||
adw::PreferencesWindow {
|
||||
adw::Window {
|
||||
set_title: Some("Full Body Trackers"),
|
||||
set_modal: true,
|
||||
set_transient_for: Some(&init.root_win),
|
||||
set_search_enabled: false,
|
||||
add: model.tracker_role_groups.widget(),
|
||||
set_default_height: 500,
|
||||
set_default_width: 600,
|
||||
gtk::Box {
|
||||
set_vexpand: true,
|
||||
set_hexpand: true,
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
gtk::WindowHandle {
|
||||
set_vexpand: false,
|
||||
set_hexpand: true,
|
||||
#[name(headerbar)]
|
||||
adw::HeaderBar {
|
||||
set_vexpand: false,
|
||||
set_hexpand: true,
|
||||
add_css_class: "flat",
|
||||
pack_start: &add_btn,
|
||||
pack_end: &save_btn,
|
||||
},
|
||||
},
|
||||
append: model.tracker_role_groups.widget(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,18 +112,13 @@ impl SimpleComponent for FbtConfigEditor {
|
|||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let page = adw::PreferencesPage::builder().build();
|
||||
let grp = adw::PreferencesGroup::builder().build();
|
||||
let add_btn = gtk::Button::builder()
|
||||
.label("Add Tracker")
|
||||
.margin_bottom(12)
|
||||
.css_classes(["pill"])
|
||||
.halign(gtk::Align::Center)
|
||||
.tooltip_text("Add Tracker")
|
||||
.icon_name("list-add-symbolic")
|
||||
.build();
|
||||
let save_btn = gtk::Button::builder()
|
||||
.label("Save")
|
||||
.margin_bottom(12)
|
||||
.halign(gtk::Align::Center)
|
||||
.css_classes(["suggested-action", "pill"])
|
||||
.css_classes(["suggested-action"])
|
||||
.build();
|
||||
{
|
||||
withclones![sender];
|
||||
|
@ -119,9 +132,6 @@ impl SimpleComponent for FbtConfigEditor {
|
|||
sender.input(Self::Input::Save);
|
||||
});
|
||||
};
|
||||
grp.add(&save_btn);
|
||||
grp.add(&add_btn);
|
||||
page.add(&grp);
|
||||
|
||||
let mut model = Self {
|
||||
win: None,
|
||||
|
@ -135,6 +145,21 @@ impl SimpleComponent for FbtConfigEditor {
|
|||
let widgets = view_output!();
|
||||
model.win = Some(widgets.win.clone());
|
||||
|
||||
widgets.headerbar.pack_start(&add_btn);
|
||||
widgets.headerbar.pack_end(&save_btn);
|
||||
{
|
||||
let win = widgets.win.clone();
|
||||
let sc = gtk::ShortcutController::new();
|
||||
sc.add_shortcut(gtk::Shortcut::new(
|
||||
gtk::ShortcutTrigger::parse_string("Escape"),
|
||||
Some(gtk::CallbackAction::new(move |_, _| {
|
||||
win.close();
|
||||
true
|
||||
})),
|
||||
));
|
||||
widgets.win.add_controller(sc);
|
||||
}
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use super::factories::env_var_row_factory::{EnvVarModel, EnvVarModelInit};
|
||||
use super::{
|
||||
alert::alert,
|
||||
factories::env_var_row_factory::{EnvVarModel, EnvVarModelInit},
|
||||
};
|
||||
use crate::{
|
||||
env_var_descriptions::env_var_descriptions_as_paragraph,
|
||||
profile::{LighthouseDriver, Profile, XRServiceType},
|
||||
|
@ -12,10 +15,8 @@ use std::{cell::RefCell, rc::Rc};
|
|||
#[tracker::track]
|
||||
pub struct ProfileEditor {
|
||||
profile: Rc<RefCell<Profile>>,
|
||||
|
||||
#[tracker::do_not_track]
|
||||
win: Option<adw::PreferencesWindow>,
|
||||
|
||||
win: Option<adw::Window>,
|
||||
#[tracker::do_not_track]
|
||||
env_rows: FactoryVecDeque<EnvVarModel>,
|
||||
}
|
||||
|
@ -47,12 +48,35 @@ impl SimpleComponent for ProfileEditor {
|
|||
|
||||
view! {
|
||||
#[name(win)]
|
||||
adw::PreferencesWindow {
|
||||
adw::Window {
|
||||
set_modal: true,
|
||||
set_transient_for: Some(&init.root_win),
|
||||
#[track = "model.changed(Self::profile())"]
|
||||
set_title: Some(model.profile.borrow().name.as_str()),
|
||||
add: mainpage = &adw::PreferencesPage {
|
||||
set_default_height: 500,
|
||||
set_default_width: 600,
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_hexpand: true,
|
||||
set_vexpand: true,
|
||||
gtk::WindowHandle {
|
||||
set_hexpand: true,
|
||||
set_vexpand: false,
|
||||
adw::HeaderBar {
|
||||
set_vexpand: false,
|
||||
add_css_class: "flat",
|
||||
pack_end: save_btn = >k::Button {
|
||||
set_label: "Save",
|
||||
add_css_class: "suggested-action",
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(Self::Input::SaveProfile);
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
adw::PreferencesPage {
|
||||
set_hexpand: true,
|
||||
set_vexpand: true,
|
||||
add: maingrp = &adw::PreferencesGroup {
|
||||
set_title: "General",
|
||||
add: {
|
||||
|
@ -263,21 +287,7 @@ impl SimpleComponent for ProfileEditor {
|
|||
},
|
||||
},
|
||||
add: model.env_rows.widget(),
|
||||
add: save_grp = &adw::PreferencesGroup {
|
||||
add: save_box = >k::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_hexpand: true,
|
||||
gtk::Button {
|
||||
set_halign: gtk::Align::Center,
|
||||
set_label: "Save",
|
||||
add_css_class: "pill",
|
||||
add_css_class: "suggested-action",
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(Self::Input::SaveProfile);
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,10 +307,10 @@ impl SimpleComponent for ProfileEditor {
|
|||
.expect("Sender output failed");
|
||||
self.win.as_ref().unwrap().close();
|
||||
} else {
|
||||
self.win.as_ref().unwrap().add_toast(
|
||||
adw::Toast::builder()
|
||||
.title("Profile failed validation")
|
||||
.build(),
|
||||
alert(
|
||||
"Profile validation failed",
|
||||
Some("Check the values you set and try again"),
|
||||
Some(&self.win.as_ref().unwrap().clone().upcast::<gtk::Window>()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue