Various small fixes and cleanups (#299)

This commit is contained in:
TrueDoctor 2021-07-24 17:59:01 +02:00 committed by Keavon Chambers
parent dca84742ca
commit 6a5d3cc48c
4 changed files with 8 additions and 18 deletions

View File

@ -233,7 +233,7 @@ pub fn set_blend_mode_for_selected_layers(blend_mode_svg_style_name: String) ->
"saturation" => BlendMode::Saturation,
"color" => BlendMode::Color,
"luminosity" => BlendMode::Luminosity,
_ => return Err(convert_error(EditorError::Misc("UnknownBlendMode".to_string())).into()),
_ => return Err(convert_error(EditorError::Misc("UnknownBlendMode".to_string()))),
};
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SetBlendModeForSelectedLayers(blend_mode)).map_err(convert_error))

View File

@ -16,7 +16,7 @@ impl fmt::Display for DocumentResponse {
let name = match self {
DocumentResponse::DocumentChanged { .. } => "DocumentChanged",
DocumentResponse::FolderChanged { .. } => "FolderChanged",
DocumentResponse::CreatedLayer { .. } => "SelectLayer",
DocumentResponse::CreatedLayer { .. } => "CreatedLayer",
DocumentResponse::DeletedLayer { .. } => "DeleteLayer",
};

View File

@ -39,7 +39,7 @@ fn layer_data<'a>(layer_data: &'a mut HashMap<Vec<LayerId>, LayerData>, path: &[
}
pub fn layer_panel_entry(layer_data: &mut LayerData, layer: &mut Layer, path: Vec<LayerId>) -> LayerPanelEntry {
let blend_mode = layer.blend_mode.clone();
let blend_mode = layer.blend_mode;
let layer_type: LayerType = (&layer.data).into();
let name = layer.name.clone().unwrap_or_else(|| format!("Unnamed {}", layer_type));
let arr = layer.current_bounding_box().unwrap_or([DVec2::ZERO, DVec2::ZERO]);

View File

@ -118,17 +118,6 @@ impl DocumentMessageHandler {
fn layerdata_mut(&mut self, path: &[LayerId]) -> &mut LayerData {
self.active_document_mut().layer_data.entry(path.to_vec()).or_insert_with(|| LayerData::new(true))
}
#[allow(dead_code)]
fn create_transform_from_layerdata(&self, path: Vec<u64>, responses: &mut VecDeque<Message>) {
let layerdata = self.layerdata(&path);
responses.push_back(
DocumentOperation::SetLayerTransform {
path,
transform: layerdata.calculate_transform().to_cols_array(),
}
.into(),
);
}
fn create_document_transform_from_layerdata(&self, viewport_size: &ViewportPosition, responses: &mut VecDeque<Message>) {
let half_viewport = viewport_size.as_dvec2() / 2.;
let layerdata = self.layerdata(&[]);
@ -142,10 +131,10 @@ impl DocumentMessageHandler {
);
}
/// Returns the paths to all layers in order, optionally including only selected layers
/// Returns the paths to all layers in order, optionally including only selected or non
/// selected layers.
fn layers_sorted(&self, selected: Option<bool>) -> Vec<Vec<LayerId>> {
// Compute the indices for each layer to be able to sort them
// TODO: Replace with drain_filter https://github.com/rust-lang/rust/issues/59618
let mut layers_with_indices: Vec<(Vec<LayerId>, Vec<usize>)> = self
.active_document()
.layer_data
@ -153,7 +142,7 @@ impl DocumentMessageHandler {
// 'path.len() > 0' filters out root layer since it has no indices
.filter_map(|(path, data)| (!path.is_empty() && (data.selected == selected.unwrap_or(data.selected))).then(|| path.clone()))
.filter_map(|path| {
// Currently it is possible that layer_data contains layers that are don't actually exist
// Currently it is possible that layer_data contains layers that are don't actually exist (has been partially fixed in #281)
// and thus indices_for_path can return an error. We currently skip these layers and log a warning.
// Once this problem is solved this code can be simplified
match self.active_document().document.indices_for_path(&path) {
@ -180,7 +169,8 @@ impl DocumentMessageHandler {
self.layers_sorted(Some(true))
}
/// Returns the paths to all selected layers in order
/// Returns the paths to all non_selected layers in order
#[allow(dead_code)] // used for test cases
pub fn non_selected_layers_sorted(&self) -> Vec<Vec<LayerId>> {
self.layers_sorted(Some(false))
}