@@ -212,25 +212,6 @@ void TextEdit_MoveCaret(LCUI_Widget widget, int row, int col)
212
212
TextEdit_UpdateCaret (widget );
213
213
}
214
214
215
- static void TextEdit_SetTaskForLineHeight (LCUI_Widget w , int height )
216
- {
217
- LCUI_TextEdit edit = GetData (w );
218
- TextLayer_SetLineHeight (edit -> layer_placeholder , height );
219
- TextLayer_SetLineHeight (edit -> layer_source , height );
220
- TextLayer_SetLineHeight (edit -> layer_mask , height );
221
- edit -> tasks [TASK_UPDATE ] = TRUE;
222
- Widget_AddTask (w , LCUI_WTASK_USER );
223
- }
224
-
225
- static void TextEdit_SetTaskForMultiline (LCUI_Widget widget , LCUI_BOOL is_true )
226
- {
227
- LCUI_TextEdit edit = Widget_GetData (widget , self .prototype );
228
- TextLayer_SetMultiline (edit -> layer_placeholder , is_true );
229
- TextLayer_SetMultiline (edit -> layer_source , is_true );
230
- TextLayer_SetMultiline (edit -> layer_mask , is_true );
231
- edit -> is_multiline_mode = is_true ;
232
- }
233
-
234
215
static void TextBlock_OnDestroy (void * arg )
235
216
{
236
217
LCUI_TextBlock blk = arg ;
@@ -463,6 +444,7 @@ static void TextEdit_AutoSize(LCUI_Widget widget, float *width, float *height)
463
444
int i , n , h ;
464
445
float scale = LCUIMetrics_GetScale ();
465
446
LCUI_TextEdit edit = GetData (widget );
447
+
466
448
if (edit -> is_multiline_mode ) {
467
449
n = max (TextLayer_GetRowTotal (edit -> layer ), 3 );
468
450
for (h = 0 , i = 0 ; i < n ; ++ i ) {
@@ -912,6 +894,7 @@ static void TextEdit_OnInit(LCUI_Widget w)
912
894
edit -> password_char = 0 ;
913
895
edit -> allow_input_char = NULL ;
914
896
edit -> is_placeholder_shown = FALSE;
897
+ edit -> is_multiline_mode = FALSE;
915
898
edit -> layer_mask = TextLayer_New ();
916
899
edit -> layer_source = TextLayer_New ();
917
900
edit -> layer_placeholder = TextLayer_New ();
@@ -983,31 +966,37 @@ static void TextEdit_OnPaint(LCUI_Widget w, LCUI_PaintContext paint,
983
966
TextLayer_RenderTo (edit -> layer , rect , pos , & canvas );
984
967
}
985
968
986
- static void TextEdit_SetTextStyle (LCUI_Widget w , LCUI_TextStyle ts )
969
+ static void TextEdit_OnUpdateStyle (LCUI_Widget w )
987
970
{
988
- LCUI_TextEdit edit = GetData ( w ) ;
971
+ int i ;
989
972
990
- TextLayer_SetTextStyle (edit -> layer_placeholder , ts );
991
- TextLayer_SetTextStyle (edit -> layer_source , ts );
992
- TextLayer_SetTextStyle (edit -> layer_mask , ts );
973
+ LCUI_TextEdit edit = GetData (w );
974
+ LCUI_TextStyleRec text_style ;
975
+ LCUI_CSSFontStyleRec style ;
976
+ LCUI_TextLayer layers [3 ] = { edit -> layer_mask , edit -> layer_placeholder ,
977
+ edit -> layer_source };
978
+
979
+ CSSFontStyle_Init (& style );
980
+ CSSFontStyle_Compute (& style , w -> style );
981
+ if (CSSFontStyle_IsEquals (& style , & edit -> style )) {
982
+ CSSFontStyle_Destroy (& style );
983
+ return ;
984
+ }
985
+ CSSFontStyle_GetTextStyle (& style , & text_style );
986
+ for (i = 0 ; i < 3 ; ++ i ) {
987
+ TextLayer_SetTextAlign (layers [i ], style .text_align );
988
+ TextLayer_SetLineHeight (layers [i ], style .line_height );
989
+ TextLayer_SetAutoWrap (layers [i ],
990
+ style .white_space != SV_NOWRAP );
991
+ TextLayer_SetTextStyle (layers [i ], & text_style );
992
+ }
993
+ CSSFontStyle_Destroy (& edit -> style );
994
+ TextStyle_Destroy (& text_style );
995
+ edit -> style = style ;
993
996
edit -> tasks [TASK_UPDATE ] = TRUE;
994
997
Widget_AddTask (w , LCUI_WTASK_USER );
995
998
}
996
999
997
- static void TextEdit_OnUpdate (LCUI_Widget w )
998
- {
999
- LCUI_TextStyleRec ts ;
1000
- LCUI_TextEdit edit = GetData (w );
1001
- LCUI_CSSFontStyle fs = & edit -> style ;
1002
-
1003
- CSSFontStyle_Compute (fs , w -> style );
1004
- CSSFontStyle_GetTextStyle (fs , & ts );
1005
- TextEdit_SetTaskForLineHeight (w , fs -> line_height );
1006
- TextEdit_SetTaskForMultiline (w , fs -> white_space != SV_NOWRAP );
1007
- TextEdit_SetTextStyle (w , & ts );
1008
- TextStyle_Destroy (& ts );
1009
- }
1010
-
1011
1000
static void TextEdit_OnValueChanged (LCUI_Object value , void * arg )
1012
1001
{
1013
1002
LCUI_Widget w = arg ;
@@ -1049,6 +1038,6 @@ void LCUIWidget_AddTextEdit(void)
1049
1038
self .prototype -> bindprop = TextEdit_BindProperty ;
1050
1039
self .prototype -> autosize = TextEdit_AutoSize ;
1051
1040
self .prototype -> runtask = TextEdit_OnTask ;
1052
- self .prototype -> update = TextEdit_OnUpdate ;
1041
+ self .prototype -> update = TextEdit_OnUpdateStyle ;
1053
1042
LCUI_LoadCSSString (textedit_css , __FILE__ );
1054
1043
}
0 commit comments