Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ pub enum ShapeType {
Arc,
Spiral,
Grid,
Rectangle,
Ellipse,
Arrow,

// These have dedicated tools and don't appear in the Shape tool's dropdown
Line,
Rectangle,
Ellipse,
}

impl ShapeType {
Expand Down
5 changes: 3 additions & 2 deletions editor/src/messages/tool/tool_message_handler.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -75,9 +75,10 @@ impl MessageHandler<ToolMessage, ToolMessageContext<'_>> for ToolMessageHandler
if self.tool_state.tool_data.active_shape_type.is_some() {
self.tool_state.tool_data.active_shape_type = None;
self.tool_state.tool_data.active_tool_type = ToolType::Shape;
// Restore current_shape from the preserved dropdown selection (options.shape_type)
responses.add(ShapeToolMessage::RestoreShapeFromOptions);
}
responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Shape });
responses.add(ShapeToolMessage::SetShape { shape: ShapeType::Polygon });
responses.add(ShapeToolMessage::HideShapeTypeWidget { hide: false })
}
ToolMessage::ActivateToolBrush => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Brush }),
Expand Down
43 changes: 17 additions & 26 deletions editor/src/messages/tool/tool_messages/shape_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub enum ShapeToolMessage {
PointerOutsideViewport { modifier: ShapeToolModifierKey },
UpdateOptions { options: ShapeOptionsUpdate },
SetShape { shape: ShapeType },
// Restores current_shape from the dropdown selection (options.shape_type)
RestoreShapeFromOptions,

IncreaseSides,
DecreaseSides,
Expand Down Expand Up @@ -132,6 +134,7 @@ fn create_turns_widget(turns: f64) -> WidgetInstance {
}

fn create_shape_option_widget(shape_type: ShapeType) -> WidgetInstance {
// Line, Rectangle, and Ellipse have dedicated tools, so they're excluded from this dropdown
let entries = vec![vec![
MenuListEntry::new("Polygon").label("Polygon").on_commit(move |_| {
ShapeToolMessage::UpdateOptions {
Expand Down Expand Up @@ -169,32 +172,21 @@ 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()
// Line, Rectangle, Ellipse have dedicated tools (and larger enum index values), so shape_type as u32 works for the rest
let selected_index = if matches!(shape_type, ShapeType::Line | ShapeType::Rectangle | ShapeType::Ellipse) {
// Default to Polygon if somehow one of these become selected
Some(0)
} else {
Some(shape_type as u32)
};
DropdownInput::new(entries).selected_index(selected_index).widget_instance()
}

fn create_arc_type_widget(arc_type: ArcType) -> WidgetInstance {
Expand Down Expand Up @@ -1091,16 +1083,15 @@ impl Fsm for ShapeToolFsmState {
(_, ShapeToolMessage::SetShape { shape }) => {
responses.add(DocumentMessage::AbortTransaction);
tool_data.data.cleanup(responses);
// Only update current_shape for drawing, preserve options.shape_type (dropdown selection)
tool_data.current_shape = shape;
responses.add(ShapeToolMessage::UpdateOptions {
options: ShapeOptionsUpdate::ShapeType(shape),
});

responses.add(ShapeToolMessage::UpdateOptions {
options: ShapeOptionsUpdate::ShapeType(shape),
});
ShapeToolFsmState::Ready(shape)
}
(_, ShapeToolMessage::RestoreShapeFromOptions) => {
// Restore current_shape from the dropdown selection when returning from Line/Rectangle/Ellipse aliases
tool_data.current_shape = tool_options.shape_type;
ShapeToolFsmState::Ready(tool_options.shape_type)
}
(_, ShapeToolMessage::HideShapeTypeWidget { hide }) => {
tool_data.hide_shape_option_widget = hide;
responses.add(ToolMessage::RefreshToolOptions);
Expand Down
Loading