From b90b7336e0ad7e9e6090f38842f4816e9086838f Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Mon, 22 Dec 2025 17:47:46 +0900 Subject: [PATCH] add universal _long_release and variants --- wgui/src/components/button.rs | 16 +- wgui/src/parser/component_button.rs | 7 +- wgui/src/widget/mod.rs | 6 +- wlx-common/src/config.rs | 3 + wlx-overlay-s/src/assets/gui/edit.xml | 4 +- wlx-overlay-s/src/assets/gui/watch-noset.xml | 2 +- wlx-overlay-s/src/assets/gui/watch.xml | 2 +- wlx-overlay-s/src/gui/README.md | 8 +- wlx-overlay-s/src/gui/panel/button.rs | 147 +++++++++++++++---- wlx-overlay-s/src/gui/panel/mod.rs | 5 +- wlx-overlay-s/src/overlays/edit/mod.rs | 57 +++---- wlx-overlay-s/src/overlays/watch.rs | 64 ++++---- wlx-overlay-s/src/res/config.yaml | 6 +- 13 files changed, 223 insertions(+), 104 deletions(-) diff --git a/wgui/src/components/button.rs b/wgui/src/components/button.rs index 6ab9043..95656b2 100644 --- a/wgui/src/components/button.rs +++ b/wgui/src/components/button.rs @@ -23,7 +23,11 @@ use crate::{ }, }; use glam::{Mat4, Vec3}; -use std::{cell::RefCell, rc::Rc}; +use std::{ + cell::RefCell, + rc::Rc, + time::{Duration, Instant}, +}; use taffy::{prelude::length, AlignItems, JustifyContent}; pub struct Params<'a> { @@ -42,6 +46,7 @@ pub struct Params<'a> { /// until "un-clicked". this is visual only. /// set the initial state using `set_sticky_state` pub sticky: bool, + pub long_press_time: f32, } impl Default for Params<'_> { @@ -59,6 +64,7 @@ impl Default for Params<'_> { text_style: TextStyle::default(), tooltip: None, sticky: false, + long_press_time: 0.0, } } } @@ -80,6 +86,7 @@ struct State { on_click: Option, active_tooltip: Option>, colors: Colors, + last_pressed: Instant, } struct Data { @@ -152,6 +159,10 @@ impl ComponentButton { rect.params.color2 = get_color2(&color); } + pub fn get_time_since_last_pressed(&self) -> Duration { + self.state.borrow().last_pressed.elapsed() + } + pub fn on_click(&self, func: ButtonClickCallback) { self.state.borrow_mut().on_click = Some(func); } @@ -329,6 +340,7 @@ fn register_event_mouse_press(state: Rc>, listeners: &mut EventLi if state.hovered { state.down = true; + state.last_pressed = Instant::now(); Ok(EventResult::Consumed) } else { Ok(EventResult::Pass) @@ -357,7 +369,6 @@ fn register_event_mouse_release( if state.down { state.down = false; - if state.hovered && let Some(on_click) = &state.on_click { @@ -507,6 +518,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul on_click: None, active_tooltip: None, sticky_down: false, + last_pressed: Instant::now(), colors: Colors { color, border_color, diff --git a/wgui/src/parser/component_button.rs b/wgui/src/parser/component_button.rs index 02dab0f..51727d1 100644 --- a/wgui/src/parser/component_button.rs +++ b/wgui/src/parser/component_button.rs @@ -5,7 +5,7 @@ use crate::{ i18n::Translation, layout::WidgetID, parser::{ - parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib, process_component, + parse_check_f32, parse_check_i32, parse_children, parse_f32, print_invalid_attrib, process_component, style::{parse_color_opt, parse_round, parse_style, parse_text_style}, AttribPair, ParserContext, ParserFile, }, @@ -28,6 +28,7 @@ pub fn parse_component_button<'a>( let mut tooltip: Option = None; let mut tooltip_side: Option = None; let mut sticky: bool = false; + let mut long_press_time = 0.0; let mut sprite_src: Option = None; let mut translation: Option = None; @@ -92,6 +93,9 @@ pub fn parse_component_button<'a>( let mut sticky_i32 = 0; sticky = parse_check_i32(value, &mut sticky_i32) && sticky_i32 == 1; } + "long_press_time" => { + long_press_time = parse_f32(value).unwrap_or(long_press_time); + } _ => {} } } @@ -113,6 +117,7 @@ pub fn parse_component_button<'a>( text: Translation::from_translation_key(&t), }), sticky, + long_press_time, sprite_src, }, )?; diff --git a/wgui/src/widget/mod.rs b/wgui/src/widget/mod.rs index 43ad633..f0712a4 100644 --- a/wgui/src/widget/mod.rs +++ b/wgui/src/widget/mod.rs @@ -205,7 +205,11 @@ impl EventResult { #[must_use] pub fn merge(self, other: Self) -> Self { - if self > other { self } else { other } + if self > other { + self + } else { + other + } } } diff --git a/wlx-common/src/config.rs b/wlx-common/src/config.rs index c064a51..ce87a79 100644 --- a/wlx-common/src/config.rs +++ b/wlx-common/src/config.rs @@ -121,6 +121,9 @@ pub struct GeneralConfig { #[serde(default = "def_one")] pub scroll_speed: f32, + #[serde(default = "def_one")] + pub long_press_duration: f32, + #[serde(default = "def_mouse_move_interval_ms")] pub mouse_move_interval_ms: u32, diff --git a/wlx-overlay-s/src/assets/gui/edit.xml b/wlx-overlay-s/src/assets/gui/edit.xml index 4582b19..27a44af 100644 --- a/wlx-overlay-s/src/assets/gui/edit.xml +++ b/wlx-overlay-s/src/assets/gui/edit.xml @@ -15,7 +15,7 @@ @@ -48,7 +48,7 @@ - +
diff --git a/wlx-overlay-s/src/assets/gui/watch-noset.xml b/wlx-overlay-s/src/assets/gui/watch-noset.xml index d2faa63..fb5c179 100644 --- a/wlx-overlay-s/src/assets/gui/watch-noset.xml +++ b/wlx-overlay-s/src/assets/gui/watch-noset.xml @@ -35,7 +35,7 @@ All overlays are listed on bottom row.