fix sticky state on Lock Interaction
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
<rectangle padding="16" gap="8" round="32" color="~color_bg" border="2" border_color="~color_accent" justify_content="center">
|
<rectangle padding="16" gap="8" round="32" color="~color_bg" border="2" border_color="~color_accent" justify_content="center">
|
||||||
<div flex_direction="column" gap="8">
|
<div flex_direction="column" gap="8">
|
||||||
<div flex_direction="row" gap="4">
|
<div flex_direction="row" gap="4">
|
||||||
<TopButton sticky="1" id="top_lock" src="edit/lock_open.svg" tooltip="EDIT_MODE.LOCK_INTERACTION" press="::EditModeToggleLock" />
|
<TopButton sticky="0" id="top_lock" src="edit/lock_open.svg" tooltip="EDIT_MODE.LOCK_INTERACTION" press="::EditModeToggleLock" />
|
||||||
<TopButton sticky="1" id="top_grab" src="edit/disable-grab.svg" tooltip="EDIT_MODE.DISABLE_GRAB" press="::EditModeToggleGrab" />
|
<TopButton sticky="1" id="top_grab" src="edit/disable-grab.svg" tooltip="EDIT_MODE.DISABLE_GRAB" press="::EditModeToggleGrab" />
|
||||||
<TopButton sticky="0" id="top_pos" src="edit/anchor.svg" tooltip="EDIT_MODE.POSITIONING" press="::EditModeTab pos" />
|
<TopButton sticky="0" id="top_pos" src="edit/anchor.svg" tooltip="EDIT_MODE.POSITIONING" press="::EditModeTab pos" />
|
||||||
<TopButton sticky="0" id="top_alpha" src="edit/fade.svg" tooltip="EDIT_MODE.OPACITY" press="::EditModeTab alpha" />
|
<TopButton sticky="0" id="top_alpha" src="edit/fade.svg" tooltip="EDIT_MODE.OPACITY" press="::EditModeTab alpha" />
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use glam::FloatExt;
|
use glam::FloatExt;
|
||||||
use wgui::{
|
use wgui::{
|
||||||
animation::{Animation, AnimationEasing},
|
animation::{Animation, AnimationEasing},
|
||||||
|
components::button::ComponentButton,
|
||||||
event::CallbackDataCommon,
|
event::CallbackDataCommon,
|
||||||
layout::WidgetID,
|
layout::WidgetID,
|
||||||
parser::Fetchable,
|
parser::Fetchable,
|
||||||
@@ -15,6 +18,7 @@ pub(super) struct InteractLockHandler {
|
|||||||
id: WidgetID,
|
id: WidgetID,
|
||||||
color: wgui::drawing::Color,
|
color: wgui::drawing::Color,
|
||||||
interactable: bool,
|
interactable: bool,
|
||||||
|
button: Option<Rc<ComponentButton>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteractLockHandler {
|
impl InteractLockHandler {
|
||||||
@@ -27,10 +31,13 @@ impl InteractLockHandler {
|
|||||||
.get_as::<WidgetRectangle>(id)
|
.get_as::<WidgetRectangle>(id)
|
||||||
.context("Element with id=\"shadow\" must be a <rectangle>")?;
|
.context("Element with id=\"shadow\" must be a <rectangle>")?;
|
||||||
|
|
||||||
|
let button = panel.parser_state.fetch_component_as("top_lock")?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
color: shadow_rect.params.color,
|
color: shadow_rect.params.color,
|
||||||
interactable: true,
|
interactable: true,
|
||||||
|
button: Some(button),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +49,10 @@ impl InteractLockHandler {
|
|||||||
.get_as::<WidgetRectangle>(self.id)
|
.get_as::<WidgetRectangle>(self.id)
|
||||||
.unwrap(); // can only fail if set_up_rect has issues
|
.unwrap(); // can only fail if set_up_rect has issues
|
||||||
|
|
||||||
|
if let Some(button) = self.button.as_ref() {
|
||||||
|
button.set_sticky_state(common, !interactable);
|
||||||
|
}
|
||||||
|
|
||||||
let globals = common.state.globals.get();
|
let globals = common.state.globals.get();
|
||||||
if interactable {
|
if interactable {
|
||||||
set_anim_color(&mut rect, 0.0, self.color, globals.defaults.danger_color);
|
set_anim_color(&mut rect, 0.0, self.color, globals.defaults.danger_color);
|
||||||
@@ -60,6 +71,9 @@ impl InteractLockHandler {
|
|||||||
let rect_color = self.color;
|
let rect_color = self.color;
|
||||||
|
|
||||||
self.interactable = !self.interactable;
|
self.interactable = !self.interactable;
|
||||||
|
if let Some(button) = self.button.as_ref() {
|
||||||
|
button.set_sticky_state(common, !self.interactable);
|
||||||
|
}
|
||||||
|
|
||||||
let anim = if self.interactable {
|
let anim = if self.interactable {
|
||||||
Animation::new(
|
Animation::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user