mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-08 00:05:00 +00:00
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 <keavon@keavon.com>
This commit is contained in:
parent
a1d85779ba
commit
04d7adb867
2 changed files with 27 additions and 13 deletions
|
@ -236,12 +236,24 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
|
||||||
TextLabel::new("Type").table_align(true).widget_holder(),
|
TextLabel::new("Type").table_align(true).widget_holder(),
|
||||||
Separator::new(SeparatorType::Unrelated).widget_holder(),
|
Separator::new(SeparatorType::Unrelated).widget_holder(),
|
||||||
RadioInput::new(vec![
|
RadioInput::new(vec![
|
||||||
RadioEntryData::new("rectangular")
|
RadioEntryData::new("rectangular").label("Rectangular").on_update(update_val(grid, |grid, _| {
|
||||||
.label("Rectangular")
|
if let GridType::Isometric { y_axis_spacing, angle_a, angle_b } = grid.grid_type {
|
||||||
.on_update(update_val(grid, |grid, _| grid.grid_type = GridType::RECTANGULAR)),
|
grid.isometric_y_spacing = y_axis_spacing;
|
||||||
RadioEntryData::new("isometric")
|
grid.isometric_angle_a = angle_a;
|
||||||
.label("Isometric")
|
grid.isometric_angle_b = angle_b;
|
||||||
.on_update(update_val(grid, |grid, _| grid.grid_type = GridType::ISOMETRIC)),
|
}
|
||||||
|
grid.grid_type = GridType::Rectangular { spacing: grid.rectangular_spacing };
|
||||||
|
})),
|
||||||
|
RadioEntryData::new("isometric").label("Isometric").on_update(update_val(grid, |grid, _| {
|
||||||
|
if let GridType::Rectangular { spacing } = grid.grid_type {
|
||||||
|
grid.rectangular_spacing = spacing;
|
||||||
|
}
|
||||||
|
grid.grid_type = GridType::Isometric {
|
||||||
|
y_axis_spacing: grid.isometric_y_spacing,
|
||||||
|
angle_a: grid.isometric_angle_a,
|
||||||
|
angle_b: grid.isometric_angle_b,
|
||||||
|
};
|
||||||
|
})),
|
||||||
])
|
])
|
||||||
.min_width(200)
|
.min_width(200)
|
||||||
.selected_index(Some(match grid.grid_type {
|
.selected_index(Some(match grid.grid_type {
|
||||||
|
|
|
@ -176,17 +176,11 @@ pub enum GridType {
|
||||||
|
|
||||||
impl Default for GridType {
|
impl Default for GridType {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::RECTANGULAR
|
Self::Rectangular { spacing: DVec2::ONE }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridType {
|
impl GridType {
|
||||||
pub const RECTANGULAR: Self = GridType::Rectangular { spacing: DVec2::ONE };
|
|
||||||
pub const ISOMETRIC: Self = GridType::Isometric {
|
|
||||||
y_axis_spacing: 1.,
|
|
||||||
angle_a: 30.,
|
|
||||||
angle_b: 30.,
|
|
||||||
};
|
|
||||||
pub fn rectangular_spacing(&mut self) -> Option<&mut DVec2> {
|
pub fn rectangular_spacing(&mut self) -> Option<&mut DVec2> {
|
||||||
match self {
|
match self {
|
||||||
Self::Rectangular { spacing } => Some(spacing),
|
Self::Rectangular { spacing } => Some(spacing),
|
||||||
|
@ -218,6 +212,10 @@ impl GridType {
|
||||||
pub struct GridSnapping {
|
pub struct GridSnapping {
|
||||||
pub origin: DVec2,
|
pub origin: DVec2,
|
||||||
pub grid_type: GridType,
|
pub grid_type: GridType,
|
||||||
|
pub rectangular_spacing: DVec2,
|
||||||
|
pub isometric_y_spacing: f64,
|
||||||
|
pub isometric_angle_a: f64,
|
||||||
|
pub isometric_angle_b: f64,
|
||||||
pub grid_color: Color,
|
pub grid_color: Color,
|
||||||
pub dot_display: bool,
|
pub dot_display: bool,
|
||||||
}
|
}
|
||||||
|
@ -227,6 +225,10 @@ impl Default for GridSnapping {
|
||||||
Self {
|
Self {
|
||||||
origin: DVec2::ZERO,
|
origin: DVec2::ZERO,
|
||||||
grid_type: Default::default(),
|
grid_type: Default::default(),
|
||||||
|
rectangular_spacing: DVec2::ONE,
|
||||||
|
isometric_y_spacing: 1.,
|
||||||
|
isometric_angle_a: 30.,
|
||||||
|
isometric_angle_b: 30.,
|
||||||
grid_color: Color::from_rgb_str(COLOR_OVERLAY_GRAY.strip_prefix('#').unwrap()).unwrap(),
|
grid_color: Color::from_rgb_str(COLOR_OVERLAY_GRAY.strip_prefix('#').unwrap()).unwrap(),
|
||||||
dot_display: false,
|
dot_display: false,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue