grab-help panel, FollowHand align_to_hmd
This commit is contained in:
@@ -4,8 +4,8 @@ use wlx_common::windowing::{OverlayWindowState, Positioning};
|
||||
|
||||
use crate::gui::panel::GuiPanel;
|
||||
use crate::state::AppState;
|
||||
use crate::windowing::Z_ORDER_ANCHOR;
|
||||
use crate::windowing::window::OverlayWindowConfig;
|
||||
use crate::windowing::{Z_ORDER_ANCHOR, Z_ORDER_HELP};
|
||||
|
||||
pub static ANCHOR_NAME: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("anchor"));
|
||||
|
||||
@@ -31,3 +31,27 @@ pub fn create_anchor(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig>
|
||||
..OverlayWindowConfig::from_backend(Box::new(panel))
|
||||
})
|
||||
}
|
||||
|
||||
pub static GRAB_HELP_NAME: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("grab-help"));
|
||||
|
||||
pub fn create_grab_help(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
let mut panel = GuiPanel::new_from_template(app, "gui/grab-help.xml", (), Default::default())?;
|
||||
panel.update_layout()?;
|
||||
|
||||
Ok(OverlayWindowConfig {
|
||||
name: GRAB_HELP_NAME.clone(),
|
||||
z_order: Z_ORDER_HELP,
|
||||
default_state: OverlayWindowState {
|
||||
interactable: false,
|
||||
grabbable: false,
|
||||
transform: Affine3A::from_scale_rotation_translation(
|
||||
Vec3::ONE * 0.15,
|
||||
Quat::IDENTITY,
|
||||
Vec3::ZERO,
|
||||
),
|
||||
..OverlayWindowState::default()
|
||||
},
|
||||
global: true,
|
||||
..OverlayWindowConfig::from_backend(Box::new(panel))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -381,6 +381,7 @@ fn make_edit_panel(app: &mut AppState) -> anyhow::Result<EditModeWrapPanel> {
|
||||
)?;
|
||||
|
||||
set_up_checkbox(&mut panel, "additive_box", cb_assign_additive)?;
|
||||
set_up_checkbox(&mut panel, "align_box", cb_assign_align)?;
|
||||
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)?;
|
||||
@@ -427,6 +428,11 @@ fn reset_panel(
|
||||
.fetch_component_as::<ComponentCheckbox>("additive_box")?;
|
||||
c.set_checked(&mut common, state.additive);
|
||||
|
||||
let c = panel
|
||||
.parser_state
|
||||
.fetch_component_as::<ComponentCheckbox>("align_box")?;
|
||||
c.set_checked(&mut common, state.positioning.get_align().unwrap_or(false));
|
||||
|
||||
panel
|
||||
.state
|
||||
.pos
|
||||
@@ -493,6 +499,12 @@ const fn cb_assign_additive(_app: &mut AppState, owc: &mut OverlayWindowConfig,
|
||||
owc.active_state.as_mut().unwrap().additive = additive;
|
||||
}
|
||||
|
||||
const fn cb_assign_align(_app: &mut AppState, owc: &mut OverlayWindowConfig, align: bool) {
|
||||
owc.dirty = true;
|
||||
let active_state = owc.active_state.as_mut().unwrap();
|
||||
active_state.positioning = active_state.positioning.with_align(align);
|
||||
}
|
||||
|
||||
fn set_up_slider(
|
||||
panel: &mut EditModeWrapPanel,
|
||||
id: &str,
|
||||
|
||||
@@ -15,6 +15,7 @@ static POS_NAMES: [&str; 6] = ["static", "anchored", "floating", "hmd", "hand_l"
|
||||
pub struct PosTabState {
|
||||
pos: Positioning,
|
||||
has_lerp: bool,
|
||||
has_align: bool,
|
||||
}
|
||||
|
||||
impl From<Positioning> for PosTabState {
|
||||
@@ -22,6 +23,7 @@ impl From<Positioning> for PosTabState {
|
||||
Self {
|
||||
pos: value,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +32,7 @@ pub fn new_pos_tab_handler(
|
||||
panel: &mut EditModeWrapPanel,
|
||||
) -> anyhow::Result<SpriteTabHandler<PosTabState>> {
|
||||
let interpolation_id = panel.parser_state.get_widget_id("pos_interpolation")?;
|
||||
let align_to_hmd_id = panel.parser_state.get_widget_id("pos_align_to_hmd")?;
|
||||
|
||||
SpriteTabHandler::new(
|
||||
panel,
|
||||
@@ -55,6 +58,16 @@ pub fn new_pos_tab_handler(
|
||||
interpolation_id,
|
||||
StyleSetRequest::Display(interpolation_disp),
|
||||
);
|
||||
|
||||
let align_to_hmd_disp = if state.has_align {
|
||||
taffy::Display::Flex
|
||||
} else {
|
||||
taffy::Display::None
|
||||
};
|
||||
|
||||
common
|
||||
.alterables
|
||||
.set_style(align_to_hmd_id, StyleSetRequest::Display(align_to_hmd_disp));
|
||||
})),
|
||||
)
|
||||
}
|
||||
@@ -82,32 +95,40 @@ impl SpriteTabKey for PosTabState {
|
||||
"static" => PosTabState {
|
||||
pos: Positioning::Static,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
},
|
||||
"anchored" => PosTabState {
|
||||
pos: Positioning::Anchored,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
},
|
||||
"floating" => PosTabState {
|
||||
pos: Positioning::Floating,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
},
|
||||
"hmd" => PosTabState {
|
||||
pos: Positioning::FollowHead { lerp: 1.0 },
|
||||
has_lerp: true,
|
||||
has_align: false,
|
||||
},
|
||||
"hand_l" => PosTabState {
|
||||
pos: Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: false,
|
||||
},
|
||||
has_lerp: true,
|
||||
has_align: true,
|
||||
},
|
||||
"hand_r" => PosTabState {
|
||||
pos: Positioning::FollowHand {
|
||||
hand: LeftRight::Right,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: false,
|
||||
},
|
||||
has_lerp: true,
|
||||
has_align: true,
|
||||
},
|
||||
_ => {
|
||||
panic!("cannot translate to positioning: {key}")
|
||||
|
||||
@@ -128,6 +128,7 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<OverlayWindowConfig> {
|
||||
LeftRight::Left =>*/ Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: true,
|
||||
/*
|
||||
},
|
||||
LeftRight::Right => {
|
||||
|
||||
@@ -433,6 +433,7 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
let positioning = Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: false,
|
||||
};
|
||||
|
||||
panel.update_layout()?;
|
||||
|
||||
Reference in New Issue
Block a user