From 51f3126cae1e6a065bc34899eb5d6fae60aa1079 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Sat, 30 May 2026 11:30:54 +0200 Subject: [PATCH] Space gravity UI improvements --- dash-frontend/assets/dashboard/gravity.svg | 46 ++++++ .../gui/tab/settings_tab_space_drag.xml | 14 ++ dash-frontend/assets/lang/en.json | 13 +- dash-frontend/src/tab/settings/mod.rs | 150 ++++++++++-------- .../src/tab/settings/tab_space_drag.rs | 110 +++++++++++-- dash-frontend/src/util/popup_manager.rs | 13 +- dash-frontend/src/views/running_games_list.rs | 5 +- uidev/src/testbed/testbed_generic.rs | 12 +- wayvr/src/backend/playspace_common.rs | 16 +- wayvr/src/config.rs | 18 ++- wayvr/src/gui/panel/mod.rs | 10 +- wayvr/src/overlays/anchor.rs | 8 +- wayvr/src/overlays/edit/pos.rs | 22 +-- wayvr/src/overlays/edit/tab.rs | 8 +- wayvr/src/overlays/watch.rs | 8 +- wgui/src/components/editbox.rs | 9 +- wgui/src/event.rs | 11 ++ wgui/src/layout.rs | 13 +- wgui/src/parser/widget_label.rs | 6 +- wlx-common/src/config.rs | 13 +- 20 files changed, 328 insertions(+), 177 deletions(-) create mode 100644 dash-frontend/assets/dashboard/gravity.svg create mode 100644 dash-frontend/assets/gui/tab/settings_tab_space_drag.xml diff --git a/dash-frontend/assets/dashboard/gravity.svg b/dash-frontend/assets/dashboard/gravity.svg new file mode 100644 index 00000000..bec06901 --- /dev/null +++ b/dash-frontend/assets/dashboard/gravity.svg @@ -0,0 +1,46 @@ + + + + + + + + + diff --git a/dash-frontend/assets/gui/tab/settings_tab_space_drag.xml b/dash-frontend/assets/gui/tab/settings_tab_space_drag.xml new file mode 100644 index 00000000..3f8f9cf7 --- /dev/null +++ b/dash-frontend/assets/gui/tab/settings_tab_space_drag.xml @@ -0,0 +1,14 @@ + + + + +
+ + +
+
+ +
+ + + diff --git a/dash-frontend/assets/lang/en.json b/dash-frontend/assets/lang/en.json index eb63fd90..f8da5b28 100644 --- a/dash-frontend/assets/lang/en.json +++ b/dash-frontend/assets/lang/en.json @@ -55,6 +55,7 @@ "DELETE_ALL_CONFIGS_HELP": "Remove all configuration files from conf.d", "DOUBLE_CURSOR_FIX": "Double cursor fix", "DOUBLE_CURSOR_FIX_HELP": "Enable this if you see 2 cursors", + "ENABLED": "Enabled", "FEATURES": "Features", "FOCUS_FOLLOWS_MOUSE_MODE": "Mouse move on trigger touch", "HANDSFREE_POINTER": "Handsfree mode", @@ -104,12 +105,16 @@ "SKYBOX": "Skybox", "SKYMAP_ALREADY_DOWNLOADED": "This skymap is already downloaded. Select desired action.", "SPACE_DRAG": "Space drag", - "SPACE_DRAG_FLING_STRENGTH": "Fling strength", - "SPACE_DRAG_DAMPING": "Damping", - "SPACE_DRAG_GRAVITY": "Gravity", "SPACE_DRAG_MULTIPLIER": "Space drag multiplier", - "SPACE_DRAG_GROUND_FRICTION": "Ground friction", "SPACE_DRAG_UNLOCKED": "Allow space drag on all axes", + "SPACE_GRAVITY_DAMPING": "Damping", + "SPACE_GRAVITY_DAMPING_HELP": "Artificial drag to slow down movement. 0.1 - high drag, 1.0 - no drag", + "SPACE_GRAVITY_FLING_STRENGTH": "Fling strength", + "SPACE_GRAVITY_FLING_STRENGTH_HELP": "Intensity multiplier of gravitational launch force after space-drag.\n0.0 - no movement at all, 2.0 - double intensity", + "SPACE_GRAVITY_GRAVITY": "Gravity", + "SPACE_GRAVITY_GRAVITY_HELP": "Amount of downwards force. 0.0 - no gravity", + "SPACE_GRAVITY_GROUND_FRICTION": "Ground friction", + "SPACE_GRAVITY_GROUND_FRICTION_HELP": "Amount of friction slowing you down if you're touching the ground.\n0.0 - no friction (just like on ice), 1.0 - rough surface", "SPACE_ROTATE_UNLOCKED": "Allow space rotate on all axes", "TROUBLESHOOTING": "Troubleshooting", "UI_GRADIENT_INTENSITY": "UI Gradient intensity", diff --git a/dash-frontend/src/tab/settings/mod.rs b/dash-frontend/src/tab/settings/mod.rs index c93f382d..17f71d8c 100644 --- a/dash-frontend/src/tab/settings/mod.rs +++ b/dash-frontend/src/tab/settings/mod.rs @@ -44,27 +44,27 @@ mod tab_troubleshooting; #[derive(Clone)] enum TabNameEnum { - LookAndFeel, - Features, - SpaceDrag, - Controls, - Misc, AutostartApps, - Troubleshooting, + Controls, + Features, + LookAndFeel, + Misc, Skybox, + SpaceDrag, + Troubleshooting, } impl TabNameEnum { fn from_string(s: &str) -> Option { match s { - "look_and_feel" => Some(TabNameEnum::LookAndFeel), - "features" => Some(TabNameEnum::Features), - "controls" => Some(TabNameEnum::Controls), - "space_drag" => Some(TabNameEnum::SpaceDrag), - "misc" => Some(TabNameEnum::Misc), "autostart_apps" => Some(TabNameEnum::AutostartApps), - "troubleshooting" => Some(TabNameEnum::Troubleshooting), + "controls" => Some(TabNameEnum::Controls), + "features" => Some(TabNameEnum::Features), + "look_and_feel" => Some(TabNameEnum::LookAndFeel), + "misc" => Some(TabNameEnum::Misc), "skybox" => Some(TabNameEnum::Skybox), + "space_drag" => Some(TabNameEnum::SpaceDrag), + "troubleshooting" => Some(TabNameEnum::Troubleshooting), _ => None, } } @@ -72,18 +72,18 @@ impl TabNameEnum { #[derive(Clone)] enum Task { - UpdateBool(SettingType, bool), - UpdateFloat(SettingType, f32), - UpdateInt(SettingType, i32), - SettingUpdated(SettingType), - OpenContextMenu(Vec2, Vec), ClearPipewireTokens, ClearSavedState, DeleteAllConfigs, + OpenContextMenu(Vec2, Vec), + RemoveAutostartApp(Rc), ResetPlayspace, RestartSoftware, - RemoveAutostartApp(Rc), SetTab(TabNameEnum), + SettingUpdated(SettingType), + UpdateBool(SettingType, bool), + UpdateFloat(SettingType, f32), + UpdateInt(SettingType, i32), } struct SettingsMountParams<'a> { @@ -93,10 +93,20 @@ struct SettingsMountParams<'a> { feats: InterfaceFeats, } +struct SettingUpdatedParams<'a> { + layout: &'a mut Layout, + config: &'a GeneralConfig, + setting_type: SettingType, +} + trait SettingsTab { fn update(&mut self, _par: &mut ViewUpdateParams) -> anyhow::Result<()> { Ok(()) } + + fn setting_updated(&mut self, _sup: &mut SettingUpdatedParams) -> anyhow::Result<()> { + Ok(()) + } } pub struct TabSettings { @@ -206,12 +216,21 @@ impl Tab for TabSettings { changed = Some(ConfigChangeKind::OverlayConfig); } } - Task::SettingUpdated(setting) => match setting { - SettingType::UiAnimationSpeed | SettingType::UiGradientIntensity | SettingType::UiRoundMultiplier => { - // todo: currently, wayvr restart is required to apply these changes (WguiTheme is Rc) + Task::SettingUpdated(setting) => { + if let Some(tab) = &mut self.current_tab { + tab.setting_updated(&mut SettingUpdatedParams { + layout: &mut frontend.layout, + config: frontend.interface.general_config(data), + setting_type: setting, + })?; } - _ => { /* do nothing */ } - }, + match setting { + SettingType::UiAnimationSpeed | SettingType::UiGradientIntensity | SettingType::UiRoundMultiplier => { + // todo: currently, wayvr restart is required to apply these changes (WguiTheme is Rc) + } + _ => { /* do nothing */ } + } + } } } @@ -250,7 +269,7 @@ impl Tab for TabSettings { // Sorted alphabetically #[allow(clippy::enum_variant_names)] -#[derive(Clone, Copy, AsRefStr, EnumString)] +#[derive(Clone, Copy, Eq, PartialEq, AsRefStr, EnumString)] enum SettingType { AllowSliding, BlockGameInput, @@ -261,6 +280,7 @@ enum SettingType { Clock12h, DoubleCursorFix, FocusFollowsMouseMode, + GridOpacity, HandsfreePointer, HideGrabHelp, HideUsername, @@ -278,12 +298,13 @@ enum SettingType { ScreenRenderDown, ScrollSpeed, SetsOnWatch, - SpaceDragFlingStrength, - SpaceDragDamping, - SpaceDragGravity, SpaceDragMultiplier, - SpaceDragGroundFriction, SpaceDragUnlocked, + SpaceGravityDamping, + SpaceGravityEnabled, + SpaceGravityFlingStrength, + SpaceGravityGravity, + SpaceGravityGroundFriction, SpaceRotateUnlocked, UiAnimationSpeed, UiGradientIntensity, @@ -291,7 +312,6 @@ enum SettingType { UprightScreenFix, UsePassthrough, UseSkybox, - GridOpacity, WatchViewAngleMax, WatchViewAngleMin, XrClickSensitivity, @@ -309,29 +329,30 @@ impl SettingType { pub fn mut_bool(self, config: &mut GeneralConfig) -> &mut bool { match self { - Self::InvertScrollDirectionX => &mut config.invert_scroll_direction_x, - Self::InvertScrollDirectionY => &mut config.invert_scroll_direction_y, - Self::NotificationsEnabled => &mut config.notifications_enabled, - Self::NotificationsSoundEnabled => &mut config.notifications_sound_enabled, - Self::KeyboardSoundEnabled => &mut config.keyboard_sound_enabled, - Self::UprightScreenFix => &mut config.upright_screen_fix, - Self::DoubleCursorFix => &mut config.double_cursor_fix, - Self::SetsOnWatch => &mut config.sets_on_watch, - Self::HideGrabHelp => &mut config.hide_grab_help, Self::AllowSliding => &mut config.allow_sliding, - Self::FocusFollowsMouseMode => &mut config.focus_follows_mouse_mode, - Self::LeftHandedMouse => &mut config.left_handed_mouse, Self::BlockGameInput => &mut config.block_game_input, Self::BlockGameInputIgnoreWatch => &mut config.block_game_input_ignore_watch, Self::BlockPosesOnKbdInteraction => &mut config.block_poses_on_kbd_interaction, - Self::UseSkybox => &mut config.use_skybox, - Self::UsePassthrough => &mut config.use_passthrough, - Self::ScreenRenderDown => &mut config.screen_render_down, - Self::SpaceDragUnlocked => &mut config.space_drag_unlocked, - Self::SpaceRotateUnlocked => &mut config.space_rotate_unlocked, Self::Clock12h => &mut config.clock_12h, + Self::DoubleCursorFix => &mut config.double_cursor_fix, + Self::FocusFollowsMouseMode => &mut config.focus_follows_mouse_mode, + Self::HideGrabHelp => &mut config.hide_grab_help, Self::HideUsername => &mut config.hide_username, + Self::InvertScrollDirectionX => &mut config.invert_scroll_direction_x, + Self::InvertScrollDirectionY => &mut config.invert_scroll_direction_y, + Self::KeyboardSoundEnabled => &mut config.keyboard_sound_enabled, + Self::LeftHandedMouse => &mut config.left_handed_mouse, + Self::NotificationsEnabled => &mut config.notifications_enabled, + Self::NotificationsSoundEnabled => &mut config.notifications_sound_enabled, Self::OpaqueBackground => &mut config.opaque_background, + Self::ScreenRenderDown => &mut config.screen_render_down, + Self::SetsOnWatch => &mut config.sets_on_watch, + Self::SpaceDragUnlocked => &mut config.space_drag_unlocked, + Self::SpaceGravityEnabled => &mut config.space_gravity_enabled, + Self::SpaceRotateUnlocked => &mut config.space_rotate_unlocked, + Self::UprightScreenFix => &mut config.upright_screen_fix, + Self::UsePassthrough => &mut config.use_passthrough, + Self::UseSkybox => &mut config.use_skybox, Self::XwaylandByDefault => &mut config.xwayland_by_default, _ => panic!("Requested bool for non-bool SettingType"), } @@ -339,22 +360,22 @@ impl SettingType { pub fn mut_f32(self, config: &mut GeneralConfig) -> &mut f32 { match self { + Self::GridOpacity => &mut config.grid_opacity, + Self::LongPressDuration => &mut config.long_press_duration, + Self::PointerLerpFactor => &mut config.pointer_lerp_factor, + Self::ScrollSpeed => &mut config.scroll_speed, + Self::SpaceDragMultiplier => &mut config.space_drag_multiplier, + Self::SpaceGravityDamping => &mut config.space_gravity_damping, + Self::SpaceGravityFlingStrength => &mut config.space_gravity_fling_strength, + Self::SpaceGravityGravity => &mut config.space_gravity_gravity, + Self::SpaceGravityGroundFriction => &mut config.space_gravity_ground_friction, Self::UiAnimationSpeed => &mut config.ui_animation_speed, Self::UiGradientIntensity => &mut config.ui_gradient_intensity, Self::UiRoundMultiplier => &mut config.ui_round_multiplier, - Self::ScrollSpeed => &mut config.scroll_speed, - Self::LongPressDuration => &mut config.long_press_duration, - Self::XrClickSensitivity => &mut config.xr_click_sensitivity, - Self::XrClickSensitivityRelease => &mut config.xr_click_sensitivity_release, - Self::SpaceDragFlingStrength => &mut config.space_drag_fling_strength, - Self::SpaceDragDamping => &mut config.space_drag_damping, - Self::SpaceDragGravity => &mut config.space_drag_gravity, - Self::SpaceDragMultiplier => &mut config.space_drag_multiplier, - Self::SpaceDragGroundFriction => &mut config.space_drag_ground_friction, - Self::PointerLerpFactor => &mut config.pointer_lerp_factor, - Self::GridOpacity => &mut config.grid_opacity, Self::WatchViewAngleMax => &mut config.watch_view_angle_max, Self::WatchViewAngleMin => &mut config.watch_view_angle_min, + Self::XrClickSensitivity => &mut config.xr_click_sensitivity, + Self::XrClickSensitivityRelease => &mut config.xr_click_sensitivity_release, _ => panic!("Requested f32 for non-f32 SettingType"), } } @@ -447,12 +468,13 @@ impl SettingType { Self::ScreenRenderDown => Ok("APP_SETTINGS.SCREEN_RENDER_DOWN"), Self::ScrollSpeed => Ok("APP_SETTINGS.SCROLL_SPEED"), Self::SetsOnWatch => Ok("APP_SETTINGS.SETS_ON_WATCH"), - Self::SpaceDragFlingStrength => Ok("APP_SETTINGS.SPACE_DRAG_FLING_STRENGTH"), - Self::SpaceDragDamping => Ok("APP_SETTINGS.SPACE_DRAG_DAMPING"), - Self::SpaceDragGravity => Ok("APP_SETTINGS.SPACE_DRAG_GRAVITY"), Self::SpaceDragMultiplier => Ok("APP_SETTINGS.SPACE_DRAG_MULTIPLIER"), - Self::SpaceDragGroundFriction => Ok("APP_SETTINGS.SPACE_DRAG_GROUND_FRICTION"), Self::SpaceDragUnlocked => Ok("APP_SETTINGS.SPACE_DRAG_UNLOCKED"), + Self::SpaceGravityDamping => Ok("APP_SETTINGS.SPACE_GRAVITY_DAMPING"), + Self::SpaceGravityEnabled => Ok("APP_SETTINGS.ENABLED"), + Self::SpaceGravityFlingStrength => Ok("APP_SETTINGS.SPACE_GRAVITY_FLING_STRENGTH"), + Self::SpaceGravityGravity => Ok("APP_SETTINGS.SPACE_GRAVITY_GRAVITY"), + Self::SpaceGravityGroundFriction => Ok("APP_SETTINGS.SPACE_GRAVITY_GROUND_FRICTION"), Self::SpaceRotateUnlocked => Ok("APP_SETTINGS.SPACE_ROTATE_UNLOCKED"), Self::UiAnimationSpeed => Ok("APP_SETTINGS.ANIMATION_SPEED"), Self::UiGradientIntensity => Ok("APP_SETTINGS.UI_GRADIENT_INTENSITY"), @@ -481,13 +503,17 @@ impl SettingType { Self::KeyboardMiddleClick => Some("APP_SETTINGS.KEYBOARD_MIDDLE_CLICK_HELP"), Self::LeftHandedMouse => Some("APP_SETTINGS.LEFT_HANDED_MOUSE_HELP"), Self::ScreenRenderDown => Some("APP_SETTINGS.SCREEN_RENDER_DOWN_HELP"), + Self::SpaceGravityDamping => Some("APP_SETTINGS.SPACE_GRAVITY_DAMPING_HELP"), + Self::SpaceGravityFlingStrength => Some("APP_SETTINGS.SPACE_GRAVITY_FLING_STRENGTH_HELP"), + Self::SpaceGravityGravity => Some("APP_SETTINGS.SPACE_GRAVITY_GRAVITY_HELP"), + Self::SpaceGravityGroundFriction => Some("APP_SETTINGS.SPACE_GRAVITY_GROUND_FRICTION_HELP"), Self::UprightScreenFix => Some("APP_SETTINGS.UPRIGHT_SCREEN_FIX_HELP"), Self::UsePassthrough => Some("APP_SETTINGS.USE_PASSTHROUGH_HELP"), Self::UseSkybox => Some("APP_SETTINGS.USE_SKYBOX_HELP"), + Self::WatchViewAngleMax => Some("APP_SETTINGS.WATCH_VIEW_ANGLE_HELP"), + Self::WatchViewAngleMin => Some("APP_SETTINGS.WATCH_VIEW_ANGLE_HELP"), Self::XrClickSensitivity => Some("APP_SETTINGS.XR_CLICK_SENSITIVITY_HELP"), Self::XrClickSensitivityRelease => Some("APP_SETTINGS.XR_CLICK_SENSITIVITY_HELP"), - Self::WatchViewAngleMin => Some("APP_SETTINGS.WATCH_VIEW_ANGLE_HELP"), - Self::WatchViewAngleMax => Some("APP_SETTINGS.WATCH_VIEW_ANGLE_HELP"), _ => None, } } diff --git a/dash-frontend/src/tab/settings/tab_space_drag.rs b/dash-frontend/src/tab/settings/tab_space_drag.rs index 3d9139d7..99aa1a50 100644 --- a/dash-frontend/src/tab/settings/tab_space_drag.rs +++ b/dash-frontend/src/tab/settings/tab_space_drag.rs @@ -1,28 +1,118 @@ +use wgui::{ + assets::AssetPath, + layout::{Layout, LayoutTask, WidgetID}, + parser::{Fetchable, ParseDocumentParams}, +}; + use crate::tab::settings::{ SettingType, SettingsMountParams, SettingsTab, macros::{options_category, options_checkbox, options_slider_f32}, }; -pub struct State {} +pub struct State { + id_space_gravity_parent: WidgetID, +} -impl SettingsTab for State {} +fn set_visible(parent: WidgetID, layout: &mut Layout, n: bool) { + layout.tasks.push(LayoutTask::SetWidgetVisible(parent, n)); +} + +impl SettingsTab for State { + fn setting_updated(&mut self, sup: &mut super::SettingUpdatedParams) -> anyhow::Result<()> { + if sup.setting_type == SettingType::SpaceGravityEnabled { + set_visible( + self.id_space_gravity_parent, + sup.layout, + sup.config.space_gravity_enabled, + ); + } + Ok(()) + } +} impl State { pub fn mount(par: SettingsMountParams) -> anyhow::Result { let c = options_category(par.mp, par.id_parent, "APP_SETTINGS.SPACE_DRAG", "dashboard/drag.svg")?; + + let globals = par.mp.layout.state.globals.clone(); + + let tab_state = wgui::parser::parse_from_assets( + &ParseDocumentParams { + globals, + path: AssetPath::BuiltIn("gui/tab/settings_tab_space_drag.xml"), + extra: Default::default(), + }, + par.mp.layout, + c, + )?; + + let id_common_options_parent = tab_state.get_widget_id("common_options_parent")?; + let id_gravity_enabled_parent = tab_state.get_widget_id("gravity_enabled_parent")?; + let id_space_gravity_parent = tab_state.get_widget_id("space_gravity_parent")?; + if !par.feats.openxr || par.feats.monado { // monado or openvr - options_checkbox(par.mp, c, SettingType::SpaceDragUnlocked)?; - options_slider_f32(par.mp, c, SettingType::SpaceDragMultiplier, -10.0, 10.0, 0.5)?; - options_slider_f32(par.mp, c, SettingType::SpaceDragGravity, 0.0, 10.0, 0.5)?; - options_slider_f32(par.mp, c, SettingType::SpaceDragDamping, 0.1, 1.0, 0.01)?; - options_slider_f32(par.mp, c, SettingType::SpaceDragFlingStrength, 0.0, 3.0, 0.1)?; - options_slider_f32(par.mp, c, SettingType::SpaceDragGroundFriction, 0.0, 1.0, 0.01)?; + options_checkbox(par.mp, id_common_options_parent, SettingType::SpaceDragUnlocked)?; + + options_slider_f32( + par.mp, + id_common_options_parent, + SettingType::SpaceDragMultiplier, + -10.0, + 10.0, + 0.5, + )?; + + /* space gravity section */ + options_checkbox(par.mp, id_gravity_enabled_parent, SettingType::SpaceGravityEnabled)?; + + options_slider_f32( + par.mp, + id_space_gravity_parent, + SettingType::SpaceGravityGravity, + 0.0, + 10.0, + 0.5, + )?; + options_slider_f32( + par.mp, + id_space_gravity_parent, + SettingType::SpaceGravityDamping, + 0.1, + 1.0, + 0.01, + )?; + options_slider_f32( + par.mp, + id_space_gravity_parent, + SettingType::SpaceGravityFlingStrength, + 0.0, + 3.0, + 0.1, + )?; + options_slider_f32( + par.mp, + id_space_gravity_parent, + SettingType::SpaceGravityGroundFriction, + 0.0, + 1.0, + 0.01, + )?; } + if par.feats.monado { // openvr can only ever rotate yaw - options_checkbox(par.mp, c, SettingType::SpaceRotateUnlocked)?; + options_checkbox(par.mp, id_common_options_parent, SettingType::SpaceRotateUnlocked)?; } - Ok(State {}) + + set_visible( + id_space_gravity_parent, + par.mp.layout, + par.mp.config.space_gravity_enabled, + ); + + Ok(State { + id_space_gravity_parent, + }) } } diff --git a/dash-frontend/src/util/popup_manager.rs b/dash-frontend/src/util/popup_manager.rs index e7c62151..7f1ab24e 100644 --- a/dash-frontend/src/util/popup_manager.rs +++ b/dash-frontend/src/util/popup_manager.rs @@ -6,12 +6,11 @@ use std::{ use wgui::{ assets::AssetPath, components::button::ComponentButton, - event::{EventAlterables, StyleSetRequest}, + event::EventAlterables, globals::WguiGlobals, i18n::Translation, layout::{Layout, LayoutTask, LayoutTasks, WidgetID}, parser::{Fetchable, ParseDocumentParams, ParserState}, - taffy::Display, widget::label::WidgetLabel, }; use wlx_common::config::GeneralConfig; @@ -232,15 +231,7 @@ impl State { let popup = popup.upgrade().unwrap(); // safe let popup = popup.borrow_mut(); let mounted_popup = popup.mounted_popup.as_ref().unwrap(); // safe; - - alterables.set_style( - mounted_popup.id_root, - StyleSetRequest::Display(if idx == self.popup_stack.len() - 1 { - Display::Flex - } else { - Display::None - }), - ); + alterables.set_widget_visible(mounted_popup.id_root, idx == self.popup_stack.len() - 1); } } } diff --git a/dash-frontend/src/views/running_games_list.rs b/dash-frontend/src/views/running_games_list.rs index 6428f5d1..bc607b20 100644 --- a/dash-frontend/src/views/running_games_list.rs +++ b/dash-frontend/src/views/running_games_list.rs @@ -112,10 +112,7 @@ impl View { fn fill_list(&mut self, layout: &mut Layout, games: Vec) -> anyhow::Result<()> { if games.is_empty() { // hide self - layout.tasks.push(LayoutTask::SetWidgetStyle( - self.parent_id, - StyleSetRequest::Display(Display::None), - )); + layout.tasks.push(LayoutTask::SetWidgetVisible(self.parent_id, false)); return Ok(()); } diff --git a/uidev/src/testbed/testbed_generic.rs b/uidev/src/testbed/testbed_generic.rs index d1d078da..e64baf79 100644 --- a/uidev/src/testbed/testbed_generic.rs +++ b/uidev/src/testbed/testbed_generic.rs @@ -13,7 +13,6 @@ use wgui::{ checkbox::ComponentCheckbox, }, drawing::Color, - event::StyleSetRequest, font_config::WguiFontConfig, globals::WguiGlobals, i18n::Translation, @@ -134,14 +133,9 @@ impl TestbedGeneric { let div_visibility = parser_state.fetch_widget(&layout.state, "div_visibility")?; cb_visible.on_toggle(Box::new(move |common, evt| { - common.alterables.set_style( - div_visibility.id, - StyleSetRequest::Display(if evt.checked { - taffy::Display::Flex - } else { - taffy::Display::None - }), - ); + common + .alterables + .set_widget_visible(div_visibility.id, evt.checked); Ok(()) })); diff --git a/wayvr/src/backend/playspace_common.rs b/wayvr/src/backend/playspace_common.rs index 9bbbb852..5fbf29cf 100644 --- a/wayvr/src/backend/playspace_common.rs +++ b/wayvr/src/backend/playspace_common.rs @@ -49,8 +49,12 @@ impl SpaceGravity { space_pos: Vec3A, dt: f32, ) { - self.velocity = hand_pos_diff * config.space_drag_fling_strength / dt; - self.space_pos = space_pos; + if config.space_gravity_enabled { + self.velocity = hand_pos_diff * config.space_gravity_fling_strength / dt; + self.space_pos = space_pos; + } else { + self.reset(); + } } pub fn reset(&mut self) { @@ -59,18 +63,18 @@ impl SpaceGravity { } pub fn update(&mut self, par: SpaceGravityUpdateParams) -> Option { - if par.dragging { + if par.dragging || !par.config.space_gravity_enabled { return None; } let prev_pos = self.space_pos; - self.velocity.y += par.config.space_drag_gravity * par.dt; + self.velocity.y += par.config.space_gravity_gravity * par.dt; // terminal velocity self.velocity.y = self.velocity.y.min(200.0); - self.velocity *= (par.config.space_drag_damping).powf(par.dt * 10.0); + self.velocity *= (par.config.space_gravity_damping).powf(par.dt * 10.0); self.space_pos += self.velocity * par.dt; @@ -80,7 +84,7 @@ impl SpaceGravity { /* at zero or below ground level */ { // apply ground friction - self.velocity *= 1.0 - par.config.space_drag_ground_friction * par.dt * 10.0; + self.velocity *= 1.0 - par.config.space_gravity_ground_friction * par.dt * 10.0; } if self.velocity.length_squared() > 0.00003 { diff --git a/wayvr/src/config.rs b/wayvr/src/config.rs index e7198bc0..df84e7c3 100644 --- a/wayvr/src/config.rs +++ b/wayvr/src/config.rs @@ -165,11 +165,12 @@ pub struct AutoSettings { pub screen_render_down: bool, pub pointer_lerp_factor: f32, pub space_drag_unlocked: bool, + pub space_gravity_damping: f32, + pub space_gravity_enabled: bool, + pub space_gravity_fling_strength: f32, + pub space_gravity_gravity: f32, + pub space_gravity_ground_friction: f32, pub space_rotate_unlocked: bool, - pub space_drag_gravity: f32, - pub space_drag_damping: f32, - pub space_drag_fling_strength: f32, - pub space_drag_ground_friction: f32, pub clock_12h: bool, pub hide_username: bool, pub opaque_background: bool, @@ -224,11 +225,12 @@ pub fn save_settings(config: &GeneralConfig) -> anyhow::Result<()> { screen_render_down: config.screen_render_down, pointer_lerp_factor: config.pointer_lerp_factor, space_drag_unlocked: config.space_drag_unlocked, + space_gravity_damping: config.space_gravity_damping, + space_gravity_enabled: config.space_gravity_enabled, + space_gravity_fling_strength: config.space_gravity_fling_strength, + space_gravity_gravity: config.space_gravity_gravity, + space_gravity_ground_friction: config.space_gravity_ground_friction, space_rotate_unlocked: config.space_rotate_unlocked, - space_drag_gravity: config.space_drag_gravity, - space_drag_damping: config.space_drag_damping, - space_drag_fling_strength: config.space_drag_fling_strength, - space_drag_ground_friction: config.space_drag_ground_friction, clock_12h: config.clock_12h, hide_username: config.hide_username, opaque_background: config.opaque_background, diff --git a/wayvr/src/gui/panel/mod.rs b/wayvr/src/gui/panel/mod.rs index 7726ffcc..5788f073 100644 --- a/wayvr/src/gui/panel/mod.rs +++ b/wayvr/src/gui/panel/mod.rs @@ -552,15 +552,7 @@ pub fn apply_custom_command( .parser_state .get_widget_id(element) .context("No widget with such id.")?; - - let display = if *visible { - taffy::Display::Flex - } else { - taffy::Display::None - }; - - com.alterables - .set_style(wid, wgui::event::StyleSetRequest::Display(display)); + com.alterables.set_widget_visible(wid, *visible); com.alterables.mark_redraw(); } ModifyPanelCommand::SetValue(value_str) => { diff --git a/wayvr/src/overlays/anchor.rs b/wayvr/src/overlays/anchor.rs index 529c1680..3b8011da 100644 --- a/wayvr/src/overlays/anchor.rs +++ b/wayvr/src/overlays/anchor.rs @@ -84,13 +84,7 @@ pub fn create_grab_help(app: &mut AppState) -> anyhow::Result anyhow::Result { } fn sets_or_overlays(panel: &mut GuiPanel, app: &mut AppState) { - let display = if app.session.config.sets_on_watch { - [taffy::Display::None, taffy::Display::Flex] + let visible = if app.session.config.sets_on_watch { + [false, true] } else { - [taffy::Display::Flex, taffy::Display::None] + [true, false] }; let widget = [ @@ -184,6 +184,6 @@ fn sets_or_overlays(panel: &mut GuiPanel, app: &mut AppState) { panel .layout .alterables - .set_style(widget[i], StyleSetRequest::Display(display[i])); + .set_widget_visible(widget[i], visible[i]); } } diff --git a/wgui/src/components/editbox.rs b/wgui/src/components/editbox.rs index c28650e6..14ea2de0 100644 --- a/wgui/src/components/editbox.rs +++ b/wgui/src/components/editbox.rs @@ -123,14 +123,7 @@ fn refresh_all(common: &mut CallbackDataCommon, data: &Data, state: &mut State) } // Cursor - common.alterables.set_style( - data.id_rect_cursor, - StyleSetRequest::Display(if state.focused { - taffy::Display::Flex - } else { - taffy::Display::None - }), - ); + common.alterables.set_widget_visible(data.id_rect_cursor, state.focused); state.first_refresh = false; diff --git a/wgui/src/event.rs b/wgui/src/event.rs index 5e09650e..ea6e38a9 100644 --- a/wgui/src/event.rs +++ b/wgui/src/event.rs @@ -138,6 +138,17 @@ impl EventAlterables { self.style_set_requests.push((widget_id, request)); } + pub fn set_widget_visible(&mut self, widget_id: WidgetID, visible: bool) { + self.style_set_requests.push(( + widget_id, + StyleSetRequest::Display(if visible { + taffy::Display::Flex + } else { + taffy::Display::None + }), + )); + } + pub fn mark_dirty(&mut self, widget_id: WidgetID) { self.dirty_widgets.push(widget_id); } diff --git a/wgui/src/layout.rs b/wgui/src/layout.rs index 2e202007..45870def 100644 --- a/wgui/src/layout.rs +++ b/wgui/src/layout.rs @@ -11,7 +11,7 @@ use crate::{ drawing::{ self, ANSI_BOLD_CODE, ANSI_RESET_CODE, Boundary, PushScissorStackResult, push_scissor_stack, push_transform_stack, }, - event::{self, CallbackDataCommon, Event, EventAlterables}, + event::{self, CallbackDataCommon, Event, EventAlterables, StyleSetRequest}, globals::WguiGlobals, sound::WguiSoundType, task::Tasks, @@ -149,6 +149,7 @@ pub type LayoutDispatchFunc = Box anyhow: pub enum LayoutTask { RemoveWidget(WidgetID), SetWidgetStyle(WidgetID, event::StyleSetRequest), + SetWidgetVisible(WidgetID, bool), // if true, sets Display to Flex; None, otherwise ModifyLayoutState(LayoutModifyStateFunc), PlaySound(WguiSoundType), Dispatch(LayoutDispatchFunc), @@ -746,6 +747,16 @@ impl Layout { LayoutTask::SetWidgetStyle(widget_id, style_request) => { self.set_style_request(widget_id, &style_request); } + LayoutTask::SetWidgetVisible(widget_id, visible) => { + self.set_style_request( + widget_id, + &StyleSetRequest::Display(if visible { + taffy::Display::Flex + } else { + taffy::Display::None + }), + ); + } LayoutTask::SetFocus(weak) => { if let Some(c) = weak.upgrade() { self.set_focus(Some(&components::Component(c)))?; diff --git a/wgui/src/parser/widget_label.rs b/wgui/src/parser/widget_label.rs index 4ad72e19..4652c72b 100644 --- a/wgui/src/parser/widget_label.rs +++ b/wgui/src/parser/widget_label.rs @@ -36,10 +36,8 @@ pub fn parse_widget_label<'a>( params.content = Translation::from_raw_text(value); } } - "translation" => { - if !value.is_empty() { - params.content = Translation::from_translation_key(value); - } + "translation" if !value.is_empty() => { + params.content = Translation::from_translation_key(value); } _ => {} } diff --git a/wlx-common/src/config.rs b/wlx-common/src/config.rs index eeb0803e..1c4dbf4d 100644 --- a/wlx-common/src/config.rs +++ b/wlx-common/src/config.rs @@ -336,17 +336,20 @@ pub struct GeneralConfig { #[serde(default = "def_false")] pub space_rotate_unlocked: bool, - #[serde(default = "def_one")] - pub space_drag_gravity: f32, + #[serde(default = "def_false")] + pub space_gravity_enabled: bool, #[serde(default = "def_one")] - pub space_drag_damping: f32, + pub space_gravity_gravity: f32, #[serde(default = "def_one")] - pub space_drag_fling_strength: f32, + pub space_gravity_damping: f32, #[serde(default = "def_one")] - pub space_drag_ground_friction: f32, + pub space_gravity_fling_strength: f32, + + #[serde(default = "def_one")] + pub space_gravity_ground_friction: f32, #[serde(default)] pub alt_click_down: Vec,