Fix hiding and collapsing layers (#1481)

* Hide and collapse layers

* Reorder imports

* Fix Ctrl+H shortcut advertized action and hotkey tooltip; improve graph top right of options bar

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2023-11-27 02:27:11 +00:00
committed by GitHub
co-authored by Keavon Chambers
parent 6d9dd5fc27
commit 5ee79031ab
22 changed files with 164 additions and 123 deletions
@@ -83,7 +83,7 @@ impl PathOutline {
/// Performs an intersect test and generates a hovered overlay if necessary
pub fn intersect_test_hovered(&mut self, input: &InputPreprocessorMessageHandler, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) {
// Get the layer the user is hovering over
let intersection = document.metadata().click(input.mouse.position, &document.document_legacy.document_network);
let intersection = document.document_legacy.click(input.mouse.position, &document.document_legacy.document_network);
let Some(hovered_layer) = intersection else {
self.clear_hovered(responses);
@@ -52,7 +52,7 @@ impl Pivot {
/// Recomputes the pivot position and transform.
fn recalculate_pivot(&mut self, document: &DocumentMessageHandler) {
let mut layers = document.metadata().selected_visible_layers();
let mut layers = document.document_legacy.selected_visible_layers();
let Some(first) = layers.next() else {
// If no layers are selected then we revert things back to default
self.normalized_pivot = DVec2::splat(0.5);
@@ -73,7 +73,7 @@ impl Pivot {
} else {
// If more than one layer is selected we use the AABB with the mean of the pivots
let xy_summation = document
.metadata()
.document_legacy
.selected_visible_layers()
.filter_map(|layer| graph_modification_utils::get_viewport_pivot(layer, &document.document_legacy))
.reduce(|a, b| a + b)
@@ -81,7 +81,7 @@ impl Pivot {
let pivot = xy_summation / selected_layers_count as f64;
self.pivot = Some(pivot);
let [min, max] = document.metadata().selected_visible_layers_bounding_box_viewport().unwrap_or([DVec2::ZERO, DVec2::ONE]);
let [min, max] = document.document_legacy.selected_visible_layers_bounding_box_viewport().unwrap_or([DVec2::ZERO, DVec2::ONE]);
self.normalized_pivot = (pivot - min) / (max - min);
self.transform_from_normalized = DAffine2::from_translation(min) * DAffine2::from_scale(max - min);
@@ -157,7 +157,7 @@ impl Pivot {
/// Sets the viewport position of the pivot for all selected layers.
pub fn set_viewport_position(&self, position: DVec2, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) {
for layer in document.metadata().selected_visible_layers() {
for layer in document.document_legacy.selected_visible_layers() {
let transform = Self::get_layer_pivot_transform(layer, document);
let pivot = transform.inverse().transform_point2(position);
// Only update the pivot when computed position is finite. Infinite can happen when scale is 0.
@@ -150,11 +150,7 @@ impl ArtboardToolData {
fn select_artboard(&mut self, document: &DocumentMessageHandler, render_data: &RenderData, input: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) -> bool {
responses.add(DocumentMessage::StartTransaction);
let mut intersections = document
.document_legacy
.metadata
.click_xray(input.mouse.position)
.filter(|&layer| is_artboard(layer, &document.document_legacy));
let mut intersections = document.document_legacy.click_xray(input.mouse.position).filter(|&layer| is_artboard(layer, &document.document_legacy));
responses.add(BroadcastEvent::DocumentIsDirty);
if let Some(intersection) = intersections.next() {
@@ -68,7 +68,7 @@ impl Fsm for FillToolFsmState {
let ToolMessage::Fill(event) = event else {
return self;
};
let Some(layer_identifier) = document.metadata().click(input.mouse.position, &document.document_legacy.document_network) else {
let Some(layer_identifier) = document.document_legacy.click(input.mouse.position, &document.document_legacy.document_network) else {
return self;
};
let layer = layer_identifier.to_path();
@@ -391,7 +391,7 @@ impl Fsm for GradientToolFsmState {
SelectedGradient::update(&mut tool_data.selected_gradient, document, responses);
}
for layer in document.metadata().selected_visible_layers() {
for layer in document.document_legacy.selected_visible_layers() {
if let Some(gradient) = get_gradient(layer, &document.document_legacy) {
let dragging = tool_data
.selected_gradient
@@ -526,7 +526,7 @@ impl Fsm for GradientToolFsmState {
document.backup_nonmut(responses);
GradientToolFsmState::Drawing
} else {
let selected_layer = document.metadata().click(input.mouse.position, &document.document_legacy.document_network);
let selected_layer = document.document_legacy.click(input.mouse.position, &document.document_legacy.document_network);
// Apply the gradient to the selected layer
if let Some(layer) = selected_layer {
@@ -119,7 +119,7 @@ impl Fsm for ImaginateToolFsmState {
match (self, event) {
(_, ImaginateToolMessage::DocumentIsDirty | ImaginateToolMessage::SelectionChanged) => {
tool_data.path_outlines.clear_selected(responses);
//tool_data.path_outlines.update_selected(document.selected_visible_layers(), document, responses, render_data);
//tool_data.path_outlines.update_selected(document.document_legacy.selected_visible_layers(), document, responses, render_data);
self
}
@@ -246,7 +246,7 @@ impl PathToolData {
PathToolFsmState::Dragging
}
// We didn't find a point nearby, so consider selecting the nearest shape instead
else if let Some(layer) = document.metadata().click(input.mouse.position, &document.document_legacy.document_network) {
else if let Some(layer) = document.document_legacy.click(input.mouse.position, &document.document_legacy.document_network) {
if shift {
responses.add(NodeGraphMessage::SelectedNodesAdd { nodes: vec![layer.to_node()] });
} else {
@@ -393,10 +393,10 @@ impl Fsm for SelectToolFsmState {
tool_data.selected_layers_changed = selected_layers_count != tool_data.selected_layers_count;
tool_data.selected_layers_count = selected_layers_count;
tool_data.path_outlines.update_selected(document.metadata().selected_layers(), document, responses);
tool_data.path_outlines.update_selected(document.document_legacy.selected_visible_layers(), document, responses);
tool_data.path_outlines.intersect_test_hovered(input, document, responses);
match (document.metadata().selected_visible_layers_bounding_box_viewport(), tool_data.bounding_box_overlays.take()) {
match (document.document_legacy.selected_visible_layers_bounding_box_viewport(), tool_data.bounding_box_overlays.take()) {
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
(Some(bounds), paths) => {
let mut bounding_box_overlays = paths.unwrap_or_else(|| BoundingBoxOverlays::new(responses));
@@ -417,7 +417,7 @@ impl Fsm for SelectToolFsmState {
}
(_, SelectToolMessage::EditLayer) => {
// Edit the clicked layer
if let Some(intersect) = document.metadata().click(input.mouse.position, &document.document_legacy.document_network) {
if let Some(intersect) = document.document_legacy.click(input.mouse.position, &document.document_legacy.document_network) {
match tool_data.nested_selection_behavior {
NestedSelectionBehavior::Shallowest => edit_layer_shallowest_manipulation(document, intersect, responses),
NestedSelectionBehavior::Deepest => edit_layer_deepest_manipulation(intersect, &document.document_legacy, responses),
@@ -450,8 +450,8 @@ impl Fsm for SelectToolFsmState {
.map(|bounding_box| bounding_box.check_rotate(input.mouse.position))
.unwrap_or_default();
let mut selected: Vec<_> = document.metadata().selected_visible_layers().collect();
let intersection = document.metadata().click(input.mouse.position, &document.document_legacy.document_network);
let mut selected: Vec<_> = document.document_legacy.selected_visible_layers().collect();
let intersection = document.document_legacy.click(input.mouse.position, &document.document_legacy.document_network);
// If the user is dragging the bounding box bounds, go into ResizingBounds mode.
// If the user is dragging the rotate trigger, go into RotatingBounds mode.
@@ -706,7 +706,7 @@ impl Fsm for SelectToolFsmState {
// Deselect layer if not snap dragging
if !tool_data.has_dragged && input.keyboard.key(remove_from_selection) && tool_data.layer_selected_on_start.is_none() {
let quad = tool_data.selection_quad();
let intersection = document.metadata().intersect_quad(quad, &document.document_legacy.document_network);
let intersection = document.document_legacy.intersect_quad(quad, &document.document_legacy.document_network);
if let Some(path) = intersection.last() {
let replacement_selected_layers: Vec<_> = document.metadata().selected_layers().filter(|&layer| !path.starts_with(layer, document.metadata())).collect();
@@ -777,7 +777,7 @@ impl Fsm for SelectToolFsmState {
(SelectToolFsmState::DrawingBox, SelectToolMessage::DragStop { .. } | SelectToolMessage::Enter) => {
let quad = tool_data.selection_quad();
// For shallow select we don't update dragging layers until inside drag_start_shallowest_manipulation()
tool_data.layers_dragging = document.metadata().intersect_quad(quad, &document.document_legacy.document_network).collect();
tool_data.layers_dragging = document.document_legacy.intersect_quad(quad, &document.document_legacy.document_network).collect();
responses.add_front(NodeGraphMessage::SelectedNodesSet {
nodes: tool_data.layers_dragging.iter().map(|layer| layer.to_node()).collect(),
});
@@ -274,7 +274,11 @@ impl TextToolData {
fn interact(&mut self, state: TextToolFsmState, mouse: DVec2, document: &DocumentMessageHandler, render_data: &RenderData, responses: &mut VecDeque<Message>) -> TextToolFsmState {
// Check if the user has selected an existing text layer
if let Some(clicked_text_layer_path) = document.metadata().click(mouse, document.network()).filter(|&layer| is_text_layer(layer, &document.document_legacy)) {
if let Some(clicked_text_layer_path) = document
.document_legacy
.click(mouse, document.network())
.filter(|&layer| is_text_layer(layer, &document.document_legacy))
{
self.start_editing_layer(clicked_text_layer_path, state, document, render_data, responses);
TextToolFsmState::Editing