Skip to content

Commit f98b9ce

Browse files
Pratik AgrawalPratik Agrawal
authored andcommitted
State management bug
1 parent d91da7f commit f98b9ce

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ impl PreferencesDialogMessageHandler {
9595
.into()
9696
}),
9797
])
98-
.selected_index(Some(
99-
(preferences.selection_mode == SelectionMode::ByDragDirection) as u32, // Accessing selection_mode correctly
100-
))
98+
.selected_index(Some(match preferences.selection_mode {
99+
SelectionMode::Touched => 0,
100+
SelectionMode::Contained => 1,
101+
SelectionMode::ByDragDirection => 2,
102+
}))
101103
.widget_holder();
102104

103105
// TODO: Reenable when Imaginate is restored

editor/src/messages/preferences/preference_type.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ impl fmt::Display for SelectionMode {
1616
}
1717
}
1818
}
19+
20+
impl Default for SelectionMode {
21+
fn default() -> Self {
22+
SelectionMode::Touched
23+
}
24+
}

editor/src/messages/preferences/preferences_message_handler.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use crate::messages::input_mapper::key_mapping::MappingVariant;
2+
use crate::messages::portfolio::document::DocumentMessageHandler;
23
use crate::messages::preferences::SelectionMode;
34
use crate::messages::prelude::*;
5+
use crate::messages::tool::tool_messages::select_tool::SelectTool;
6+
use crate::messages::tool::ToolMessageData;
7+
use graph_craft::document;
48
use graph_craft::wasm_application_io::EditorPreferences;
59

610
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, specta::Type)]
@@ -102,7 +106,7 @@ impl MessageHandler<PreferencesMessage, ()> for PreferencesMessageHandler {
102106
responses.add(FrontendMessage::UpdateZoomWithScroll { zoom_with_scroll });
103107
}
104108
PreferencesMessage::SelectionMode { selection_mode } => {
105-
log::info!("Setting selection mode: {:?}", selection_mode);
109+
info!("Setting selection mode to: {:?}", selection_mode);
106110
self.selection_mode = selection_mode;
107111
}
108112
}

editor/src/messages/tool/tool_messages/select_tool.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::messages::portfolio::document::utility_types::document_metadata::{sel
1010
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis};
1111
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, NodeNetworkInterface, NodeTemplate};
1212
use crate::messages::portfolio::document::utility_types::transformation::Selected;
13+
use crate::messages::preferences::PreferencesMessageHandler;
14+
use crate::messages::preferences::SelectionMode;
1315
use crate::messages::tool::common_functionality::graph_modification_utils::is_layer_fed_by_node_of_name;
1416
use crate::messages::tool::common_functionality::pivot::Pivot;
1517
use crate::messages::tool::common_functionality::snapping::{self, SnapCandidatePoint, SnapData, SnapManager};
@@ -77,7 +79,6 @@ pub enum SelectToolMessage {
7779
// Standard messages
7880
Abort,
7981
Overlays(OverlayContext),
80-
8182
// Tool-specific messages
8283
DragStart { extend_selection: Key, select_deepest: Key },
8384
DragStop { remove_from_selection: Key },
@@ -87,6 +88,7 @@ pub enum SelectToolMessage {
8788
PointerOutsideViewport(SelectToolPointerKeys),
8889
SelectOptions(SelectOptionsUpdate),
8990
SetPivot { position: PivotPosition },
91+
UpdateSelectionMode { selection_mode: SelectionMode },
9092
}
9193

9294
impl ToolMetadata for SelectTool {
@@ -263,6 +265,7 @@ enum SelectToolFsmState {
263265
RotatingBounds,
264266
DraggingPivot,
265267
}
268+
266269
impl Default for SelectToolFsmState {
267270
fn default() -> Self {
268271
let selection = NestedSelectionBehavior::Deepest;
@@ -288,6 +291,7 @@ struct SelectToolData {
288291
selected_layers_changed: bool,
289292
snap_candidates: Vec<SnapCandidatePoint>,
290293
auto_panning: AutoPanning,
294+
selection_mode: SelectionMode,
291295
}
292296

293297
impl SelectToolData {
@@ -304,12 +308,12 @@ impl SelectToolData {
304308
}
305309
}
306310

307-
fn selection_quad(&self) -> Quad {
311+
pub fn selection_quad(&self) -> Quad {
308312
let bbox = self.selection_box();
309313
Quad::from_box(bbox)
310314
}
311315

312-
fn calculate_direction(&self) -> SelectionDirection {
316+
pub fn calculate_direction(&self) -> SelectionDirection {
313317
let bbox: [DVec2; 2] = self.selection_box();
314318
if bbox[1].x > bbox[0].x {
315319
SelectionDirection::Rightwards
@@ -320,7 +324,7 @@ impl SelectToolData {
320324
}
321325
}
322326

323-
fn selection_box(&self) -> [DVec2; 2] {
327+
pub fn selection_box(&self) -> [DVec2; 2] {
324328
if self.drag_current == self.drag_start {
325329
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
326330
[self.drag_start - tolerance, self.drag_start + tolerance]
@@ -1025,14 +1029,23 @@ impl Fsm for SelectToolFsmState {
10251029
SelectToolFsmState::Ready { selection }
10261030
}
10271031
(SelectToolFsmState::DrawingBox { .. }, SelectToolMessage::DragStop { .. } | SelectToolMessage::Enter) => {
1032+
let mut preferences_handler = PreferencesMessageHandler::default();
1033+
tool_data.selection_mode = preferences_handler.selection_mode.clone();
1034+
info!("Setting selection mode to: {:?}", tool_data.selection_mode);
10281035
let quad = tool_data.selection_quad();
10291036
let direction = tool_data.calculate_direction();
1037+
info!("Using SelectionMode: {:?}", tool_data.selection_mode);
10301038
// let new_selected: HashSet<_> = document.intersect_quad_no_artboards(quad, input).collect();
1031-
let new_selected: HashSet<_> = match direction {
1032-
SelectionDirection::Rightwards => document.intersect_quad_no_artboards(quad, input).filter(|layer| document.is_layer_fully_inside(layer, quad)).collect(),
1033-
SelectionDirection::Leftwards => document.intersect_quad_no_artboards(quad, input).collect(),
1034-
SelectionDirection::None => HashSet::new(),
1039+
let new_selected: HashSet<_> = match tool_data.selection_mode {
1040+
SelectionMode::Touched => document.intersect_quad_no_artboards(quad, input).collect(),
1041+
SelectionMode::Contained => document.intersect_quad_no_artboards(quad, input).filter(|layer| document.is_layer_fully_inside(layer, quad)).collect(),
1042+
SelectionMode::ByDragDirection => match direction {
1043+
SelectionDirection::Rightwards => document.intersect_quad_no_artboards(quad, input).filter(|layer| document.is_layer_fully_inside(layer, quad)).collect(),
1044+
SelectionDirection::Leftwards => document.intersect_quad_no_artboards(quad, input).collect(),
1045+
SelectionDirection::None => HashSet::new(),
1046+
},
10351047
};
1048+
10361049
let current_selected: HashSet<_> = document.network_interface.selected_nodes(&[]).unwrap().selected_layers(document.metadata()).collect();
10371050
if new_selected != current_selected {
10381051
tool_data.layers_dragging = new_selected.into_iter().collect();

0 commit comments

Comments
 (0)