implement edit mode toggle
This commit is contained in:
@@ -260,6 +260,20 @@ pub fn openvr_run(
|
|||||||
TaskType::ToggleSet(set) => {
|
TaskType::ToggleSet(set) => {
|
||||||
overlays.switch_or_toggle_set(&mut app, set);
|
overlays.switch_or_toggle_set(&mut app, set);
|
||||||
}
|
}
|
||||||
|
TaskType::ToggleEditMode => {
|
||||||
|
if !overlays.get_edit_mode() {
|
||||||
|
Toast::new(
|
||||||
|
ToastTopic::System,
|
||||||
|
"Edit mode enabled".into(),
|
||||||
|
"Hover overlays to see their options".into(),
|
||||||
|
)
|
||||||
|
.with_timeout(5.)
|
||||||
|
.with_sound(true)
|
||||||
|
.submit(&mut app);
|
||||||
|
}
|
||||||
|
|
||||||
|
overlays.set_edit_mode(!overlays.get_edit_mode());
|
||||||
|
}
|
||||||
#[cfg(feature = "wayvr")]
|
#[cfg(feature = "wayvr")]
|
||||||
TaskType::WayVR(action) => {
|
TaskType::WayVR(action) => {
|
||||||
wayvr_action(&mut app, &mut overlays, &action);
|
wayvr_action(&mut app, &mut overlays, &action);
|
||||||
|
|||||||
@@ -544,6 +544,20 @@ pub fn openxr_run(
|
|||||||
TaskType::ToggleSet(set) => {
|
TaskType::ToggleSet(set) => {
|
||||||
overlays.switch_or_toggle_set(&mut app, set);
|
overlays.switch_or_toggle_set(&mut app, set);
|
||||||
}
|
}
|
||||||
|
TaskType::ToggleEditMode => {
|
||||||
|
if !overlays.get_edit_mode() {
|
||||||
|
Toast::new(
|
||||||
|
ToastTopic::System,
|
||||||
|
"Edit mode enabled".into(),
|
||||||
|
"Hover overlays to see their options".into(),
|
||||||
|
)
|
||||||
|
.with_timeout(5.)
|
||||||
|
.with_sound(true)
|
||||||
|
.submit(&mut app);
|
||||||
|
}
|
||||||
|
|
||||||
|
overlays.set_edit_mode(!overlays.get_edit_mode());
|
||||||
|
}
|
||||||
#[cfg(feature = "wayvr")]
|
#[cfg(feature = "wayvr")]
|
||||||
TaskType::WayVR(action) => {
|
TaskType::WayVR(action) => {
|
||||||
wayvr_action(&mut app, &mut overlays, &action);
|
wayvr_action(&mut app, &mut overlays, &action);
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ pub enum TaskType {
|
|||||||
CreateOverlay(OverlaySelector, Box<CreateOverlayTask>),
|
CreateOverlay(OverlaySelector, Box<CreateOverlayTask>),
|
||||||
DropOverlay(OverlaySelector),
|
DropOverlay(OverlaySelector),
|
||||||
ToggleSet(usize),
|
ToggleSet(usize),
|
||||||
|
ToggleEditMode,
|
||||||
System(SystemTask),
|
System(SystemTask),
|
||||||
#[cfg(feature = "wayvr")]
|
#[cfg(feature = "wayvr")]
|
||||||
WayVR(WayVRAction),
|
WayVR(WayVRAction),
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ pub(super) fn setup_custom_button<S: 'static>(
|
|||||||
"::WatchSwapHand" => todo!(),
|
"::WatchSwapHand" => todo!(),
|
||||||
// TODO
|
// TODO
|
||||||
#[allow(clippy::match_same_arms)]
|
#[allow(clippy::match_same_arms)]
|
||||||
"::EditToggle" => return,
|
"::EditToggle" => Box::new(move |_common, _data, app, _| {
|
||||||
|
app.tasks.enqueue(TaskType::ToggleEditMode);
|
||||||
|
Ok(EventResult::Consumed)
|
||||||
|
}),
|
||||||
// TODO
|
// TODO
|
||||||
#[allow(clippy::match_same_arms)]
|
#[allow(clippy::match_same_arms)]
|
||||||
"::OscSend" => return,
|
"::OscSend" => return,
|
||||||
|
|||||||
@@ -20,11 +20,12 @@ use crate::{
|
|||||||
type EditModeWrapPanel = GuiPanel<Arc<str>>;
|
type EditModeWrapPanel = GuiPanel<Arc<str>>;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct EditModeManager {
|
pub struct EditWrapperManager {
|
||||||
|
edit_mode: bool,
|
||||||
panel_pool: Vec<EditModeWrapPanel>,
|
panel_pool: Vec<EditModeWrapPanel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EditModeManager {
|
impl EditWrapperManager {
|
||||||
pub fn wrap_edit_mode(
|
pub fn wrap_edit_mode(
|
||||||
&mut self,
|
&mut self,
|
||||||
owc: &mut OverlayWindowConfig,
|
owc: &mut OverlayWindowConfig,
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ use slotmap::{HopSlotMap, Key, SecondaryMap};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
overlays::{
|
overlays::{
|
||||||
anchor::create_anchor, edit::EditModeManager, keyboard::builder::create_keyboard,
|
anchor::create_anchor,
|
||||||
screen::create_screens, watch::create_watch,
|
edit::EditWrapperManager,
|
||||||
|
keyboard::builder::create_keyboard,
|
||||||
|
screen::create_screens,
|
||||||
|
watch::{create_watch, WATCH_NAME},
|
||||||
},
|
},
|
||||||
state::AppState,
|
state::AppState,
|
||||||
windowing::{
|
windowing::{
|
||||||
@@ -18,7 +21,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct OverlayWindowManager<T> {
|
pub struct OverlayWindowManager<T> {
|
||||||
wrappers: EditModeManager,
|
wrappers: EditWrapperManager,
|
||||||
overlays: HopSlotMap<OverlayID, OverlayWindowData<T>>,
|
overlays: HopSlotMap<OverlayID, OverlayWindowData<T>>,
|
||||||
sets: Vec<OverlayWindowSet>,
|
sets: Vec<OverlayWindowSet>,
|
||||||
/// The set that is currently visible.
|
/// The set that is currently visible.
|
||||||
@@ -28,6 +31,7 @@ pub struct OverlayWindowManager<T> {
|
|||||||
restore_set: usize,
|
restore_set: usize,
|
||||||
anchor_local: Affine3A,
|
anchor_local: Affine3A,
|
||||||
watch_id: OverlayID,
|
watch_id: OverlayID,
|
||||||
|
edit_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> OverlayWindowManager<T>
|
impl<T> OverlayWindowManager<T>
|
||||||
@@ -38,13 +42,14 @@ where
|
|||||||
let mut maybe_keymap = None;
|
let mut maybe_keymap = None;
|
||||||
|
|
||||||
let mut me = Self {
|
let mut me = Self {
|
||||||
wrappers: EditModeManager::default(),
|
wrappers: EditWrapperManager::default(),
|
||||||
overlays: HopSlotMap::with_key(),
|
overlays: HopSlotMap::with_key(),
|
||||||
current_set: Some(0),
|
current_set: Some(0),
|
||||||
restore_set: 0,
|
restore_set: 0,
|
||||||
sets: vec![OverlayWindowSet::default()],
|
sets: vec![OverlayWindowSet::default()],
|
||||||
anchor_local: Affine3A::from_translation(Vec3::NEG_Z),
|
anchor_local: Affine3A::from_translation(Vec3::NEG_Z),
|
||||||
watch_id: OverlayID::null(), // set down below
|
watch_id: OverlayID::null(), // set down below
|
||||||
|
edit_mode: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if headless {
|
if headless {
|
||||||
@@ -170,11 +175,32 @@ impl<T> OverlayWindowManager<T> {
|
|||||||
self.restore_set = (app.session.config.last_set as usize).min(self.sets.len() - 1);
|
self.restore_set = (app.session.config.last_set as usize).min(self.sets.len() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_edit_mode(&self) -> bool {
|
||||||
|
self.edit_mode
|
||||||
|
}
|
||||||
|
pub fn set_edit_mode(&mut self, enabled: bool) {
|
||||||
|
self.edit_mode = enabled;
|
||||||
|
if enabled {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for o in self.overlays.values_mut() {
|
||||||
|
self.wrappers.unwrap_edit_mode(&mut o.config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn edit_overlay(&mut self, id: OverlayID, enabled: bool, app: &mut AppState) {
|
pub fn edit_overlay(&mut self, id: OverlayID, enabled: bool, app: &mut AppState) {
|
||||||
|
if !self.edit_mode {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let Some(overlay) = self.overlays.get_mut(id) else {
|
let Some(overlay) = self.overlays.get_mut(id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if &*overlay.config.name == WATCH_NAME {
|
||||||
|
return; // FIXME: not a proper solution
|
||||||
|
}
|
||||||
|
|
||||||
if enabled {
|
if enabled {
|
||||||
self.wrappers
|
self.wrappers
|
||||||
.wrap_edit_mode(&mut overlay.config, app)
|
.wrap_edit_mode(&mut overlay.config, app)
|
||||||
|
|||||||
Reference in New Issue
Block a user