From 2ae35a67e70bcafc033cc9f6c00f1462a28adc4f Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Wed, 6 May 2026 19:26:26 -0700 Subject: [PATCH] Add icons for text alignment/justification --- .branding | 4 +- .../messages/tool/tool_messages/text_tool.rs | 37 ++++++----- frontend/src/icons.ts | 18 ++++++ node-graph/libraries/core-types/src/text.rs | 62 ------------------- node-graph/nodes/text/src/lib.rs | 7 +++ 5 files changed, 45 insertions(+), 83 deletions(-) delete mode 100644 node-graph/libraries/core-types/src/text.rs diff --git a/.branding b/.branding index dcfcb9d1..50217994 100644 --- a/.branding +++ b/.branding @@ -1,2 +1,2 @@ -https://github.com/Keavon/graphite-branded-assets/archive/1509880500e32cb21235343ba865adcf0579133f.tar.gz -89b4c58aee186b0c1610a8778bd199c9bdaf1191b4006e6b007dc40a402f4aa7 +https://github.com/Keavon/graphite-branded-assets/archive/b83626b10f0f9102503c845354e9e3f161949ce0.tar.gz +353e9cba90f420b11863055a32e554937638b47d1539632ef0e8a30f37a353d7 diff --git a/editor/src/messages/tool/tool_messages/text_tool.rs b/editor/src/messages/tool/tool_messages/text_tool.rs index a91d9101..0e054757 100644 --- a/editor/src/messages/tool/tool_messages/text_tool.rs +++ b/editor/src/messages/tool/tool_messages/text_tool.rs @@ -17,6 +17,7 @@ use crate::messages::tool::common_functionality::utility_functions::text_boundin use crate::messages::tool::utility_types::ToolRefreshOptions; use graph_craft::document::value::TaggedValue; use graph_craft::document::{NodeId, NodeInput}; +use graphene_std::choice_type::ChoiceTypeStatic; use graphene_std::renderer::Quad; use graphene_std::text::{Font, FontCache, TextAlign, TypesettingConfig, lines_clipping}; use graphene_std::vector::style::Fill; @@ -204,25 +205,23 @@ fn create_text_widgets(tool: &TextTool, font_catalog: &FontCatalog) -> Vec = [ - TextAlign::AlignLeft, - TextAlign::AlignCenter, - TextAlign::AlignRight, - TextAlign::JustifyLeft, - TextAlign::JustifyCenter, - TextAlign::JustifyRight, - TextAlign::JustifyAll, - ] - .into_iter() - .map(|align| { - RadioEntryData::new(format!("{align:?}")).label(align.to_string()).on_update(move |_| { - TextToolMessage::UpdateOptions { - options: TextOptionsUpdate::Align(align), - } - .into() + let align_entries: Vec<_> = TextAlign::list() + .iter() + .flat_map(|section| section.iter()) + .map(|(item, var_meta)| { + let align = *item; + let entry = RadioEntryData::new(var_meta.name) + .tooltip_label(var_meta.label) + .tooltip_description(var_meta.description.unwrap_or_default()) + .on_update(move |_| { + TextToolMessage::UpdateOptions { + options: TextOptionsUpdate::Align(align), + } + .into() + }); + if let Some(icon) = var_meta.icon { entry.icon(icon) } else { entry.label(var_meta.label) } }) - }) - .collect(); + .collect(); let align = RadioInput::new(align_entries).selected_index(Some(tool.options.align as u32)).widget_instance(); vec![ font, @@ -232,7 +231,7 @@ fn create_text_widgets(tool: &TextTool, font_catalog: &FontCatalog) -> Vec for parley::Alignment { - fn from(val: TextAlign) -> Self { - match val { - TextAlign::Left => parley::Alignment::Left, - TextAlign::Center => parley::Alignment::Center, - TextAlign::Right => parley::Alignment::Right, - TextAlign::JustifyLeft => parley::Alignment::Justify, - } - } -} - -#[derive(PartialEq, Clone, Copy, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct TypesettingConfig { - pub font_size: f64, - pub line_height_ratio: f64, - pub character_spacing: f64, - pub max_width: Option, - pub max_height: Option, - pub tilt: f64, - pub align: TextAlign, -} - -impl Default for TypesettingConfig { - fn default() -> Self { - Self { - font_size: 24., - line_height_ratio: 1.2, - character_spacing: 0., - max_width: None, - max_height: None, - tilt: 0., - align: TextAlign::default(), - } - } -} diff --git a/node-graph/nodes/text/src/lib.rs b/node-graph/nodes/text/src/lib.rs index 7d60038d..a9605780 100644 --- a/node-graph/nodes/text/src/lib.rs +++ b/node-graph/nodes/text/src/lib.rs @@ -31,12 +31,19 @@ pub use vector_types; #[widget(Radio)] pub enum TextAlign { #[default] + #[icon("TextAlignLeft")] AlignLeft, + #[icon("TextAlignCenter")] AlignCenter, + #[icon("TextAlignRight")] AlignRight, + #[icon("TextJustifyLeft")] JustifyLeft, + #[icon("TextJustifyCenter")] JustifyCenter, + #[icon("TextJustifyRight")] JustifyRight, + #[icon("TextJustifyAll")] JustifyAll, }