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::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 crate::application::generate_uuid;
|
||||
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;
|
||||
}
|
||||
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 })
|
||||
}
|
||||
ToolMessage::ActivateToolBrush => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Brush }),
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ pub enum ShapeToolMessage {
|
|||
PointerOutsideViewport { modifier: ShapeToolModifierKey },
|
||||
UpdateOptions { options: ShapeOptionsUpdate },
|
||||
SetShape { shape: ShapeType },
|
||||
SyncShapeWithOptions,
|
||||
|
||||
IncreaseSides,
|
||||
DecreaseSides,
|
||||
|
|
@ -180,30 +181,12 @@ fn create_shape_option_widget(shape_type: ShapeType) -> WidgetInstance {
|
|||
}
|
||||
.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 |_| {
|
||||
ShapeToolMessage::UpdateOptions {
|
||||
options: ShapeOptionsUpdate::ShapeType(ShapeType::Arrow),
|
||||
}
|
||||
.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()
|
||||
}
|
||||
|
|
@ -1183,15 +1166,16 @@ impl Fsm for ShapeToolFsmState {
|
|||
responses.add(DocumentMessage::AbortTransaction);
|
||||
tool_data.data.cleanup(responses);
|
||||
tool_data.current_shape = shape;
|
||||
responses.add(ShapeToolMessage::UpdateOptions {
|
||||
options: ShapeOptionsUpdate::ShapeType(shape),
|
||||
});
|
||||
|
||||
responses.add(ShapeToolMessage::UpdateOptions {
|
||||
options: ShapeOptionsUpdate::ShapeType(shape),
|
||||
});
|
||||
// Update hints for the new shape (without updating options.shape_type)
|
||||
update_dynamic_hints(&ShapeToolFsmState::Ready(shape), responses, tool_data);
|
||||
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 }) => {
|
||||
tool_data.hide_shape_option_widget = hide;
|
||||
responses.add(ToolMessage::RefreshToolOptions);
|
||||
|
|
|
|||
Loading…
Reference in New Issue