Skip to content

Commit 199630e

Browse files
Pratik AgrawalPratik Agrawal
authored andcommitted
added radio buttons for selection_mode
1 parent 99ed23a commit 199630e

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::messages::layout::utility_types::widget_prelude::*;
2+
use crate::messages::preferences::SelectionMode;
23
use crate::messages::prelude::*;
34

45
pub struct PreferencesDialogMessageData<'a> {
@@ -62,6 +63,42 @@ impl PreferencesDialogMessageHandler {
6263
.widget_holder(),
6364
];
6465

66+
let selection_mode_tooltip = "Choose the selection mode for objects in the editor";
67+
let selection_mode_checkboxes = vec![
68+
CheckboxInput::new(matches!(preferences.selection_mode, SelectionMode::Touched))
69+
.tooltip("Select objects that are touched by the selection area")
70+
.on_update(|_| {
71+
PreferencesMessage::SelectionMode {
72+
selection_mode: SelectionMode::Touched,
73+
}
74+
.into()
75+
})
76+
.widget_holder(),
77+
TextLabel::new("Touched").table_align(true).widget_holder(),
78+
Separator::new(SeparatorType::Unrelated).widget_holder(),
79+
CheckboxInput::new(matches!(preferences.selection_mode, SelectionMode::Contained))
80+
.tooltip("Select objects that are fully contained within the selection area")
81+
.on_update(|_| {
82+
PreferencesMessage::SelectionMode {
83+
selection_mode: SelectionMode::Contained,
84+
}
85+
.into()
86+
})
87+
.widget_holder(),
88+
TextLabel::new("Contained").table_align(true).widget_holder(),
89+
Separator::new(SeparatorType::Unrelated).widget_holder(),
90+
CheckboxInput::new(matches!(preferences.selection_mode, SelectionMode::ByDragDirection))
91+
.tooltip("Select objects based on the drag direction of the selection area")
92+
.on_update(|_| {
93+
PreferencesMessage::SelectionMode {
94+
selection_mode: SelectionMode::ByDragDirection,
95+
}
96+
.into()
97+
})
98+
.widget_holder(),
99+
TextLabel::new("By Drag Direction").table_align(true).widget_holder(),
100+
];
101+
65102
// TODO: Reenable when Imaginate is restored
66103
// let imaginate_server_hostname = vec![
67104
// TextLabel::new("Imaginate").min_width(60).italic(true).widget_holder(),
@@ -90,6 +127,10 @@ impl PreferencesDialogMessageHandler {
90127
LayoutGroup::Row { widgets: zoom_with_scroll },
91128
LayoutGroup::Row { widgets: renderer_section },
92129
LayoutGroup::Row { widgets: use_vello },
130+
LayoutGroup::Row {
131+
widgets: vec![TextLabel::new("Selection Mode").italic(true).widget_holder()],
132+
},
133+
LayoutGroup::Row { widgets: selection_mode_checkboxes },
93134
// LayoutGroup::Row { widgets: imaginate_server_hostname },
94135
// LayoutGroup::Row { widgets: imaginate_refresh_frequency },
95136
]))

editor/src/messages/preferences/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
mod preference_type;
12
mod preferences_message;
23
mod preferences_message_handler;
34

5+
#[doc(inline)]
6+
pub use preference_type::SelectionMode;
47
#[doc(inline)]
58
pub use preferences_message::{PreferencesMessage, PreferencesMessageDiscriminant};
69
#[doc(inline)]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::fmt;
2+
3+
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, specta::Type)]
4+
pub enum SelectionMode {
5+
Touched,
6+
Contained,
7+
ByDragDirection,
8+
}
9+
10+
impl fmt::Display for SelectionMode {
11+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12+
match self {
13+
SelectionMode::Touched => write!(f, "Touched"),
14+
SelectionMode::Contained => write!(f, "Contained"),
15+
SelectionMode::ByDragDirection => write!(f, "By Drag Direction"),
16+
}
17+
}
18+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
use crate::messages::preferences::SelectionMode;
12
use crate::messages::prelude::*;
2-
33
#[impl_message(Message, Preferences)]
44
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
55
pub enum PreferencesMessage {
66
Load { preferences: String },
77
ResetToDefaults,
8-
98
ImaginateRefreshFrequency { seconds: f64 },
109
UseVello { use_vello: bool },
10+
SelectionMode { selection_mode: SelectionMode },
1111
ImaginateServerHostname { hostname: String },
1212
ModifyLayout { zoom_with_scroll: bool },
1313
}

editor/src/messages/preferences/preferences_message_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::messages::input_mapper::key_mapping::MappingVariant;
2+
use crate::messages::preferences::SelectionMode;
23
use crate::messages::prelude::*;
34
use graph_craft::wasm_application_io::EditorPreferences;
45

@@ -8,6 +9,7 @@ pub struct PreferencesMessageHandler {
89
pub imaginate_refresh_frequency: f64,
910
pub zoom_with_scroll: bool,
1011
pub use_vello: bool,
12+
pub selection_mode: SelectionMode,
1113
}
1214

1315
impl PreferencesMessageHandler {
@@ -34,6 +36,7 @@ impl Default for PreferencesMessageHandler {
3436
imaginate_refresh_frequency: 1.,
3537
zoom_with_scroll: matches!(MappingVariant::default(), MappingVariant::ZoomWithScroll),
3638
use_vello,
39+
selection_mode: SelectionMode::Touched,
3740
}
3841
}
3942
}
@@ -98,6 +101,7 @@ impl MessageHandler<PreferencesMessage, ()> for PreferencesMessageHandler {
98101
responses.add(KeyMappingMessage::ModifyMapping(variant));
99102
responses.add(FrontendMessage::UpdateZoomWithScroll { zoom_with_scroll });
100103
}
104+
PreferencesMessage::SelectionMode { selection_mode } => todo!(),
101105
}
102106

103107
responses.add(FrontendMessage::TriggerSavePreferences { preferences: self.clone() });

0 commit comments

Comments
 (0)