Skip to content

Commit c0d3eb8

Browse files
Nitish-botKeavon0HyperCube
authored
Add sizing gizmos to the Text tool's text area (#2176)
* Fix abortion while dragging * Create function for text bounding box * Reorder arms of text tool FSM * add transform cage to textbox pt.1 * add transform cage pt.2 * Fix minor issue after merge * Get bounding box working in place without action keys * Add max_height and disable pivot drag * Cleanup code and write doco for new utility function * Minor change due to merge * Add bottom overlay * Get modifier keys to work pt.1 * Code cleanup * cleanup * Fix transform * Minor improvements * Undo debug statement! * Add comments and keep original layer transformation * Alt from centre * Fix merge conflict * Minor code review --------- Co-authored-by: Keavon Chambers <[email protected]> Co-authored-by: hypercube <[email protected]> Co-authored-by: James Lindsay <[email protected]>
1 parent a696aae commit c0d3eb8

File tree

8 files changed

+319
-63
lines changed

8 files changed

+319
-63
lines changed

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ pub fn input_mappings() -> Mapping {
157157
entry!(PointerMove; refresh_keys=[Alt, Shift], action_dispatch=TextToolMessage::PointerMove { center: Alt, lock_ratio: Shift }),
158158
entry!(KeyDown(MouseLeft); action_dispatch=TextToolMessage::DragStart),
159159
entry!(KeyUp(MouseLeft); action_dispatch=TextToolMessage::DragStop),
160-
entry!(KeyDown(MouseRight); action_dispatch=TextToolMessage::CommitText),
161-
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::CommitText),
162-
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::CommitText),
160+
entry!(KeyDown(MouseRight); action_dispatch=TextToolMessage::Abort),
161+
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::Abort),
162+
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::Abort),
163163
//
164164
// GradientToolMessage
165165
entry!(KeyDown(MouseLeft); action_dispatch=GradientToolMessage::PointerDown),

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3821,7 +3821,6 @@ impl NodeNetworkInterface {
38213821
log::error!("Cannot connect a network to an export, see https://github.com/GraphiteEditor/Graphite/issues/1762");
38223822
return;
38233823
}
3824-
38253824
let Some(previous_input) = self.input_from_connector(input_connector, network_path).cloned() else {
38263825
log::error!("Could not get previous input in set_input");
38273826
return;

editor/src/messages/tool/common_functionality/transformation_cage.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,13 @@ pub fn snap_drag(start: DVec2, current: DVec2, axis_align: bool, snap_data: Snap
351351
/// Contains info on the overlays for the bounding box and transform handles
352352
#[derive(Clone, Debug, Default)]
353353
pub struct BoundingBoxManager {
354+
/// The corners of the box. Transform with original_bound_transform to get viewport co-ordinates.
354355
pub bounds: [DVec2; 2],
356+
/// The transform to viewport space for the bounds co-ordinates when the bounds were last updated.
355357
pub transform: DAffine2,
358+
/// Was the transform previously singular?
356359
pub transform_tampered: bool,
360+
/// The transform to viewport space for the bounds co-ordinates when the transformation was started.
357361
pub original_bound_transform: DAffine2,
358362
pub selected_edges: Option<SelectedEdges>,
359363
pub original_transforms: OriginalTransforms,

editor/src/messages/tool/common_functionality/utility_functions.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
22
use crate::messages::prelude::*;
3+
use crate::messages::tool::common_functionality::graph_modification_utils::get_text;
34

5+
use graphene_core::renderer::Quad;
6+
use graphene_core::text::{load_face, FontCache};
47
use graphene_std::vector::PointId;
58

69
use glam::DVec2;
@@ -53,3 +56,13 @@ where
5356

5457
best
5558
}
59+
60+
/// Calculates the bounding box of the layer's text, based on the settings for max width and height specified in the typesetting config.
61+
pub fn text_bounding_box(layer: LayerNodeIdentifier, document: &DocumentMessageHandler, font_cache: &FontCache) -> Quad {
62+
let (text, font, typesetting) = get_text(layer, &document.network_interface).expect("Text layer should have text when interacting with the Text tool");
63+
64+
let buzz_face = font_cache.get(font).map(|data| load_face(data));
65+
let far = graphene_core::text::bounding_box(text, buzz_face.as_ref(), typesetting);
66+
67+
Quad::from_box([DVec2::ZERO, far])
68+
}

editor/src/messages/tool/tool_messages/select_tool.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
1515
use crate::messages::portfolio::document::utility_types::transformation::Selected;
1616
use crate::messages::preferences::SelectionMode;
1717
use crate::messages::tool::common_functionality::compass_rose::{Axis, CompassRose};
18-
use crate::messages::tool::common_functionality::graph_modification_utils::{get_text, is_layer_fed_by_node_of_name};
18+
use crate::messages::tool::common_functionality::graph_modification_utils::is_layer_fed_by_node_of_name;
1919
use crate::messages::tool::common_functionality::pivot::Pivot;
2020
use crate::messages::tool::common_functionality::shape_editor::SelectionShapeType;
2121
use crate::messages::tool::common_functionality::snapping::{self, SnapCandidatePoint, SnapData, SnapManager};
2222
use crate::messages::tool::common_functionality::transformation_cage::*;
23+
use crate::messages::tool::common_functionality::utility_functions::text_bounding_box;
2324
use crate::messages::tool::common_functionality::{auto_panning::AutoPanning, measure};
2425

2526
use bezier_rs::Subpath;
2627
use graph_craft::document::NodeId;
2728
use graphene_core::renderer::Quad;
28-
use graphene_core::text::load_face;
2929
use graphene_std::renderer::Rect;
3030
use graphene_std::vector::misc::BooleanOperation;
3131

@@ -511,14 +511,8 @@ impl Fsm for SelectToolFsmState {
511511
overlay_context.outline(document.metadata().layer_outline(layer), document.metadata().transform_to_viewport(layer));
512512

513513
if is_layer_fed_by_node_of_name(layer, &document.network_interface, "Text") {
514-
let (text, font, typesetting) = get_text(layer, &document.network_interface).expect("Text layer should have text when interacting with the Text tool in `interact()`");
515-
516-
let buzz_face = font_cache.get(font).map(|data| load_face(data));
517-
let far = graphene_core::text::bounding_box(text, buzz_face, typesetting);
518-
let quad = Quad::from_box([DVec2::ZERO, far]);
519-
let transformed_quad = document.metadata().transform_to_viewport(layer) * quad;
520-
521-
overlay_context.dashed_quad(transformed_quad, None, Some(4.), Some(4.), Some(0.5));
514+
let transformed_quad = document.metadata().transform_to_viewport(layer) * text_bounding_box(layer, document, font_cache);
515+
overlay_context.dashed_quad(transformed_quad, None, Some(7.), Some(5.), None);
522516
}
523517
}
524518

0 commit comments

Comments
 (0)