Skip to content

Commit 4d084e8

Browse files
committed
minor format
Introduce text alignment
1 parent 5c8cd9a commit 4d084e8

File tree

8 files changed

+342
-44
lines changed

8 files changed

+342
-44
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use graph_craft::document::*;
1717
use graphene_core::raster::brush_cache::BrushCache;
1818
use graphene_core::raster::image::RasterDataTable;
1919
use graphene_core::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
20-
use graphene_core::text::{Font, TypesettingConfig};
20+
use graphene_core::text::{Font, TextAlignment, TypesettingConfig};
2121
use graphene_core::transform::Footprint;
2222
use graphene_core::vector::VectorDataTable;
2323
use graphene_core::*;
@@ -1987,6 +1987,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
19871987
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().character_spacing), false),
19881988
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_width), false),
19891989
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_height), false),
1990+
NodeInput::value(TaggedValue::TextAlignment(TypesettingConfig::default().text_alignment), false),
19901991
],
19911992
..Default::default()
19921993
},
@@ -2040,6 +2041,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
20402041
..Default::default()
20412042
}),
20422043
),
2044+
PropertiesRow::with_override("Text Alignment", "TODO", WidgetOverride::Custom("text_alignment".to_string())),
20432045
],
20442046
output_names: vec!["Vector".to_string()],
20452047
..Default::default()
@@ -3311,6 +3313,16 @@ fn static_input_properties() -> InputProperties {
33113313
)])
33123314
}),
33133315
);
3316+
map.insert(
3317+
"text_alignment".to_string(),
3318+
Box::new(|node_id, index, context| {
3319+
let (document_node, input_name, input_description) = node_properties::query_node_and_input_info(node_id, index, context)?;
3320+
let text_alignment = enum_choice::<TextAlignment>()
3321+
.for_socket(ParameterWidgetsInfo::new(document_node, node_id, index, input_name, input_description, true))
3322+
.property_row();
3323+
Ok(vec![text_alignment])
3324+
}),
3325+
);
33143326
map
33153327
}
33163328

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
750750
}
751751

752752
// Upgrade Text node to include line height and character spacing, which were previously hardcoded to 1, from https://github.com/GraphiteEditor/Graphite/pull/2016
753-
if reference == "Text" && inputs_count != 8 {
753+
if reference == "Text" && inputs_count != 9 {
754754
let node_definition = resolve_document_node_type(reference).unwrap();
755755
let document_node = node_definition.default_node_template().document_node;
756756
document.network_interface.replace_implementation(node_id, network_path, document_node.implementation.clone());
@@ -789,6 +789,11 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
789789
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_height), false),
790790
network_path,
791791
);
792+
document.network_interface.set_input(
793+
&InputConnector::node(*node_id, 8),
794+
NodeInput::value(TaggedValue::TextAlignment(TypesettingConfig::default().text_alignment), false),
795+
network_path,
796+
);
792797
}
793798

794799
// Upgrade Sine, Cosine, and Tangent nodes to include a boolean input for whether the output should be in radians, which was previously the only option but is now not the default

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,15 @@ pub fn get_text(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInter
342342
let Some(&TaggedValue::F64(character_spacing)) = inputs[5].as_value() else { return None };
343343
let Some(&TaggedValue::OptionalF64(max_width)) = inputs[6].as_value() else { return None };
344344
let Some(&TaggedValue::OptionalF64(max_height)) = inputs[7].as_value() else { return None };
345+
let Some(&TaggedValue::TextAlignment(text_alignment)) = inputs[8].as_value() else { return None };
345346

346347
let typesetting = TypesettingConfig {
347348
font_size,
348349
line_height_ratio,
349350
max_width,
350351
character_spacing,
351352
max_height,
353+
text_alignment,
352354
};
353355
Some((text, font, typesetting))
354356
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use graph_craft::document::value::TaggedValue;
1818
use graph_craft::document::{NodeId, NodeInput};
1919
use graphene_core::Color;
2020
use graphene_core::renderer::Quad;
21-
use graphene_core::text::{Font, FontCache, TypesettingConfig, lines_clipping, load_face};
21+
use graphene_core::text::{Font, FontCache, TextAlignment, TypesettingConfig, lines_clipping, load_face};
2222
use graphene_core::vector::style::Fill;
2323

2424
#[derive(Default)]
@@ -784,6 +784,7 @@ impl Fsm for TextToolFsmState {
784784
max_width: constraint_size.map(|size| size.x),
785785
character_spacing: tool_options.character_spacing,
786786
max_height: constraint_size.map(|size| size.y),
787+
text_alignment: TextAlignment::default(),
787788
},
788789
font: Font::new(tool_options.font_name.clone(), tool_options.font_style.clone()),
789790
color: tool_options.fill.active_color(),
2.44 KB
Binary file not shown.

0 commit comments

Comments
 (0)