add more help to grab-help

This commit is contained in:
galister
2025-12-21 17:03:40 +09:00
parent 1c6ebc745d
commit a139ab7b15
6 changed files with 121 additions and 14 deletions

View File

@@ -2,23 +2,37 @@
<elements>
<div interactable="0">
<rectangle
max_width="500"
max_width="600"
padding="16"
flex_direction="column"
gap="8"
color="#000000c0" border_color="~color_accent" border="2" round="8">
<div flex_direction="row" align_items="center" gap="8">
<div flex_direction="row" padding="8" justify_content="space_between">
<div flex_direction="column" align_items="center" gap="8" max_width="160" min_width="160">
<sprite src="grab-help/controller-grip-joy.svg" min_width="128" min_height="128" max_width="128" max_height="128" flex_grow="1" />
<label wrap="1" size="25" padding_left="16" padding_right="16" translation="GRAB.ADJUST_DISTANCE" />
<label wrap="1" size="25" padding_left="16" padding_right="16" translation="GRAB.ADJUST_DISTANCE" align="center" />
</div>
<div flex_direction="row" align_items="center" gap="8">
<div flex_direction="column" align_items="center" gap="8" max_width="160" min_width="160">
<sprite src="grab-help/controller-grip-trigger-joy.svg" min_width="128" min_height="128" max_width="128" max_height="128" flex_grow="1" />
<label wrap="1" size="25" padding_left="16" padding_right="16" translation="GRAB.ADJUST_SIZE" />
<label wrap="1" size="25" padding_left="16" padding_right="16" translation="GRAB.ADJUST_SIZE" align="center" />
</div>
<div flex_direction="row" align_items="center" gap="8">
<div flex_direction="column" align_items="center" gap="8" max_width="160" min_width="160">
<sprite src="grab-help/controller-grip-b.svg" min_width="128" min_height="128" max_width="128" max_height="128" flex_grow="1" />
<label wrap="1" size="25" padding_left="16" padding_right="16" translation="GRAB.UNRESTRICTED_MOVEMENT" />
<label wrap="1" size="25" padding_left="16" padding_right="16" translation="GRAB.UNRESTRICTED_MOVEMENT" align="center" />
</div>
</div>
<!-- A simple separator -->
<rectangle width="100%" height="2" color="~color_accent" />
<div align_items="center" padding="8" >
<label display="none" id="grabbing_watch" wrap="1" size="20" padding_right="16" translation="GRAB.GRABBING_WATCH" />
<label display="none" id="grabbing_static" wrap="1" size="20" padding_left="16" padding_right="16" translation="GRAB.GRABBING_STATIC" />
<label display="none" id="grabbing_anchored" wrap="1" size="20" padding_left="16" padding_right="16" translation="GRAB.GRABBING_ANCHORED" />
<label display="none" id="grabbing_anchored_edit" wrap="1" size="20" padding_left="16" padding_right="16" translation="GRAB.GRABBING_ANCHORED_EDIT" />
<label display="none" id="grabbing_floating" wrap="1" size="20" padding_left="16" padding_right="16" translation="GRAB.GRABBING_FLOATING" />
<label display="none" id="grabbing_follow" wrap="1" size="20" padding_left="16" padding_right="16" translation="GRAB.GRABBING_FOLLOW" />
</div>
</rectangle>

View File

@@ -49,7 +49,13 @@
"GRAB": {
"ADJUST_DISTANCE": "Adjust distance",
"ADJUST_SIZE": "Adjust size",
"UNRESTRICTED_MOVEMENT": "Unrestricted movement"
"UNRESTRICTED_MOVEMENT": "Unrestricted movement",
"GRABBING_WATCH": "To swap hands, move the watch in front and grab it with the other hand.",
"GRABBING_STATIC": "This overlay is Static and will stay in place, ignoring recenter.",
"GRABBING_ANCHORED": "Anchored overlays all move together. Separate a single window by grabbing it with the other hand while still grabbing the anchor.",
"GRABBING_ANCHORED_EDIT": "This overlay will stay anchored to the center marker.",
"GRABBING_FLOATING": "This overlay is Floating and will stay in place, unless recentered.",
"GRABBING_FOLLOW": "This overlay will follow the device it is attached to."
},
"WATCH": {
"ADD_NEW_SET": "Add a new set",

View File

@@ -1,5 +1,6 @@
use std::f32::consts::PI;
use std::process::{Child, Command};
use std::sync::Arc;
use std::time::Instant;
use glam::{Affine3A, Vec2, Vec3A, Vec3Swizzles};
@@ -15,6 +16,7 @@ use crate::overlays::watch::WATCH_NAME;
use crate::state::{AppSession, AppState};
use crate::subsystem::hid::WheelDelta;
use crate::subsystem::input::KeyboardFocus;
use crate::windowing::backend::OverlayEventData;
use crate::windowing::manager::OverlayWindowManager;
use crate::windowing::window::{self, OverlayWindowData, realign};
use crate::windowing::{OverlayID, OverlaySelector};
@@ -403,7 +405,15 @@ where
&mut app.hid_provider.keyboard_focus,
hovered.config.keyboard_focus,
);
start_grab(idx, hit.overlay, hovered_state, app, edit_mode);
start_grab(
idx,
hit.overlay,
hovered.config.name.clone(),
hovered.config.editing,
hovered_state,
app,
edit_mode,
);
log::debug!("Hand {}: grabbed {}", hit.pointer, hovered.config.name);
return (
hit.dist,
@@ -606,6 +616,8 @@ where
fn start_grab(
idx: usize,
id: OverlayID,
name: Arc<str>,
editing: bool,
state: &mut OverlayWindowState,
app: &mut AppState,
edit_mode: bool,
@@ -644,9 +656,15 @@ fn start_grab(
)));
if let Some(hand) = pointer.hand().clone() {
let pos = state.positioning;
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Modify(
OverlaySelector::Name(GRAB_HELP_NAME.clone()),
Box::new(move |app, o| {
let _ = o
.backend
.notify(app, OverlayEventData::OverlayGrabbed { name, pos, editing })
.inspect_err(|e| log::warn!("Error during Notify OverlayGrabbed: {e:?}"));
o.default_state.positioning = Positioning::FollowHand {
hand,
lerp: 0.1,

View File

@@ -1,9 +1,14 @@
use glam::{Affine3A, Quat, Vec3};
use std::sync::{Arc, LazyLock};
use wgui::event::{EventAlterables, StyleSetRequest};
use wgui::parser::Fetchable;
use wgui::taffy;
use wlx_common::windowing::{OverlayWindowState, Positioning};
use crate::gui::panel::GuiPanel;
use crate::overlays::watch::WATCH_NAME;
use crate::state::AppState;
use crate::windowing::backend::OverlayEventData;
use crate::windowing::window::OverlayWindowConfig;
use crate::windowing::{Z_ORDER_ANCHOR, Z_ORDER_HELP};
@@ -38,6 +43,61 @@ pub fn create_grab_help(app: &mut AppState) -> anyhow::Result<OverlayWindowConfi
let mut panel = GuiPanel::new_from_template(app, "gui/grab-help.xml", (), Default::default())?;
panel.update_layout()?;
let id_watch = panel.parser_state.data.get_widget_id("grabbing_watch")?;
let id_static = panel.parser_state.data.get_widget_id("grabbing_static")?;
let id_anchored = panel.parser_state.data.get_widget_id("grabbing_anchored")?;
let id_anchored_edit = panel
.parser_state
.data
.get_widget_id("grabbing_anchored_edit")?;
let id_floating = panel.parser_state.data.get_widget_id("grabbing_floating")?;
let id_follow = panel.parser_state.data.get_widget_id("grabbing_follow")?;
let all = [
id_watch,
id_static,
id_anchored,
id_anchored_edit,
id_floating,
id_follow,
];
panel.on_notify = Some(Box::new(move |panel, _app, event_data| {
let mut alterables = EventAlterables::default();
let OverlayEventData::OverlayGrabbed { name, pos, editing } = event_data else {
return Ok(());
};
let show_id = match pos {
Positioning::Static => id_static,
Positioning::Floating => id_floating,
Positioning::Anchored => {
if editing {
id_anchored_edit
} else {
id_anchored
}
}
Positioning::FollowHand { .. } if &*name == WATCH_NAME => id_watch,
Positioning::FollowHead { .. } | Positioning::FollowHand { .. } => id_follow,
};
for id in &all {
let display = if *id == show_id {
taffy::Display::Flex
} else {
taffy::Display::None
};
alterables.set_style(*id, StyleSetRequest::Display(display));
}
panel.layout.process_alterables(alterables)?;
Ok(())
}));
Ok(OverlayWindowConfig {
name: GRAB_HELP_NAME.clone(),
z_order: Z_ORDER_HELP,

View File

@@ -420,6 +420,7 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
}
}
}
_ => {}
}
panel.layout.process_alterables(alterables)?;

View File

@@ -6,7 +6,10 @@ use wgui::gfx::{
WGfx,
cmd::{GfxCommandBuffer, WGfxClearMode},
};
use wlx_common::overlays::{BackendAttrib, BackendAttribValue};
use wlx_common::{
overlays::{BackendAttrib, BackendAttribValue},
windowing::Positioning,
};
use crate::{
backend::input::{HoverResult, PointerHit},
@@ -112,6 +115,11 @@ pub enum OverlayEventData {
EditModeChanged(bool),
OverlaysChanged(Vec<OverlayMeta>),
DevicesChanged,
OverlayGrabbed {
name: Arc<str>,
pos: Positioning,
editing: bool,
},
}
pub trait OverlayBackend: Any {