@@ -17,7 +17,7 @@ use graph_craft::document::value::TaggedValue;
1717use graph_craft:: document:: { NodeId , NodeInput } ;
1818use graphene_std:: Color ;
1919use graphene_std:: renderer:: Quad ;
20- use graphene_std:: text:: { Font , FontCache , TypesettingConfig , lines_clipping, load_font} ;
20+ use graphene_std:: text:: { Font , FontCache , TextAlign , TypesettingConfig , lines_clipping, load_font} ;
2121use graphene_std:: vector:: style:: Fill ;
2222
2323#[ derive( Default , ExtractField ) ]
@@ -35,6 +35,7 @@ pub struct TextOptions {
3535 font_style : String ,
3636 fill : ToolColorOptions ,
3737 tilt : f64 ,
38+ align : TextAlign ,
3839}
3940
4041impl Default for TextOptions {
@@ -47,6 +48,7 @@ impl Default for TextOptions {
4748 font_style : graphene_std:: consts:: DEFAULT_FONT_STYLE . into ( ) ,
4849 fill : ToolColorOptions :: new_primary ( ) ,
4950 tilt : 0. ,
51+ align : TextAlign :: default ( ) ,
5052 }
5153 }
5254}
@@ -78,7 +80,7 @@ pub enum TextOptionsUpdate {
7880 Font { family : String , style : String } ,
7981 FontSize ( f64 ) ,
8082 LineHeightRatio ( f64 ) ,
81- CharacterSpacing ( f64 ) ,
83+ Align ( TextAlign ) ,
8284 WorkingColors ( Option < Color > , Option < Color > ) ,
8385}
8486
@@ -131,14 +133,15 @@ fn create_text_widgets(tool: &TextTool) -> Vec<WidgetHolder> {
131133 . step ( 0.1 )
132134 . on_update ( |number_input : & NumberInput | TextToolMessage :: UpdateOptions ( TextOptionsUpdate :: LineHeightRatio ( number_input. value . unwrap ( ) ) ) . into ( ) )
133135 . widget_holder ( ) ;
134- let character_spacing = NumberInput :: new ( Some ( tool. options . character_spacing ) )
135- . label ( "Char. Spacing" )
136- . int ( )
137- . min ( 0. )
138- . max ( ( 1_u64 << f64:: MANTISSA_DIGITS ) as f64 )
139- . step ( 0.1 )
140- . on_update ( |number_input : & NumberInput | TextToolMessage :: UpdateOptions ( TextOptionsUpdate :: CharacterSpacing ( number_input. value . unwrap ( ) ) ) . into ( ) )
141- . widget_holder ( ) ;
136+ let align_entries: Vec < _ > = [ TextAlign :: Left , TextAlign :: Center , TextAlign :: Right , TextAlign :: JustifyLeft ]
137+ . into_iter ( )
138+ . map ( |align| {
139+ RadioEntryData :: new ( format ! ( "{align:?}" ) )
140+ . label ( align. to_string ( ) )
141+ . on_update ( move |_| TextToolMessage :: UpdateOptions ( TextOptionsUpdate :: Align ( align) ) . into ( ) )
142+ } )
143+ . collect ( ) ;
144+ let align = RadioInput :: new ( align_entries) . selected_index ( Some ( tool. options . align as u32 ) ) . widget_holder ( ) ;
142145 vec ! [
143146 font,
144147 Separator :: new( SeparatorType :: Related ) . widget_holder( ) ,
@@ -148,7 +151,7 @@ fn create_text_widgets(tool: &TextTool) -> Vec<WidgetHolder> {
148151 Separator :: new( SeparatorType :: Related ) . widget_holder( ) ,
149152 line_height_ratio,
150153 Separator :: new( SeparatorType :: Related ) . widget_holder( ) ,
151- character_spacing ,
154+ align ,
152155 ]
153156}
154157
@@ -186,7 +189,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Text
186189 }
187190 TextOptionsUpdate :: FontSize ( font_size) => self . options . font_size = font_size,
188191 TextOptionsUpdate :: LineHeightRatio ( line_height_ratio) => self . options . line_height_ratio = line_height_ratio,
189- TextOptionsUpdate :: CharacterSpacing ( character_spacing ) => self . options . character_spacing = character_spacing ,
192+ TextOptionsUpdate :: Align ( align ) => self . options . align = align ,
190193 TextOptionsUpdate :: FillColor ( color) => {
191194 self . options . fill . custom_color = color;
192195 self . options . fill . color_type = ToolColorType :: Custom ;
@@ -314,6 +317,7 @@ impl TextToolData {
314317 transform : editing_text. transform . to_cols_array ( ) ,
315318 max_width : editing_text. typesetting . max_width ,
316319 max_height : editing_text. typesetting . max_height ,
320+ align : editing_text. typesetting . align ,
317321 } ) ;
318322 } else {
319323 // Check if DisplayRemoveEditableTextbox is already in the responses queue
@@ -792,6 +796,7 @@ impl Fsm for TextToolFsmState {
792796 character_spacing : tool_options. character_spacing ,
793797 max_height : constraint_size. map ( |size| size. y ) ,
794798 tilt : tool_options. tilt ,
799+ align : tool_options. align ,
795800 } ,
796801 font : Font :: new ( tool_options. font_name . clone ( ) , tool_options. font_style . clone ( ) ) ,
797802 color : tool_options. fill . active_color ( ) ,
0 commit comments