Skip to content

Commit bbb7cbc

Browse files
committedFeb 16, 2020
perf(gui): improve textedit update processing
1 parent 2287f97 commit bbb7cbc

File tree

2 files changed

+29
-39
lines changed

2 files changed

+29
-39
lines changed
 

‎src/gui/css_fontstyle.c

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ static void OnComputeWhiteSpace(LCUI_CSSFontStyle fs, LCUI_Style s)
350350

351351
void CSSFontStyle_Init(LCUI_CSSFontStyle fs)
352352
{
353+
fs->color.value = 0;
353354
fs->content = NULL;
354355
fs->font_ids = NULL;
355356
fs->font_family = NULL;

‎src/gui/widget/textedit.c

+28-39
Original file line numberDiff line numberDiff line change
@@ -212,25 +212,6 @@ void TextEdit_MoveCaret(LCUI_Widget widget, int row, int col)
212212
TextEdit_UpdateCaret(widget);
213213
}
214214

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-
234215
static void TextBlock_OnDestroy(void *arg)
235216
{
236217
LCUI_TextBlock blk = arg;
@@ -463,6 +444,7 @@ static void TextEdit_AutoSize(LCUI_Widget widget, float *width, float *height)
463444
int i, n, h;
464445
float scale = LCUIMetrics_GetScale();
465446
LCUI_TextEdit edit = GetData(widget);
447+
466448
if (edit->is_multiline_mode) {
467449
n = max(TextLayer_GetRowTotal(edit->layer), 3);
468450
for (h = 0, i = 0; i < n; ++i) {
@@ -912,6 +894,7 @@ static void TextEdit_OnInit(LCUI_Widget w)
912894
edit->password_char = 0;
913895
edit->allow_input_char = NULL;
914896
edit->is_placeholder_shown = FALSE;
897+
edit->is_multiline_mode = FALSE;
915898
edit->layer_mask = TextLayer_New();
916899
edit->layer_source = TextLayer_New();
917900
edit->layer_placeholder = TextLayer_New();
@@ -983,31 +966,37 @@ static void TextEdit_OnPaint(LCUI_Widget w, LCUI_PaintContext paint,
983966
TextLayer_RenderTo(edit->layer, rect, pos, &canvas);
984967
}
985968

986-
static void TextEdit_SetTextStyle(LCUI_Widget w, LCUI_TextStyle ts)
969+
static void TextEdit_OnUpdateStyle(LCUI_Widget w)
987970
{
988-
LCUI_TextEdit edit = GetData(w);
971+
int i;
989972

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;
993996
edit->tasks[TASK_UPDATE] = TRUE;
994997
Widget_AddTask(w, LCUI_WTASK_USER);
995998
}
996999

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-
10111000
static void TextEdit_OnValueChanged(LCUI_Object value, void *arg)
10121001
{
10131002
LCUI_Widget w = arg;
@@ -1049,6 +1038,6 @@ void LCUIWidget_AddTextEdit(void)
10491038
self.prototype->bindprop = TextEdit_BindProperty;
10501039
self.prototype->autosize = TextEdit_AutoSize;
10511040
self.prototype->runtask = TextEdit_OnTask;
1052-
self.prototype->update = TextEdit_OnUpdate;
1041+
self.prototype->update = TextEdit_OnUpdateStyle;
10531042
LCUI_LoadCSSString(textedit_css, __FILE__);
10541043
}

0 commit comments

Comments
 (0)
Please sign in to comment.