From 30c8a7e3c146e3b73b45495f1265113bc7975b51 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Thu, 11 Dec 2025 21:00:49 +0900 Subject: [PATCH] edit mode ui fixes --- wlx-common/src/windowing.rs | 15 +++++++ wlx-overlay-s/src/assets/gui/edit.xml | 19 ++++---- wlx-overlay-s/src/assets/gui/watch.xml | 2 +- wlx-overlay-s/src/assets/lang/en.json | 4 +- wlx-overlay-s/src/overlays/edit/mod.rs | 12 +++++ wlx-overlay-s/src/overlays/edit/pos.rs | 62 +++++++++++++++++++------- 6 files changed, 85 insertions(+), 29 deletions(-) diff --git a/wlx-common/src/windowing.rs b/wlx-common/src/windowing.rs index 4bda90f..30ccee8 100644 --- a/wlx-common/src/windowing.rs +++ b/wlx-common/src/windowing.rs @@ -22,6 +22,21 @@ impl Positioning { pub const fn moves_with_space(self) -> bool { matches!(self, Self::Floating | Self::Anchored | Self::Static) } + pub const fn get_lerp(self) -> Option { + match self { + Self::FollowHead { lerp } => Some(lerp), + Self::FollowHand { lerp, .. } => Some(lerp), + Self::Floating | Self::Anchored | Self::Static => None, + } + } + pub const fn with_lerp(mut self, value: f32) -> Self { + match self { + Self::FollowHead { ref mut lerp } => *lerp = value, + Self::FollowHand { ref mut lerp, .. } => *lerp = value, + Self::Floating | Self::Anchored | Self::Static => {} + } + self + } } // Contains the window state for a given set diff --git a/wlx-overlay-s/src/assets/gui/edit.xml b/wlx-overlay-s/src/assets/gui/edit.xml index 6029fc1..9db83e1 100644 --- a/wlx-overlay-s/src/assets/gui/edit.xml +++ b/wlx-overlay-s/src/assets/gui/edit.xml @@ -45,8 +45,8 @@ - - + +
@@ -63,20 +63,21 @@
-
+
-
-
-
-
diff --git a/wlx-overlay-s/src/assets/lang/en.json b/wlx-overlay-s/src/assets/lang/en.json index a1f1ee9..7ce93c5 100644 --- a/wlx-overlay-s/src/assets/lang/en.json +++ b/wlx-overlay-s/src/assets/lang/en.json @@ -5,12 +5,12 @@ "ADD_NEW_SET": "Add a new set", "SWITCH_TO_SET": "Switch to set", "TOGGLE_FOR_CURRENT_SET": "Toggle for current set", - "LONG_PRESS_TO_DELETE_SET": "Long press to delete set" + "LONG_PRESS_TO_DELETE_SET": "Hold to delete" }, "EDIT_MODE": { "ADJUST_CURVATURE": "Adjust curvature", "ALPHA_BLEND_MODE": "Alpha blend mode", - "BLENDING_ADDITIVE": "Additive", + "BLENDING_ADDITIVE": "Additive blending", "CURVATURE": "Curvature", "DELETE": "Long press to remove from current set", "HINT_POINT_WINDOW": "Point at a window to change its parameters.\nOnce done, leave edit mode using the button on the right.", diff --git a/wlx-overlay-s/src/overlays/edit/mod.rs b/wlx-overlay-s/src/overlays/edit/mod.rs index 6b14b29..bd29af8 100644 --- a/wlx-overlay-s/src/overlays/edit/mod.rs +++ b/wlx-overlay-s/src/overlays/edit/mod.rs @@ -309,6 +309,7 @@ fn make_edit_panel(app: &mut AppState) -> anyhow::Result { panel.state.tabs = ButtonPaneTabSwitcher::new(&mut panel, &["none", "pos", "alpha", "curve"])?; set_up_checkbox(&mut panel, "additive_box", cb_assign_additive)?; + set_up_slider(&mut panel, "lerp_slider", cb_assign_lerp)?; set_up_slider(&mut panel, "alpha_slider", cb_assign_alpha)?; set_up_slider(&mut panel, "curve_slider", cb_assign_curve)?; @@ -329,6 +330,11 @@ fn reset_panel( state: &panel.layout.state, }; + let c = panel + .parser_state + .fetch_component_as::("lerp_slider")?; + c.set_value(&mut common, state.positioning.get_lerp().unwrap_or(1.0)); + let c = panel .parser_state .fetch_component_as::("alpha_slider")?; @@ -353,6 +359,12 @@ fn reset_panel( Ok(()) } +const fn cb_assign_lerp(_app: &mut AppState, owc: &mut OverlayWindowConfig, lerp: f32) { + owc.dirty = true; + let active_state = owc.active_state.as_mut().unwrap(); + active_state.positioning = active_state.positioning.with_lerp(lerp); +} + const fn cb_assign_alpha(_app: &mut AppState, owc: &mut OverlayWindowConfig, alpha: f32) { owc.dirty = true; owc.active_state.as_mut().unwrap().alpha = alpha; diff --git a/wlx-overlay-s/src/overlays/edit/pos.rs b/wlx-overlay-s/src/overlays/edit/pos.rs index 893abab..93bc6d0 100644 --- a/wlx-overlay-s/src/overlays/edit/pos.rs +++ b/wlx-overlay-s/src/overlays/edit/pos.rs @@ -1,8 +1,12 @@ use std::{collections::HashMap, rc::Rc}; use wgui::{ - components::button::ComponentButton, event::CallbackDataCommon, layout::WidgetID, - parser::Fetchable, renderer_vk::text::custom_glyph::CustomGlyphData, + components::button::ComponentButton, + event::{CallbackDataCommon, StyleSetRequest}, + layout::WidgetID, + parser::Fetchable, + renderer_vk::text::custom_glyph::CustomGlyphData, + taffy, widget::sprite::WidgetSprite, }; use wlx_common::{common::LeftRight, windowing::Positioning}; @@ -18,11 +22,13 @@ struct PosButtonState { sprite: CustomGlyphData, component: Rc, positioning: Positioning, + has_interpolation: bool, } #[derive(Default)] pub(super) struct PositioningHandler { top_sprite_id: WidgetID, + interpolation_id: WidgetID, buttons: HashMap<&'static str, Rc>, active_button: Option>, } @@ -50,22 +56,27 @@ impl PositioningHandler { anyhow::anyhow!("Element with id=\"{sprite_id}\" must have a valid src!") })?; + let (positioning, has_interpolation) = key_to_pos(name); + buttons.insert( *name, Rc::new(PosButtonState { component, name, sprite, - positioning: key_to_pos(name), + positioning, + has_interpolation, }), ); } let top_sprite_id = panel.parser_state.get_widget_id("top_pos_sprite")?; + let interpolation_id = panel.parser_state.get_widget_id("pos_interpolation")?; Ok(Self { buttons, active_button: None, top_sprite_id, + interpolation_id, }) } @@ -77,6 +88,17 @@ impl PositioningHandler { new.component.set_sticky_state(common, true); self.active_button = Some(new.clone()); + let interpolation_disp = if new.has_interpolation { + taffy::Display::Flex + } else { + taffy::Display::None + }; + + common.alterables.set_style( + self.interpolation_id, + StyleSetRequest::Display(interpolation_disp), + ); + // change top sprite if let Some(mut sprite) = common .state @@ -94,7 +116,7 @@ impl PositioningHandler { ) -> Box { self.change_highlight(common, key); - let pos = key_to_pos(key); + let (pos, _) = key_to_pos(key); Box::new(move |app, owc| { let state = owc.active_state.as_mut().unwrap(); //want panic state.positioning = pos; @@ -108,20 +130,26 @@ impl PositioningHandler { } } -fn key_to_pos(key: &str) -> Positioning { +fn key_to_pos(key: &str) -> (Positioning, bool) { match key { - "static" => Positioning::Static, - "anchored" => Positioning::Anchored, - "floating" => Positioning::Floating, - "hmd" => Positioning::FollowHead { lerp: 1.0 }, - "hand_l" => Positioning::FollowHand { - hand: LeftRight::Left, - lerp: 1.0, - }, - "hand_r" => Positioning::FollowHand { - hand: LeftRight::Right, - lerp: 1.0, - }, + "static" => (Positioning::Static, false), + "anchored" => (Positioning::Anchored, false), + "floating" => (Positioning::Floating, false), + "hmd" => (Positioning::FollowHead { lerp: 1.0 }, true), + "hand_l" => ( + Positioning::FollowHand { + hand: LeftRight::Left, + lerp: 1.0, + }, + true, + ), + "hand_r" => ( + Positioning::FollowHand { + hand: LeftRight::Right, + lerp: 1.0, + }, + true, + ), _ => { panic!("cannot translate to positioning: {key}") }