Add a 'Preserve Aspect Ratio' checkbox to Properties panel (#923)

* Add the link button

* Transform around pivot

* Remove log

* Fix tests

* Add a hacky two-line layout for the checkbox

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-12-28 15:21:03 -08:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent df74f6f562
commit 904f38fa1b
8 changed files with 85 additions and 9 deletions
+6
View File
@@ -628,6 +628,12 @@ impl Document {
}
Some(vec![LayerChanged { path: layer_path.clone() }])
}
Operation::SetLayerPreserveAspect { layer_path, preserve_aspect } => {
if let Ok(layer) = self.layer_mut(&layer_path) {
layer.preserve_aspect = preserve_aspect;
}
Some(vec![LayerChanged { path: layer_path.clone() }])
}
Operation::SetTextEditability { path, editable } => {
self.layer_mut(&path)?.as_text_mut()?.editable = editable;
self.mark_as_dirty(&path)?;
+5
View File
@@ -227,6 +227,9 @@ pub struct Layer {
/// A transformation applied to the layer (translation, rotation, scaling, and shear).
#[serde(with = "DAffine2Ref")]
pub transform: glam::DAffine2,
/// Should the aspect ratio of this layer be preserved?
#[serde(default = "return_true")]
pub preserve_aspect: bool,
/// The center of transformations like rotation or scaling with the shift key.
/// This is in local space (so the layer's transform should be applied).
pub pivot: DVec2,
@@ -255,6 +258,7 @@ impl Layer {
name: None,
data,
transform: glam::DAffine2::from_cols_array(&transform),
preserve_aspect: true,
pivot: DVec2::splat(0.5),
cache: String::new(),
thumbnail_cache: String::new(),
@@ -515,6 +519,7 @@ impl Clone for Layer {
name: self.name.clone(),
data: self.data.clone(),
transform: self.transform,
preserve_aspect: self.preserve_aspect,
pivot: self.pivot,
cache: String::new(),
thumbnail_cache: String::new(),
+4
View File
@@ -245,6 +245,10 @@ pub enum Operation {
path: Vec<LayerId>,
name: String,
},
SetLayerPreserveAspect {
layer_path: Vec<LayerId>,
preserve_aspect: bool,
},
SetLayerBlendMode {
path: Vec<LayerId>,
blend_mode: BlendMode,