Skip to content

Commit 04d7adb

Browse files
mTvare6Keavon
andcommitted
Fix grid overlay values getting wiped when switching between isometric/rectangular and back (#2702)
* Retain values present in previous git overlay state * Code review --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent a1d8577 commit 04d7adb

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

editor/src/messages/portfolio/document/overlays/grid_overlays.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,24 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
236236
TextLabel::new("Type").table_align(true).widget_holder(),
237237
Separator::new(SeparatorType::Unrelated).widget_holder(),
238238
RadioInput::new(vec![
239-
RadioEntryData::new("rectangular")
240-
.label("Rectangular")
241-
.on_update(update_val(grid, |grid, _| grid.grid_type = GridType::RECTANGULAR)),
242-
RadioEntryData::new("isometric")
243-
.label("Isometric")
244-
.on_update(update_val(grid, |grid, _| grid.grid_type = GridType::ISOMETRIC)),
239+
RadioEntryData::new("rectangular").label("Rectangular").on_update(update_val(grid, |grid, _| {
240+
if let GridType::Isometric { y_axis_spacing, angle_a, angle_b } = grid.grid_type {
241+
grid.isometric_y_spacing = y_axis_spacing;
242+
grid.isometric_angle_a = angle_a;
243+
grid.isometric_angle_b = angle_b;
244+
}
245+
grid.grid_type = GridType::Rectangular { spacing: grid.rectangular_spacing };
246+
})),
247+
RadioEntryData::new("isometric").label("Isometric").on_update(update_val(grid, |grid, _| {
248+
if let GridType::Rectangular { spacing } = grid.grid_type {
249+
grid.rectangular_spacing = spacing;
250+
}
251+
grid.grid_type = GridType::Isometric {
252+
y_axis_spacing: grid.isometric_y_spacing,
253+
angle_a: grid.isometric_angle_a,
254+
angle_b: grid.isometric_angle_b,
255+
};
256+
})),
245257
])
246258
.min_width(200)
247259
.selected_index(Some(match grid.grid_type {

editor/src/messages/portfolio/document/utility_types/misc.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,11 @@ pub enum GridType {
176176

177177
impl Default for GridType {
178178
fn default() -> Self {
179-
Self::RECTANGULAR
179+
Self::Rectangular { spacing: DVec2::ONE }
180180
}
181181
}
182182

183183
impl GridType {
184-
pub const RECTANGULAR: Self = GridType::Rectangular { spacing: DVec2::ONE };
185-
pub const ISOMETRIC: Self = GridType::Isometric {
186-
y_axis_spacing: 1.,
187-
angle_a: 30.,
188-
angle_b: 30.,
189-
};
190184
pub fn rectangular_spacing(&mut self) -> Option<&mut DVec2> {
191185
match self {
192186
Self::Rectangular { spacing } => Some(spacing),
@@ -218,6 +212,10 @@ impl GridType {
218212
pub struct GridSnapping {
219213
pub origin: DVec2,
220214
pub grid_type: GridType,
215+
pub rectangular_spacing: DVec2,
216+
pub isometric_y_spacing: f64,
217+
pub isometric_angle_a: f64,
218+
pub isometric_angle_b: f64,
221219
pub grid_color: Color,
222220
pub dot_display: bool,
223221
}
@@ -227,6 +225,10 @@ impl Default for GridSnapping {
227225
Self {
228226
origin: DVec2::ZERO,
229227
grid_type: Default::default(),
228+
rectangular_spacing: DVec2::ONE,
229+
isometric_y_spacing: 1.,
230+
isometric_angle_a: 30.,
231+
isometric_angle_b: 30.,
230232
grid_color: Color::from_rgb_str(COLOR_OVERLAY_GRAY.strip_prefix('#').unwrap()).unwrap(),
231233
dot_display: false,
232234
}

0 commit comments

Comments
 (0)