Conditionally enable align and pivot buttons (#1313)
* feat: conditionally enable align buttons - enable select tool align buttons if selected layer count > 1 * wip: conditionally render pivot button * [wip] feat: conditionally enable select tools' pivot button * fix: prevent repeated UI updates on layer selection - set bool flag to false after first UI update
This commit is contained in:
parent
40ec52b395
commit
b937a64c37
|
|
@ -126,6 +126,10 @@ impl PropertyHolder for SelectTool {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let selected_layers_count = self.tool_data.selected_layers_count;
|
||||||
|
let deactivate_alignment = selected_layers_count < 2;
|
||||||
|
let deactivate_pivot = selected_layers_count < 1;
|
||||||
|
|
||||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||||
widgets: vec![
|
widgets: vec![
|
||||||
DropdownInput::new(vec![layer_selection_behavior_entries])
|
DropdownInput::new(vec![layer_selection_behavior_entries])
|
||||||
|
|
@ -135,11 +139,13 @@ impl PropertyHolder for SelectTool {
|
||||||
WidgetHolder::related_separator(),
|
WidgetHolder::related_separator(),
|
||||||
// We'd like this widget to hide and show itself whenever the transformation cage is active or inactive (i.e. when no layers are selected)
|
// We'd like this widget to hide and show itself whenever the transformation cage is active or inactive (i.e. when no layers are selected)
|
||||||
PivotAssist::new(self.tool_data.pivot.to_pivot_position())
|
PivotAssist::new(self.tool_data.pivot.to_pivot_position())
|
||||||
|
.disabled(deactivate_pivot)
|
||||||
.on_update(|pivot_assist: &PivotAssist| SelectToolMessage::SetPivot { position: pivot_assist.position }.into())
|
.on_update(|pivot_assist: &PivotAssist| SelectToolMessage::SetPivot { position: pivot_assist.position }.into())
|
||||||
.widget_holder(),
|
.widget_holder(),
|
||||||
WidgetHolder::section_separator(),
|
WidgetHolder::section_separator(),
|
||||||
IconButton::new("AlignLeft", 24)
|
IconButton::new("AlignLeft", 24)
|
||||||
.tooltip("Align Left")
|
.tooltip("Align Left")
|
||||||
|
.disabled(deactivate_alignment)
|
||||||
.on_update(|_| {
|
.on_update(|_| {
|
||||||
DocumentMessage::AlignSelectedLayers {
|
DocumentMessage::AlignSelectedLayers {
|
||||||
axis: AlignAxis::X,
|
axis: AlignAxis::X,
|
||||||
|
|
@ -150,6 +156,7 @@ impl PropertyHolder for SelectTool {
|
||||||
.widget_holder(),
|
.widget_holder(),
|
||||||
IconButton::new("AlignHorizontalCenter", 24)
|
IconButton::new("AlignHorizontalCenter", 24)
|
||||||
.tooltip("Align Horizontal Center")
|
.tooltip("Align Horizontal Center")
|
||||||
|
.disabled(deactivate_alignment)
|
||||||
.on_update(|_| {
|
.on_update(|_| {
|
||||||
DocumentMessage::AlignSelectedLayers {
|
DocumentMessage::AlignSelectedLayers {
|
||||||
axis: AlignAxis::X,
|
axis: AlignAxis::X,
|
||||||
|
|
@ -160,6 +167,7 @@ impl PropertyHolder for SelectTool {
|
||||||
.widget_holder(),
|
.widget_holder(),
|
||||||
IconButton::new("AlignRight", 24)
|
IconButton::new("AlignRight", 24)
|
||||||
.tooltip("Align Right")
|
.tooltip("Align Right")
|
||||||
|
.disabled(deactivate_alignment)
|
||||||
.on_update(|_| {
|
.on_update(|_| {
|
||||||
DocumentMessage::AlignSelectedLayers {
|
DocumentMessage::AlignSelectedLayers {
|
||||||
axis: AlignAxis::X,
|
axis: AlignAxis::X,
|
||||||
|
|
@ -171,6 +179,7 @@ impl PropertyHolder for SelectTool {
|
||||||
WidgetHolder::unrelated_separator(),
|
WidgetHolder::unrelated_separator(),
|
||||||
IconButton::new("AlignTop", 24)
|
IconButton::new("AlignTop", 24)
|
||||||
.tooltip("Align Top")
|
.tooltip("Align Top")
|
||||||
|
.disabled(deactivate_alignment)
|
||||||
.on_update(|_| {
|
.on_update(|_| {
|
||||||
DocumentMessage::AlignSelectedLayers {
|
DocumentMessage::AlignSelectedLayers {
|
||||||
axis: AlignAxis::Y,
|
axis: AlignAxis::Y,
|
||||||
|
|
@ -181,6 +190,7 @@ impl PropertyHolder for SelectTool {
|
||||||
.widget_holder(),
|
.widget_holder(),
|
||||||
IconButton::new("AlignVerticalCenter", 24)
|
IconButton::new("AlignVerticalCenter", 24)
|
||||||
.tooltip("Align Vertical Center")
|
.tooltip("Align Vertical Center")
|
||||||
|
.disabled(deactivate_alignment)
|
||||||
.on_update(|_| {
|
.on_update(|_| {
|
||||||
DocumentMessage::AlignSelectedLayers {
|
DocumentMessage::AlignSelectedLayers {
|
||||||
axis: AlignAxis::Y,
|
axis: AlignAxis::Y,
|
||||||
|
|
@ -191,6 +201,7 @@ impl PropertyHolder for SelectTool {
|
||||||
.widget_holder(),
|
.widget_holder(),
|
||||||
IconButton::new("AlignBottom", 24)
|
IconButton::new("AlignBottom", 24)
|
||||||
.tooltip("Align Bottom")
|
.tooltip("Align Bottom")
|
||||||
|
.disabled(deactivate_alignment)
|
||||||
.on_update(|_| {
|
.on_update(|_| {
|
||||||
DocumentMessage::AlignSelectedLayers {
|
DocumentMessage::AlignSelectedLayers {
|
||||||
axis: AlignAxis::Y,
|
axis: AlignAxis::Y,
|
||||||
|
|
@ -253,9 +264,10 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SelectT
|
||||||
|
|
||||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &(), responses, false);
|
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &(), responses, false);
|
||||||
|
|
||||||
if self.tool_data.pivot.should_refresh_pivot_position() {
|
if self.tool_data.pivot.should_refresh_pivot_position() || self.tool_data.selected_layers_changed {
|
||||||
// Notify the frontend about the updated pivot position (a bit ugly to do it here not in the fsm but that doesn't have SelectTool)
|
// Notify the frontend about the updated pivot position (a bit ugly to do it here not in the fsm but that doesn't have SelectTool)
|
||||||
self.register_properties(responses, LayoutTarget::ToolOptions);
|
self.register_properties(responses, LayoutTarget::ToolOptions);
|
||||||
|
self.tool_data.selected_layers_changed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,6 +330,8 @@ struct SelectToolData {
|
||||||
cursor: MouseCursorIcon,
|
cursor: MouseCursorIcon,
|
||||||
pivot: Pivot,
|
pivot: Pivot,
|
||||||
nested_selection_behavior: NestedSelectionBehavior,
|
nested_selection_behavior: NestedSelectionBehavior,
|
||||||
|
selected_layers_count: usize,
|
||||||
|
selected_layers_changed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectToolData {
|
impl SelectToolData {
|
||||||
|
|
@ -434,6 +448,16 @@ impl Fsm for SelectToolFsmState {
|
||||||
if let ToolMessage::Select(event) = event {
|
if let ToolMessage::Select(event) = event {
|
||||||
match (self, event) {
|
match (self, event) {
|
||||||
(_, DocumentIsDirty | SelectionChanged) => {
|
(_, DocumentIsDirty | SelectionChanged) => {
|
||||||
|
let selected_layers_count = document.selected_layers().count();
|
||||||
|
let selected_layers_changed = selected_layers_count != tool_data.selected_layers_count;
|
||||||
|
|
||||||
|
if selected_layers_changed {
|
||||||
|
tool_data.selected_layers_count = selected_layers_count;
|
||||||
|
tool_data.selected_layers_changed = true;
|
||||||
|
} else {
|
||||||
|
tool_data.selected_layers_changed = false;
|
||||||
|
}
|
||||||
|
|
||||||
match (document.selected_visible_layers_bounding_box(render_data), tool_data.bounding_box_overlays.take()) {
|
match (document.selected_visible_layers_bounding_box(render_data), tool_data.bounding_box_overlays.take()) {
|
||||||
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
|
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
|
||||||
(Some(bounds), paths) => {
|
(Some(bounds), paths) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue