feat: openhmd calibration reset box in main view
Some checks failed
/ cargo-fmtcheck (push) Has been cancelled
/ cargo-clippy (push) Has been cancelled
/ cargo-test (push) Has been cancelled
/ appimage (push) Has been cancelled

This commit is contained in:
Gabriele Musco 2024-10-17 18:21:03 +02:00
commit 59b035c49d
3 changed files with 120 additions and 0 deletions

View file

@ -6,6 +6,7 @@ use super::{
},
devices_box::{DevicesBox, DevicesBoxMsg},
install_wivrn_box::{InstallWivrnBox, InstallWivrnBoxInit, InstallWivrnBoxMsg},
openhmd_calibration_box::{OpenHmdCalibrationBox, OpenHmdCalibrationBoxMsg},
profile_editor::{ProfileEditor, ProfileEditorInit, ProfileEditorMsg, ProfileEditorOutMsg},
steam_launch_options_box::{SteamLaunchOptionsBox, SteamLaunchOptionsBoxMsg},
steamvr_calibration_box::{SteamVrCalibrationBox, SteamVrCalibrationBoxMsg},
@ -62,6 +63,8 @@ pub struct MainView {
#[tracker::do_not_track]
steamvr_calibration_box: Controller<SteamVrCalibrationBox>,
#[tracker::do_not_track]
openhmd_calibration_box: Controller<OpenHmdCalibrationBox>,
#[tracker::do_not_track]
root_win: gtk::Window,
#[tracker::do_not_track]
profile_delete_action: gtk::gio::SimpleAction,
@ -404,6 +407,7 @@ impl SimpleComponent for MainView {
model.wivrn_wired_start_box.widget(),
model.install_wivrn_box.widget(),
model.steamvr_calibration_box.widget(),
model.openhmd_calibration_box.widget(),
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
@ -505,6 +509,9 @@ impl SimpleComponent for MainView {
self.steamvr_calibration_box
.sender()
.emit(SteamVrCalibrationBoxMsg::XRServiceActiveChanged(active));
self.openhmd_calibration_box
.sender()
.emit(OpenHmdCalibrationBoxMsg::XRServiceActiveChanged(active));
if !active {
sender.input(Self::Input::UpdateDevices(vec![]));
}
@ -529,6 +536,11 @@ impl SimpleComponent for MainView {
.emit(SteamVrCalibrationBoxMsg::SetVisible(
prof.lighthouse_driver == LighthouseDriver::SteamVR,
));
self.openhmd_calibration_box
.sender()
.emit(OpenHmdCalibrationBoxMsg::SetVisible(
prof.features.openhmd.enabled,
));
self.install_wivrn_box
.sender()
.emit(InstallWivrnBoxMsg::UpdateSelectedProfile(prof.clone()));
@ -788,6 +800,12 @@ impl SimpleComponent for MainView {
.emit(SteamVrCalibrationBoxMsg::SetVisible(
init.selected_profile.lighthouse_driver == LighthouseDriver::SteamVR,
));
let openhmd_calibration_box = OpenHmdCalibrationBox::builder().launch(()).detach();
openhmd_calibration_box
.sender()
.emit(OpenHmdCalibrationBoxMsg::SetVisible(
init.selected_profile.features.openhmd.enabled,
));
let mut actions = RelmActionGroup::<ProfileActionGroup>::new();
@ -842,6 +860,7 @@ impl SimpleComponent for MainView {
profile_delete_confirm_dialog,
root_win: init.root_win.clone(),
steamvr_calibration_box,
openhmd_calibration_box,
profile_editor: None,
xrservice_ready: false,
profile_delete_action,

View file

@ -12,6 +12,7 @@ pub mod job_worker;
mod libsurvive_setup_window;
mod macros;
mod main_view;
mod openhmd_calibration_box;
mod preference_rows;
mod profile_editor;
mod steam_launch_options_box;

View file

@ -0,0 +1,100 @@
use crate::{constants::APP_NAME, xdg::XDG};
use relm4::{
gtk::{self, prelude::*},
ComponentParts, ComponentSender, SimpleComponent,
};
#[tracker::track]
pub struct OpenHmdCalibrationBox {
visible: bool,
xrservice_active: bool,
}
#[derive(Debug)]
pub enum OpenHmdCalibrationBoxMsg {
SetVisible(bool),
XRServiceActiveChanged(bool),
}
#[relm4::component(pub)]
impl SimpleComponent for OpenHmdCalibrationBox {
type Init = ();
type Input = OpenHmdCalibrationBoxMsg;
type Output = ();
view! {
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_hexpand: true,
set_vexpand: false,
set_spacing: 12,
add_css_class: "card",
add_css_class: "padded",
#[track = "model.changed(Self::visible())"]
set_visible: model.visible,
gtk::Label {
add_css_class: "heading",
set_hexpand: true,
set_xalign: 0.0,
set_label: "Rift CV1 Calibration",
set_wrap: true,
set_wrap_mode: gtk::pango::WrapMode::Word,
},
gtk::Label {
add_css_class: "dim-label",
set_hexpand: true,
set_label: &format!(
"On the first run, start {APP_NAME} with your headset in full clear view of both camera bases for a functioning and effective calibration.\n\nYou can reset the calibration with the button below.",
),
set_xalign: 0.0,
set_wrap: true,
set_wrap_mode: gtk::pango::WrapMode::Word,
},
gtk::Button {
set_label: "Reset Calibration",
set_halign: gtk::Align::Start,
#[track = "model.changed(Self::xrservice_active())"]
set_sensitive: !model.xrservice_active,
connect_clicked => move |_| {
let target = XDG.get_config_home().join("openhmd/rift-room-config.json");
if target.is_file() {
if let Err(e) = std::fs::remove_file(target) {
eprintln!("Failed to remove openhmd config: {e}");
}
} else {
println!("info: trying to delete openhmd calibration config, but file is missing")
}
}
},
},
}
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
self.reset();
match message {
Self::Input::SetVisible(state) => {
self.set_visible(state);
}
Self::Input::XRServiceActiveChanged(active) => {
self.set_xrservice_active(active);
}
}
}
fn init(
_init: Self::Init,
root: Self::Root,
_sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {
tracker: 0,
visible: false,
xrservice_active: false,
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
}