format code

This commit is contained in:
xianjimli 2020-10-20 18:13:38 +08:00
parent 6685f42933
commit f695719134
11 changed files with 51 additions and 34 deletions

View File

@ -31,7 +31,8 @@ typedef struct _dialog_highlighter_t dialog_highlighter_t;
typedef ret_t (*dialog_highlighter_set_system_bar_alpha_t)(dialog_highlighter_t* h, uint8_t alpha);
typedef uint8_t (*dialog_highlighter_get_alpha_t)(dialog_highlighter_t* h, float_t percent);
typedef ret_t (*dialog_highlighter_draw_mask_t)(dialog_highlighter_t* h, canvas_t* c, float_t percent);
typedef ret_t (*dialog_highlighter_draw_mask_t)(dialog_highlighter_t* h, canvas_t* c,
float_t percent);
typedef ret_t (*dialog_highlighter_prepare_t)(dialog_highlighter_t* h, canvas_t* c);
typedef ret_t (*dialog_highlighter_draw_t)(dialog_highlighter_t* h, float_t percent);
typedef bool_t (*dialog_highlighter_is_dynamic_t)(dialog_highlighter_t* h);

3
src/dialog_highlighters/dialog_highlighter_default.c Executable file → Normal file
View File

@ -52,7 +52,8 @@ static ret_t dialog_highlighter_default_draw_mask_system_bar(canvas_t* c, uint8_
return RET_OK;
}
static ret_t dialog_highlighter_default_draw_mask_from_percent(dialog_highlighter_t* h, canvas_t* c, float_t percent) {
static ret_t dialog_highlighter_default_draw_mask_from_percent(dialog_highlighter_t* h, canvas_t* c,
float_t percent) {
dialog_highlighter_default_t* dh = (dialog_highlighter_default_t*)h;
return_value_if_fail(dh != NULL && c != NULL, RET_BAD_PARAMS);

View File

@ -149,8 +149,9 @@ static ret_t rich_text_on_paint_text(widget_t* widget, canvas_t* c) {
return RET_OK;
}
static bool_t rich_text_is_need_reset_from_style(rich_text_t* rich_text, char* font_name, uint16_t font_size, color_t color, align_v_t align_v) {
static bool_t rich_text_is_need_reset_from_style(rich_text_t* rich_text, char* font_name,
uint16_t font_size, color_t color,
align_v_t align_v) {
if (tk_str_cmp(rich_text->default_font_name, font_name) != 0) {
return TRUE;
}
@ -176,17 +177,20 @@ static ret_t rich_text_ensure_render_node(widget_t* widget, canvas_t* c) {
const char* default_font_name = style_get_str(style, STYLE_ID_FONT_NAME, NULL);
uint16_t default_font_size = style_get_int(style, STYLE_ID_FONT_SIZE, TK_DEFAULT_FONT_SIZE);
color_t default_color = style_get_color(style, STYLE_ID_TEXT_COLOR, color_init(0, 0, 0, 0xff));
align_v_t default_align_v = (align_v_t)style_get_int(style, STYLE_ID_TEXT_ALIGN_V, ALIGN_V_BOTTOM);
align_v_t default_align_v =
(align_v_t)style_get_int(style, STYLE_ID_TEXT_ALIGN_V, ALIGN_V_BOTTOM);
return_value_if_fail(widget != NULL && rich_text != NULL && style != NULL, RET_BAD_PARAMS);
rich_text->need_reset = rich_text_is_need_reset_from_style(rich_text, default_font_name, default_font_size, default_color, default_align_v);
rich_text->need_reset = rich_text_is_need_reset_from_style(
rich_text, default_font_name, default_font_size, default_color, default_align_v);
if (rich_text->need_reset) {
str_t str;
str_init(&str, widget->text.size * 4 + 1);
str_from_wstr(&str, widget->text.str);
rich_text_reset(widget);
rich_text->node = rich_text_parse(str.str, str.size, default_font_name, default_font_size, default_color, default_align_v);
rich_text->node = rich_text_parse(str.str, str.size, default_font_name, default_font_size,
default_color, default_align_v);
str_reset(&str);
rich_text->need_reset = FALSE;

8
src/ext_widgets/rich_text/rich_text_parser.c Executable file → Normal file
View File

@ -160,7 +160,8 @@ static void xml_rich_text_destroy(XmlBuilder* thiz) {
return;
}
static XmlBuilder* builder_init(xml_builder_t* b, char* font_name, uint16_t font_size, color_t color, align_v_t align_v) {
static XmlBuilder* builder_init(xml_builder_t* b, char* font_name, uint16_t font_size,
color_t color, align_v_t align_v) {
int32_t i = 0;
memset(b, 0x00, sizeof(xml_builder_t));
@ -175,7 +176,7 @@ static XmlBuilder* builder_init(xml_builder_t* b, char* font_name, uint16_t font
rich_text_font_t* iter = b->fonts + i;
iter->name = font_name;
iter->size = font_size;
iter->color =color;
iter->color = color;
iter->align_v = align_v;
}
str_init(&(b->temp), 100);
@ -183,7 +184,8 @@ static XmlBuilder* builder_init(xml_builder_t* b, char* font_name, uint16_t font
return &(b->builder);
}
rich_text_node_t* rich_text_parse(const char* str, uint32_t size, char* font_name, uint16_t font_size, color_t color, align_v_t align_v) {
rich_text_node_t* rich_text_parse(const char* str, uint32_t size, char* font_name,
uint16_t font_size, color_t color, align_v_t align_v) {
xml_builder_t b;
XmlParser* parser = NULL;
rich_text_node_t* node = NULL;

View File

@ -26,7 +26,8 @@
BEGIN_C_DECLS
rich_text_node_t* rich_text_parse(const char* str, uint32_t size, char* font_name, uint16_t font_size, color_t color, align_v_t align_v);
rich_text_node_t* rich_text_parse(const char* str, uint32_t size, char* font_name,
uint16_t font_size, color_t color, align_v_t align_v);
END_C_DECLS

View File

@ -367,8 +367,9 @@ static ret_t label_auto_adjust_size(widget_t* widget) {
w = label_get_text_line_max_w(widget, c);
}
return_value_if_fail(label_line_parser_init(&p, c, widget->text.str, widget->text.size,
c->font_size, w - 2 * margin, label->line_wrap) == RET_OK,
return_value_if_fail(
label_line_parser_init(&p, c, widget->text.str, widget->text.size, c->font_size,
w - 2 * margin, label->line_wrap) == RET_OK,
RET_BAD_PARAMS);
widget->w = w;

View File

@ -143,18 +143,21 @@ ret_t window_manager_default_snap_curr_window(widget_t* widget, widget_t* curr_w
return RET_OK;
}
static ret_t window_manager_default_snap_prev_window_draw_dialog_highlighter_and_get_alpha(widget_t* widget, canvas_t* c, uint8_t* alpha){
static ret_t window_manager_default_snap_prev_window_draw_dialog_highlighter_and_get_alpha(
widget_t* widget, canvas_t* c, uint8_t* alpha) {
value_t v;
return_value_if_fail(widget != NULL && c != NULL, FALSE);
if (widget_get_prop(widget, WIDGET_PROP_HIGHLIGHT, &v) == RET_OK) {
const char* args = value_str(&v);
dialog_highlighter_factory_t* f = dialog_highlighter_factory();
dialog_highlighter_t* dialog_highlighter = dialog_highlighter_factory_create_highlighter(f, args, widget);
dialog_highlighter_t* dialog_highlighter =
dialog_highlighter_factory_create_highlighter(f, args, widget);
if (dialog_highlighter != NULL) {
dialog_highlighter_draw_mask(dialog_highlighter, c, 1.0f);
*alpha = dialog_highlighter_get_alpha(dialog_highlighter, 1.0f);
widget_off_by_func(widget, EVT_DESTROY, dialog_highlighter_on_dialog_destroy, dialog_highlighter);
widget_off_by_func(widget, EVT_DESTROY, dialog_highlighter_on_dialog_destroy,
dialog_highlighter);
dialog_highlighter_destroy(dialog_highlighter);
return RET_OK;
}
@ -173,7 +176,9 @@ static bool_t window_manager_default_is_dialog_highlighter(widget_t* widget) {
return FALSE;
}
static widget_t* window_manager_default_find_top_dialog_highlighter(widget_t* widget, widget_t* prev_win, widget_t* curr_win) {
static widget_t* window_manager_default_find_top_dialog_highlighter(widget_t* widget,
widget_t* prev_win,
widget_t* curr_win) {
int32_t i = 0;
widget_t* dialog = NULL;
widget_t** children = (widget_t**)(widget->children->elms);
@ -237,7 +242,8 @@ ret_t window_manager_default_snap_prev_window(widget_t* widget, widget_t* prev_w
/* 给前面的高亮对话框叠加黑色色块 */
if (widget_is_dialog(iter)) {
uint8_t a = 0x0;
window_manager_default_snap_prev_window_draw_dialog_highlighter_and_get_alpha(iter, canvas, &a);
window_manager_default_snap_prev_window_draw_dialog_highlighter_and_get_alpha(iter,
canvas, &a);
if (dialog_highlighter != NULL) {
dialog_highlighter_set_system_bar_alpha(dialog_highlighter, a);
}
@ -730,7 +736,8 @@ static ret_t window_manager_animate_done(widget_t* widget) {
window_manager_dispatch_window_event(prev_win, EVT_WINDOW_TO_BACKGROUND);
}
if (!curr_win_is_normal_window) {
top_dialog_highligth = window_manager_default_find_top_dialog_highlighter(widget, prev_win, curr_win_is_keyboard ? curr_win : NULL);
top_dialog_highligth = window_manager_default_find_top_dialog_highlighter(
widget, prev_win, curr_win_is_keyboard ? curr_win : NULL);
}
window_manager_dispatch_window_event(curr_win, EVT_WINDOW_OPEN);
} else {
@ -738,8 +745,8 @@ static ret_t window_manager_animate_done(widget_t* widget) {
if (!curr_win_is_keyboard) {
window_manager_animate_done_set_window_foreground(widget, prev_win, curr_win);
}
top_dialog_highligth = window_manager_default_find_top_dialog_highlighter(widget, prev_win, curr_win);
top_dialog_highligth =
window_manager_default_find_top_dialog_highlighter(widget, prev_win, curr_win);
}
/* 制作一张没有最后一个对话框的高亮背景贴图 */
if (top_dialog_highligth != NULL) {