Repository: GraphiteEditor/Graphite
File: editor/src/messages/tool/tool_messages/select_tool.rs (Rust)

Code before:
				}

				if let Self::Dragging { .. } = self {
					let quad = Quad::from_box([tool_data.drag_start, tool_data.drag_current]);
					let document_start = document.metadata().document_to_viewport.inverse().transform_point2(quad.top_left());
					let document_current = document.metadata().document_to_viewport.inverse().transform_point2(quad.bottom_right());

					if document_current.x != document_start.x {
						overlay_context.dashed_line(quad.top_left(), quad.top_right(), None, None, Some(2.), Some(2.), Some(0.5));

						let width = format!("{:.2}", document_current.x - document_start.x).trim_end_matches('0').trim_end_matches('.').to_string();
						let x_transform = DAffine2::from_translation((quad.top_left() + quad.top_right()) / 2.);
						overlay_context.text(&width, COLOR_OVERLAY_BLUE, None, x_transform, 4., [OverlayPivot::Middle, OverlayPivot::End]);
					}
					if document_current.y != document_start.y {
						overlay_context.dashed_line(quad.top_left(), quad.bottom_left(), None, None, Some(2.), Some(2.), Some(0.5));

						let height = format!("{:.2}", document_current.y - document_start.y).trim_end_matches('0').trim_end_matches('.').to_string();
						let y_transform = DAffine2::from_translation((quad.top_left() + quad.bottom_left()) / 2.);
						let height_pivot = if document_current.x >= document_start.x { OverlayPivot::Start } else { OverlayPivot::End };
						overlay_context.text(&height, COLOR_OVERLAY_BLUE, None, y_transform, 3., [height_pivot, OverlayPivot::Middle]);
					}
					if !tool_data.axis_align && document_start.x != document_current.x && document_start.y != document_current.y {
						overlay_context.line(quad.top_right(), quad.bottom_right(), None, None);
						overlay_context.line(quad.bottom_left(), quad.bottom_right(), None, None);
					}
				}

				self
			}
			(_, SelectToolMessage::EditLayer) => {
				// Edit the clicked layer
				if let Some(intersect) = document.click(input) {
					match tool_data.nested_selection_behavior {
						NestedSelectionBehavior::Shallowest => edit_layer_shallowest_manipulation(document, intersect, responses),
						NestedSelectionBehavior::Deepest => edit_layer_deepest_manipulation(intersect, &document.network_interface, responses),
					}
				}

				self
			}
			(
				SelectToolFsmState::Ready { .. },
				SelectToolMessage::DragStart {
					extend_selection,
					remove_from_selection,
					select_deepest,
					lasso_select,
					..
				},
			) => {

Review comment (suggestion):
This overlay code is basically the same as for the <kbd>G</kbd> translation. Please consolidate this into a function inside overlay_context to reduce code duplication.
https://github.com/GraphiteEditor/Graphite/blob/49db963ce1067bc40af822e6e46d8777a4db7281/editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs#L262-L284

Code after:
				let has_layers = document.network_interface.selected_nodes().has_selected_nodes();
				let draw_pivot = tool_data.pivot_gizmo.state.is_pivot() && overlay_context.visibility_settings.pivot() && has_layers;
				tool_data.pivot_gizmo.pivot.recalculate_pivot(document);
				let pivot = draw_pivot.then_some(tool_data.pivot_gizmo.pivot.pivot).flatten();
				if let Some(pivot) = pivot {
					let offset = tool_data
						.pivot_gizmo_start
						.map(|offset| tool_data.pivot_gizmo.pivot_disconnected().then_some(tool_data.drag_current - offset).unwrap_or_default())
						.unwrap_or_default();
					let shift = tool_data.pivot_gizmo_shift.unwrap_or_default();
					overlay_context.pivot(pivot + offset + shift, angle);
				}

				// Update compass rose
				if overlay_context.visibility_settings.compass_rose() {
					tool_data.compass_rose.refresh_position(document);
					let compass_center = tool_data.compass_rose.compass_rose_position();
					if !matches!(self, Self::Dragging { .. }) {
						tool_data.line_center = compass_center;
					}

					overlay_context.compass_rose(compass_center, angle, show_compass_with_ring);

					let axis_state = if let SelectToolFsmState::Dragging { axis, .. } = self {
						Some((axis, false))
					} else {
						compass_rose_state.axis_type().and_then(|axis| axis.is_constraint().then_some((axis, true)))
					};

					if show_compass_with_ring.is_some() {
						if let Some((axis, hover)) = axis_state {
							if axis.is_constraint() {
								let e0 = tool_data
									.bounding_box_manager
									.as_ref()
									.map(|bounding_box_manager| bounding_box_manager.transform * Quad::from_box(bounding_box_manager.bounds))
									.map_or(DVec2::X, |quad| (quad.top_left() - quad.top_right()).normalize_or(DVec2::X));

								let (direction, color) = match axis {
									Axis::X => (e0, COLOR_OVERLAY_RED),
									Axis::Y => (e0.perp(), COLOR_OVERLAY_GREEN),
									_ => unreachable!(),
								};

								let viewport_diagonal = input.viewport_bounds.size().length();

								let color = if !hover {
									color
								} else {
									let color_string = &graphene_std::Color::from_rgb_str(color.strip_prefix('#').unwrap()).unwrap().with_alpha(0.25).to_rgba_hex_srgb();
									&format!("#{}", color_string)