|
1 | 1 | /* |
2 | | - * lib/ui-widgets/src/textinput.c: -- textinput widget, used to allow user edit text. |
| 2 | + * lib/ui-widgets/src/textinput.c: -- textinput widget, used to allow user edit |
| 3 | + * text. |
3 | 4 | * |
4 | 5 | * Copyright (c) 2018-2024, Liu chao <[email protected]> All rights reserved. |
5 | 6 | * |
|
26 | 27 |
|
27 | 28 | enum task_type_t { TASK_SET_TEXT, TASK_UPDATE, TASK_TOTAL }; |
28 | 29 |
|
29 | | -typedef struct ui_textinput_t { |
| 30 | +typedef struct ui_textinput { |
30 | 31 | ui_text_style_t style; /**< 字体样式 */ |
31 | 32 | pd_text_t *layer_source; /**< 实际文本层 */ |
32 | 33 | pd_text_t *layer_mask; /**< 屏蔽后的文本层 */ |
@@ -371,8 +372,7 @@ static void ui_textinput_update_text(ui_widget_t *widget) |
371 | 372 | for (list_each(node, &blocks)) { |
372 | 373 | textinput_process_textblock(widget, node->data); |
373 | 374 | } |
374 | | - list_destroy(&blocks, |
375 | | - (list_item_destructor_t)textblock_destroy); |
| 375 | + list_destroy(&blocks, (list_item_destructor_t)textblock_destroy); |
376 | 376 | ui_event_init(&ev, "change"); |
377 | 377 | ui_widget_emit_event(widget, ev, NULL); |
378 | 378 | } |
@@ -400,48 +400,21 @@ static void ui_textinput_on_resize(ui_widget_t *w, float width, float height) |
400 | 400 | pd_rects_clear(&rects); |
401 | 401 | } |
402 | 402 |
|
403 | | -static void ui_textinput_on_auto_size(ui_widget_t *w, float *width, |
404 | | - float *height, ui_layout_rule_t rule) |
| 403 | +static void ui_textinput_on_autosize(ui_widget_t *w, float *width, |
| 404 | + float *height) |
405 | 405 | { |
406 | | - int i, n; |
| 406 | + int i; |
407 | 407 | int max_width = 0, max_height = 0; |
408 | 408 | float scale = ui_get_actual_scale(); |
409 | | - |
410 | 409 | ui_textinput_t *edit = ui_widget_get_data(w, ui_textinput_proto); |
411 | 410 |
|
412 | | - switch (rule) { |
413 | | - case UI_LAYOUT_RULE_FIXED_WIDTH: |
414 | | - max_width = ui_compute(w->content_box.width); |
415 | | - if (edit->is_multiline_mode) { |
416 | | - n = y_max(pd_text_get_lines_length(edit->layer), 6); |
417 | | - for (max_height = 0, i = 0; i < n; ++i) { |
418 | | - max_height += |
419 | | - pd_text_get_line_height(edit->layer, i); |
420 | | - } |
421 | | - } else { |
422 | | - max_height = pd_text_get_height(edit->layer); |
| 411 | + max_width = ui_compute(DEFAULT_WIDTH); |
| 412 | + if (edit->is_multiline_mode) { |
| 413 | + for (max_height = 0, i = 0; i < 6; ++i) { |
| 414 | + max_height += pd_text_get_line_height(edit->layer, i); |
423 | 415 | } |
424 | | - break; |
425 | | - case UI_LAYOUT_RULE_FIXED_HEIGHT: |
426 | | - max_width = ui_compute(DEFAULT_WIDTH); |
427 | | - max_height = ui_compute(w->content_box.height); |
428 | | - break; |
429 | | - case UI_LAYOUT_RULE_FIXED: |
430 | | - max_width = ui_compute(w->content_box.width); |
431 | | - max_height = ui_compute(w->content_box.height); |
432 | | - break; |
433 | | - default: |
434 | | - max_width = ui_compute(DEFAULT_WIDTH); |
435 | | - if (edit->is_multiline_mode) { |
436 | | - n = y_max(pd_text_get_lines_length(edit->layer), 6); |
437 | | - for (max_height = 0, i = 0; i < n; ++i) { |
438 | | - max_height += |
439 | | - pd_text_get_line_height(edit->layer, i); |
440 | | - } |
441 | | - } else { |
442 | | - max_height = pd_text_get_height(edit->layer); |
443 | | - } |
444 | | - break; |
| 416 | + } else { |
| 417 | + max_height = pd_text_get_height(edit->layer); |
445 | 418 | } |
446 | 419 | *height = max_height / scale; |
447 | 420 | *width = max_width / scale; |
@@ -1004,7 +977,7 @@ void ui_register_textinput(void) |
1004 | 977 | ui_textinput_proto->destroy = ui_textinput_on_destroy; |
1005 | 978 | ui_textinput_proto->settext = ui_textinput_on_parse_text; |
1006 | 979 | ui_textinput_proto->setattr = ui_textinput_on_set_attr; |
1007 | | - ui_textinput_proto->autosize = ui_textinput_on_auto_size; |
| 980 | + ui_textinput_proto->autosize = ui_textinput_on_autosize; |
1008 | 981 | ui_textinput_proto->resize = ui_textinput_on_resize; |
1009 | 982 | ui_textinput_proto->update = ui_textinput_on_update; |
1010 | 983 | ui_load_css_string(ui_textinput_css, __FILE__); |
|
0 commit comments