Fix Shape tool type dropdown not persisting selection and not excluding Line/Rectangle/Ellipse (#3731)
* fix Shape tool dropdown resetting to Polygon when switching tools * add sync for rectangle/ellipse and line * fix build issues
This commit is contained in:
parent
9f9dd71e91
commit
e7a2800665
|
|
@ -1,5 +1,5 @@
|
||||||
use super::common_functionality::shape_editor::ShapeState;
|
use super::common_functionality::shape_editor::ShapeState;
|
||||||
use super::common_functionality::shapes::shape_utility::ShapeType::{self, Ellipse, Line, Rectangle};
|
use super::common_functionality::shapes::shape_utility::ShapeType::{Ellipse, Line, Rectangle};
|
||||||
use super::utility_types::{ToolActionMessageContext, ToolFsmState, tool_message_to_tool_type};
|
use super::utility_types::{ToolActionMessageContext, ToolFsmState, tool_message_to_tool_type};
|
||||||
use crate::application::generate_uuid;
|
use crate::application::generate_uuid;
|
||||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||||
|
|
@ -77,7 +77,8 @@ impl MessageHandler<ToolMessage, ToolMessageContext<'_>> for ToolMessageHandler
|
||||||
self.tool_state.tool_data.active_tool_type = ToolType::Shape;
|
self.tool_state.tool_data.active_tool_type = ToolType::Shape;
|
||||||
}
|
}
|
||||||
responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Shape });
|
responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Shape });
|
||||||
responses.add(ShapeToolMessage::SetShape { shape: ShapeType::Polygon });
|
// Sync current_shape with the dropdown selection (options.shape_type)
|
||||||
|
responses.add(ShapeToolMessage::SyncShapeWithOptions);
|
||||||
responses.add(ShapeToolMessage::HideShapeTypeWidget { hide: false })
|
responses.add(ShapeToolMessage::HideShapeTypeWidget { hide: false })
|
||||||
}
|
}
|
||||||
ToolMessage::ActivateToolBrush => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Brush }),
|
ToolMessage::ActivateToolBrush => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Brush }),
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ pub enum ShapeToolMessage {
|
||||||
PointerOutsideViewport { modifier: ShapeToolModifierKey },
|
PointerOutsideViewport { modifier: ShapeToolModifierKey },
|
||||||
UpdateOptions { options: ShapeOptionsUpdate },
|
UpdateOptions { options: ShapeOptionsUpdate },
|
||||||
SetShape { shape: ShapeType },
|
SetShape { shape: ShapeType },
|
||||||
|
SyncShapeWithOptions,
|
||||||
|
|
||||||
IncreaseSides,
|
IncreaseSides,
|
||||||
DecreaseSides,
|
DecreaseSides,
|
||||||
|
|
@ -180,30 +181,12 @@ fn create_shape_option_widget(shape_type: ShapeType) -> WidgetInstance {
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}),
|
}),
|
||||||
MenuListEntry::new("Rectangle").label("Rectangle").on_commit(move |_| {
|
|
||||||
ShapeToolMessage::UpdateOptions {
|
|
||||||
options: ShapeOptionsUpdate::ShapeType(ShapeType::Rectangle),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}),
|
|
||||||
MenuListEntry::new("Ellipse").label("Ellipse").on_commit(move |_| {
|
|
||||||
ShapeToolMessage::UpdateOptions {
|
|
||||||
options: ShapeOptionsUpdate::ShapeType(ShapeType::Ellipse),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}),
|
|
||||||
MenuListEntry::new("Arrow").label("Arrow").on_commit(move |_| {
|
MenuListEntry::new("Arrow").label("Arrow").on_commit(move |_| {
|
||||||
ShapeToolMessage::UpdateOptions {
|
ShapeToolMessage::UpdateOptions {
|
||||||
options: ShapeOptionsUpdate::ShapeType(ShapeType::Arrow),
|
options: ShapeOptionsUpdate::ShapeType(ShapeType::Arrow),
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}),
|
}),
|
||||||
MenuListEntry::new("Line").label("Line").on_commit(move |_| {
|
|
||||||
ShapeToolMessage::UpdateOptions {
|
|
||||||
options: ShapeOptionsUpdate::ShapeType(ShapeType::Line),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}),
|
|
||||||
]];
|
]];
|
||||||
DropdownInput::new(entries).selected_index(Some(shape_type as u32)).widget_instance()
|
DropdownInput::new(entries).selected_index(Some(shape_type as u32)).widget_instance()
|
||||||
}
|
}
|
||||||
|
|
@ -1183,15 +1166,16 @@ impl Fsm for ShapeToolFsmState {
|
||||||
responses.add(DocumentMessage::AbortTransaction);
|
responses.add(DocumentMessage::AbortTransaction);
|
||||||
tool_data.data.cleanup(responses);
|
tool_data.data.cleanup(responses);
|
||||||
tool_data.current_shape = shape;
|
tool_data.current_shape = shape;
|
||||||
responses.add(ShapeToolMessage::UpdateOptions {
|
// Update hints for the new shape (without updating options.shape_type)
|
||||||
options: ShapeOptionsUpdate::ShapeType(shape),
|
update_dynamic_hints(&ShapeToolFsmState::Ready(shape), responses, tool_data);
|
||||||
});
|
|
||||||
|
|
||||||
responses.add(ShapeToolMessage::UpdateOptions {
|
|
||||||
options: ShapeOptionsUpdate::ShapeType(shape),
|
|
||||||
});
|
|
||||||
ShapeToolFsmState::Ready(shape)
|
ShapeToolFsmState::Ready(shape)
|
||||||
}
|
}
|
||||||
|
(_, ShapeToolMessage::SyncShapeWithOptions) => {
|
||||||
|
// Sync current_shape with the dropdown selection when returning from alias tools
|
||||||
|
tool_data.current_shape = tool_options.shape_type;
|
||||||
|
update_dynamic_hints(&ShapeToolFsmState::Ready(tool_options.shape_type), responses, tool_data);
|
||||||
|
ShapeToolFsmState::Ready(tool_options.shape_type)
|
||||||
|
}
|
||||||
(_, ShapeToolMessage::HideShapeTypeWidget { hide }) => {
|
(_, ShapeToolMessage::HideShapeTypeWidget { hide }) => {
|
||||||
tool_data.hide_shape_option_widget = hide;
|
tool_data.hide_shape_option_widget = hide;
|
||||||
responses.add(ToolMessage::RefreshToolOptions);
|
responses.add(ToolMessage::RefreshToolOptions);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue