Skip to content

Commit

Permalink
Various small fixes and cleanups (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Jul 24, 2021
1 parent 8d444f4 commit e78d598
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion client/web/wasm/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion core/document/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand Down
2 changes: 1 addition & 1 deletion core/editor/src/document/document_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
20 changes: 5 additions & 15 deletions core/editor/src/document/document_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&[]);
Expand All @@ -142,18 +131,18 @@ 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
.iter()
// '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) {
Expand All @@ -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))
}
Expand Down

0 comments on commit e78d598

Please sign in to comment.