fix set/overlay persistence
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use std::{
|
||||
f32::consts::PI,
|
||||
ops::Add,
|
||||
sync::{Arc, LazyLock},
|
||||
time::Instant,
|
||||
@@ -17,6 +16,7 @@ use wlx_common::{
|
||||
use crate::{
|
||||
backend::task::{OverlayTask, TaskType},
|
||||
gui::panel::{GuiPanel, NewGuiPanelParams, OnCustomIdFunc},
|
||||
overlays::watch::{WATCH_POS, WATCH_ROT},
|
||||
state::AppState,
|
||||
windowing::{window::OverlayWindowConfig, OverlaySelector, Z_ORDER_TOAST},
|
||||
};
|
||||
@@ -121,12 +121,14 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<OverlayWindowConfig> {
|
||||
Positioning::FollowHead { lerp: 0.1 },
|
||||
),
|
||||
ToastDisplayMethod::Watch => {
|
||||
let mut watch_pos = app.session.config.watch_pos + vec3(-0.005, -0.05, 0.02);
|
||||
let mut watch_rot = app.session.config.watch_rot;
|
||||
let relative_to = match app.session.config.watch_hand {
|
||||
LeftRight::Left => Positioning::FollowHand {
|
||||
//FIXME: properly follow watch
|
||||
let watch_pos = WATCH_POS + vec3(-0.005, -0.05, 0.02);
|
||||
let watch_rot = WATCH_ROT;
|
||||
let relative_to = /*match app.session.config.watch_hand {
|
||||
LeftRight::Left =>*/ Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
/*
|
||||
},
|
||||
LeftRight::Right => {
|
||||
watch_pos.x = -watch_pos.x;
|
||||
@@ -135,7 +137,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<OverlayWindowConfig> {
|
||||
hand: LeftRight::Right,
|
||||
lerp: 1.0,
|
||||
}
|
||||
}
|
||||
}*/
|
||||
};
|
||||
(watch_pos, watch_rot, relative_to)
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use glam::{Affine3A, Vec3};
|
||||
|
||||
use crate::{
|
||||
gui::{panel::GuiPanel, timer::GuiTimer},
|
||||
state::AppState,
|
||||
windowing::{
|
||||
window::{OverlayWindowConfig, OverlayWindowState, Positioning},
|
||||
Z_ORDER_WATCH,
|
||||
},
|
||||
};
|
||||
|
||||
pub const EDIT_NAME: &str = "edit";
|
||||
|
||||
struct EditState {
|
||||
num_sets: usize,
|
||||
current_set: usize,
|
||||
}
|
||||
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
pub fn create_edit(
|
||||
app: &mut AppState,
|
||||
num_sets: usize,
|
||||
current_set: usize,
|
||||
) -> anyhow::Result<OverlayWindowConfig> {
|
||||
let state = EditState {
|
||||
num_sets,
|
||||
current_set,
|
||||
};
|
||||
let mut panel = GuiPanel::new_from_template(
|
||||
app,
|
||||
"gui/watch.xml",
|
||||
state,
|
||||
Some(Box::new(
|
||||
move |id, widget, doc_params, layout, parser_state| {
|
||||
if &*id != "sets" {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for idx in 0..num_sets {
|
||||
let mut params: HashMap<Rc<str>, Rc<str>> = HashMap::new();
|
||||
params.insert("display".into(), (idx + 1).to_string().into());
|
||||
params.insert("handle".into(), idx.to_string().into());
|
||||
parser_state.instantiate_template(doc_params, "Set", layout, widget, params)?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)),
|
||||
)?;
|
||||
|
||||
panel
|
||||
.timers
|
||||
.push(GuiTimer::new(Duration::from_millis(100), 0));
|
||||
|
||||
let positioning = Positioning::FollowHand {
|
||||
hand: app.session.config.watch_hand as _,
|
||||
lerp: 1.0,
|
||||
};
|
||||
|
||||
panel.update_layout()?;
|
||||
|
||||
Ok(OverlayWindowConfig {
|
||||
name: EDIT_NAME.into(),
|
||||
z_order: Z_ORDER_WATCH,
|
||||
default_state: OverlayWindowState {
|
||||
interactable: true,
|
||||
positioning,
|
||||
transform: Affine3A::from_scale_rotation_translation(
|
||||
Vec3::ONE * 0.115,
|
||||
app.session.config.watch_rot,
|
||||
app.session.config.watch_pos,
|
||||
) * Affine3A::from_translation(Vec3::Y * 0.075),
|
||||
..OverlayWindowState::default()
|
||||
},
|
||||
show_on_spawn: true,
|
||||
global: true,
|
||||
..OverlayWindowConfig::from_backend(Box::new(panel))
|
||||
})
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use glam::{Affine3A, Vec3, Vec3A};
|
||||
use glam::{vec3, Affine3A, Quat, Vec3, Vec3A};
|
||||
use idmap::DirectIdMap;
|
||||
use wgui::{
|
||||
components::button::ComponentButton,
|
||||
@@ -16,7 +16,10 @@ use wgui::{
|
||||
taffy,
|
||||
widget::{sprite::WidgetSprite, EventResult},
|
||||
};
|
||||
use wlx_common::windowing::{OverlayWindowState, Positioning};
|
||||
use wlx_common::{
|
||||
common::LeftRight,
|
||||
windowing::{OverlayWindowState, Positioning},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
backend::{
|
||||
@@ -41,6 +44,9 @@ pub const WATCH_NAME: &str = "watch";
|
||||
const MAX_TOOLBOX_BUTTONS: usize = 16;
|
||||
const MAX_DEVICES: usize = 9;
|
||||
|
||||
pub(crate) const WATCH_POS: Vec3 = vec3(-0.03, -0.01, 0.125);
|
||||
pub(crate) const WATCH_ROT: Quat = Quat::from_xyzw(-0.707_106_6, 0.000_796_361_8, 0.707_106_6, 0.0);
|
||||
|
||||
#[derive(Default)]
|
||||
struct WatchState {
|
||||
current_set: Option<usize>,
|
||||
@@ -323,7 +329,7 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
.push(GuiTimer::new(Duration::from_millis(100), 0));
|
||||
|
||||
let positioning = Positioning::FollowHand {
|
||||
hand: app.session.config.watch_hand,
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
};
|
||||
|
||||
@@ -337,8 +343,8 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
positioning,
|
||||
transform: Affine3A::from_scale_rotation_translation(
|
||||
Vec3::ONE * 0.115,
|
||||
app.session.config.watch_rot,
|
||||
app.session.config.watch_pos,
|
||||
WATCH_ROT,
|
||||
WATCH_POS,
|
||||
),
|
||||
..OverlayWindowState::default()
|
||||
},
|
||||
|
||||
@@ -251,7 +251,7 @@ where
|
||||
if newly_created {
|
||||
log::info!("Creating dashboard overlay");
|
||||
|
||||
let mut overlay = OverlayWindowData::from_config(OverlayWindowConfig {
|
||||
let overlay = OverlayWindowData::from_config(OverlayWindowConfig {
|
||||
default_state: OverlayWindowState {
|
||||
interactable: true,
|
||||
grabbable: true,
|
||||
@@ -284,8 +284,6 @@ where
|
||||
)?
|
||||
});
|
||||
|
||||
overlay.config.reset(app, true);
|
||||
|
||||
let overlay_id = overlays.add(overlay, app);
|
||||
wayvr.set_overlay_display_handle(overlay_id, disp_handle);
|
||||
|
||||
@@ -433,7 +431,14 @@ where
|
||||
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Modify(
|
||||
OverlaySelector::Id(overlay_id),
|
||||
Box::new(move |app, o| {
|
||||
o.toggle(app);
|
||||
if visible == o.is_active() {
|
||||
return;
|
||||
}
|
||||
if visible {
|
||||
o.activate(app);
|
||||
} else {
|
||||
o.deactivate();
|
||||
}
|
||||
}),
|
||||
)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user