format code

This commit is contained in:
lixianjing 2020-10-24 09:45:42 +08:00
parent 9af821b04b
commit b35d57d166
9 changed files with 55 additions and 39 deletions

View File

@ -479,4 +479,3 @@ ret_t conf_json_save_as(object_t* obj, const char* url) {
return RET_OK;
}

View File

@ -246,4 +246,3 @@ ret_t conf_ubjson_save_as(object_t* obj, const char* url) {
return RET_OK;
}

View File

@ -181,8 +181,10 @@ static ret_t rich_text_ensure_render_node(widget_t* widget, canvas_t* c) {
(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->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->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;

View File

@ -73,8 +73,9 @@ static ret_t text_selector_paint_mask(widget_t* widget, canvas_t* c) {
return RET_OK;
}
static int32_t text_selector_range_yoffset(int32_t value, int32_t min_yoffset, int32_t max_yoffset, int32_t item_height, int32_t empty_item_height, bool_t loop_options) {
static int32_t text_selector_range_yoffset(int32_t value, int32_t min_yoffset, int32_t max_yoffset,
int32_t item_height, int32_t empty_item_height,
bool_t loop_options) {
if (value < min_yoffset) {
if (loop_options) {
int32_t tmp = max_yoffset + empty_item_height + item_height;
@ -127,7 +128,8 @@ static ret_t text_selector_paint_self(widget_t* widget, canvas_t* c) {
i = 0;
}
yoffset = text_selector_range_yoffset(yoffset, min_yoffset, max_yoffset, item_height, empty_item_height, text_selector->loop_options);
yoffset = text_selector_range_yoffset(yoffset, min_yoffset, max_yoffset, item_height,
empty_item_height, text_selector->loop_options);
while (iter != NULL) {
r.y = y - yoffset;
@ -296,7 +298,7 @@ static ret_t text_selector_get_prop(widget_t* widget, const char* name, value_t*
} else if (tk_str_eq(name, TEXT_SELECTOR_PROP_Y_SPEED_SCALE)) {
value_set_float(v, text_selector->yspeed_scale);
return RET_OK;
} else if (tk_str_eq(name,TEXT_SELECTOR_PROP_LOOP_OPTIONS)) {
} else if (tk_str_eq(name, TEXT_SELECTOR_PROP_LOOP_OPTIONS)) {
value_set_bool(v, text_selector->loop_options);
return RET_OK;
}
@ -423,7 +425,9 @@ static ret_t text_selector_on_scroll_done(void* ctx, event_t* e) {
text_selector->wa = NULL;
if (text_selector->loop_options) {
text_selector->yoffset = text_selector_range_yoffset(text_selector->yoffset, min_yoffset, max_yoffset, item_height, empty_item_height, text_selector->loop_options);
text_selector->yoffset =
text_selector_range_yoffset(text_selector->yoffset, min_yoffset, max_yoffset, item_height,
empty_item_height, text_selector->loop_options);
}
text_selector_sync_selected_index_with_yoffset(text_selector);

View File

@ -175,14 +175,18 @@ void awtk_ios_log(const char* message, ...);
if (log_get_log_level() <= LOG_LEVEL_ERROR) printf(format, ##args)
#else
/*MSVC*/
#define log_debug(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_DEBUG) printf(format, __VA_ARGS__);fflush(stdout)
#define log_info(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_INFO) printf(format, __VA_ARGS__);fflush(stdout)
#define log_warn(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_WARN) printf(format, __VA_ARGS__);fflush(stdout)
#define log_error(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_ERROR) printf(format, __VA_ARGS__);fflush(stdout)
#define log_debug(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_DEBUG) printf(format, __VA_ARGS__); \
fflush(stdout)
#define log_info(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_INFO) printf(format, __VA_ARGS__); \
fflush(stdout)
#define log_warn(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_WARN) printf(format, __VA_ARGS__); \
fflush(stdout)
#define log_error(format, ...) \
if (log_get_log_level() <= LOG_LEVEL_ERROR) printf(format, __VA_ARGS__); \
fflush(stdout)
#endif
#elif defined(HAS_STDIO) || defined(AWTK_WEB)
#include <stdio.h>

View File

@ -288,10 +288,9 @@ ret_t label_resize_to_content(widget_t* widget, uint32_t min_w, uint32_t max_w,
tmp_w = max_w - 2 * margin;
}
}
return_value_if_fail(
label_line_parser_init(&p, c, widget->text.str, widget->text.size, c->font_size,
tmp_w, label->line_wrap) == RET_OK,
RET_BAD_PARAMS);
return_value_if_fail(label_line_parser_init(&p, c, widget->text.str, widget->text.size,
c->font_size, tmp_w, label->line_wrap) == RET_OK,
RET_BAD_PARAMS);
h = p.total_lines * line_height + 2 * margin;
h = tk_clampi(h, min_h, max_h);
@ -381,10 +380,9 @@ static ret_t label_auto_adjust_size(widget_t* widget) {
w = tmp_w + 2 * margin;
}
return_value_if_fail(
label_line_parser_init(&p, c, widget->text.str, widget->text.size, c->font_size,
tmp_w, label->line_wrap) == RET_OK,
RET_BAD_PARAMS);
return_value_if_fail(label_line_parser_init(&p, c, widget->text.str, widget->text.size,
c->font_size, tmp_w, label->line_wrap) == RET_OK,
RET_BAD_PARAMS);
widget->w = w;
widget->h = line_height * p.total_lines;

View File

@ -22,7 +22,7 @@ static ret_t application_init(void) {
data_reader_factory_set(reader_factory);
data_reader_factory_register(reader_factory, "file", data_reader_file_create);
data_writer_factory_set(writer_factory);
data_writer_factory_register(writer_factory, "file", data_writer_file_create);
@ -41,7 +41,7 @@ static ret_t application_deinit(void) {
int main(int argc, char* argv[]) {
platform_prepare();
if(argc != 3) {
if (argc != 3) {
log_info("Usage: %s ubjson_filename json_filename\n", argv[0]);
return -1;
}

View File

@ -7,7 +7,8 @@ using std::string;
TEST(RichTextParser, basic) {
const char* str = "text";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -18,7 +19,8 @@ TEST(RichTextParser, basic) {
TEST(RichTextParser, font) {
const char* str = "<font color=\"#123456\" size=\"12\" name=\"test\">text</font>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -35,7 +37,8 @@ TEST(RichTextParser, font) {
TEST(RichTextParser, b) {
const char* str = "<b>text</b>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -47,7 +50,8 @@ TEST(RichTextParser, b) {
TEST(RichTextParser, i) {
const char* str = "<i>text</i>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -59,7 +63,8 @@ TEST(RichTextParser, i) {
TEST(RichTextParser, u) {
const char* str = "<u>text</u>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -71,7 +76,8 @@ TEST(RichTextParser, u) {
TEST(RichTextParser, image) {
const char* str = "<image name=\"earth\" w=\"12\" h=\"34\"/>text";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_IMAGE);
ASSERT_EQ(node->u.image.name, string("earth"));
@ -87,7 +93,8 @@ TEST(RichTextParser, image) {
TEST(RichTextParser, bu) {
const char* str = "<b><u>text</u></b>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -100,7 +107,8 @@ TEST(RichTextParser, bu) {
TEST(RichTextParser, bui) {
const char* str = "<b><u><i>text</i></u></b>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(rich_text_node_count(node), 1);
@ -114,7 +122,8 @@ TEST(RichTextParser, bui) {
TEST(RichTextParser, bui1) {
const char* str = "<b>bold<u>underline<i>italic</i></u></b>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(node->u.text.font.bold, TRUE);
@ -135,7 +144,8 @@ TEST(RichTextParser, bui1) {
TEST(RichTextParser, bui2) {
const char* str = "<b><u><i>italic</i>underline</u>bold</b>";
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE, color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
rich_text_node_t* node = rich_text_parse(str, strlen(str), NULL, TK_DEFAULT_FONT_SIZE,
color_init(0, 0, 0, 0xff), ALIGN_V_BOTTOM);
ASSERT_EQ(node->type, RICH_TEXT_TEXT);
ASSERT_EQ(node->u.text.font.bold, TRUE);

View File

@ -22,7 +22,7 @@ static ret_t application_init(void) {
data_reader_factory_set(reader_factory);
data_reader_factory_register(reader_factory, "file", data_reader_file_create);
data_writer_factory_set(writer_factory);
data_writer_factory_register(writer_factory, "file", data_writer_file_create);
@ -41,7 +41,7 @@ static ret_t application_deinit(void) {
int main(int argc, char* argv[]) {
platform_prepare();
if(argc != 3) {
if (argc != 3) {
log_info("Usage: %s ubjson_filename json_filename\n", argv[0]);
return -1;
}