Skip to content

Commit

Permalink
disable "Colinear Handles" checkbox when only endpoint or its handle …
Browse files Browse the repository at this point in the history
…is selected
  • Loading branch information
indierusty authored and Keavon committed Mar 6, 2025
1 parent 0c1e96b commit 081635a
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions editor/src/messages/tool/tool_messages/path_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl LayoutHolder for PathTool {
// TODO: Remove `unwrap_or_default` once checkboxes are capable of displaying a mixed state
.unwrap_or_default();
let colinear_handle_checkbox = CheckboxInput::new(colinear_handles_state)
.disabled(self.tool_data.selection_status.is_none())
.disabled(!self.tool_data.can_toggle_colinearity)
.on_update(|&CheckboxInput { checked, .. }| {
if checked {
PathToolMessage::ManipulatorMakeHandlesColinear.into()
Expand All @@ -186,7 +186,7 @@ impl LayoutHolder for PathTool {
.tooltip(colinear_handles_tooltip)
.widget_holder();
let colinear_handles_label = TextLabel::new("Colinear Handles")
.disabled(self.tool_data.selection_status.is_none())
.disabled(!self.tool_data.can_toggle_colinearity)
.tooltip(colinear_handles_tooltip)
.widget_holder();

Expand Down Expand Up @@ -359,7 +359,10 @@ struct PathToolData {
opposing_handle_lengths: Option<OpposingHandleLengths>,
/// Describes information about the selected point(s), if any, across one or multiple shapes and manipulator point types (anchor or handle).
/// The available information varies depending on whether `None`, `One`, or `Multiple` points are currently selected.
/// NOTE: It must be updated using `update_selection_status` to ensure `can_toggle_colinearity` stays synchronized with the current selection.
selection_status: SelectionStatus,
/// `true` if we can change the current selection to colinear or not.
can_toggle_colinearity: bool,
segment: Option<ClosestSegment>,
snap_cache: SnapCache,
double_click_handled: bool,
Expand Down Expand Up @@ -415,6 +418,24 @@ impl PathToolData {
}
}

fn update_selection_status(&mut self, shape_editor: &mut ShapeState, document: &DocumentMessageHandler) {
let selection_status = get_selection_status(&document.network_interface, shape_editor);

self.can_toggle_colinearity = match &selection_status {
SelectionStatus::None => false,
SelectionStatus::One(single_selected_point) => {
let vector_data = document.network_interface.compute_modified_vector(single_selected_point.layer).unwrap();
if single_selected_point.id.get_handle_pair(&vector_data).is_some() {
true
} else {
false
}
}
SelectionStatus::Multiple(_) => true,
};
self.selection_status = selection_status;
}

fn start_insertion(&mut self, responses: &mut VecDeque<Message>, segment: ClosestSegment) -> PathToolFsmState {
if self.segment.is_some() {
warn!("Segment was `Some(..)` before `start_insertion`")
Expand Down Expand Up @@ -1302,7 +1323,7 @@ impl Fsm for PathToolFsmState {
point_select_state: shape_editor.get_dragging_state(&document.network_interface),
colinear,
};
tool_data.selection_status = get_selection_status(&document.network_interface, shape_editor);
tool_data.update_selection_status(shape_editor, document);
self
}
(_, PathToolMessage::ManipulatorMakeHandlesColinear) => {
Expand Down

0 comments on commit 081635a

Please sign in to comment.