edit mode ui fixes
This commit is contained in:
@@ -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<ComponentButton>,
|
||||
positioning: Positioning,
|
||||
has_interpolation: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct PositioningHandler {
|
||||
top_sprite_id: WidgetID,
|
||||
interpolation_id: WidgetID,
|
||||
buttons: HashMap<&'static str, Rc<PosButtonState>>,
|
||||
active_button: Option<Rc<PosButtonState>>,
|
||||
}
|
||||
@@ -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<ModifyOverlayTask> {
|
||||
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}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user