format code

This commit is contained in:
lixianjing 2022-11-15 17:34:36 +08:00
parent c28ad0d4e8
commit 371c5e857b
24 changed files with 71 additions and 62 deletions

View File

@ -130,8 +130,9 @@ static ret_t update_title_on_timer(const timer_info_t* info) {
return RET_REPEAT;
}
static ret_t popup_move_to_foreground(void* ctx, event_t* e){
window_manager_switch_to(window_manager(), window_manager_get_top_main_window(window_manager()), ctx, FALSE);
static ret_t popup_move_to_foreground(void* ctx, event_t* e) {
window_manager_switch_to(window_manager(), window_manager_get_top_main_window(window_manager()),
ctx, FALSE);
return RET_OK;
}
@ -203,7 +204,7 @@ static ret_t on_paint_linear_gradient(void* ctx, event_t* e) {
vgcanvas_translate(vg, 0, r.y + r.h);
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
ecolor = color_init(0, 0, 0xff, 0xff);
vgcanvas_set_fill_linear_gradient(vg, r.x + r.w*0.6, r.y, r.x + r.w*0.4, r.y, scolor, ecolor);
vgcanvas_set_fill_linear_gradient(vg, r.x + r.w * 0.6, r.y, r.x + r.w * 0.4, r.y, scolor, ecolor);
vgcanvas_fill(vg);
vgcanvas_translate(vg, -(r.x + r.w), 0);

View File

@ -35,7 +35,8 @@ ret_t locale_info_set(locale_info_t* locale_info) {
return RET_OK;
}
static locale_info_t* locale_info_init(locale_info_t* locale_info, const char* language, const char* country, assets_manager_t* am) {
static locale_info_t* locale_info_init(locale_info_t* locale_info, const char* language,
const char* country, assets_manager_t* am) {
return_value_if_fail(locale_info != NULL, NULL);
locale_info->assets_manager = am;
@ -45,7 +46,8 @@ static locale_info_t* locale_info_init(locale_info_t* locale_info, const char* l
return locale_info;
}
static locale_info_t* locale_info_create_internal(const char* language, const char* country, assets_manager_t* am) {
static locale_info_t* locale_info_create_internal(const char* language, const char* country,
assets_manager_t* am) {
locale_info_t* locale_info = TKMEM_ZALLOC(locale_info_t);
return locale_info_init(locale_info, language, country, am);
}

View File

@ -309,9 +309,11 @@ typedef struct _widget_animator_t widget_animator_t;
#define TK_GET_VTABLE(vt) vt##_get_widget_vtable()
#define TK_GET_PARENT_VTABLE(vt) vt##_get_widget_vtable
#define TK_PARENT_VTABLE(vt) NULL, .get_parent_vt = TK_GET_PARENT_VTABLE(vt)
#define TK_DECL_VTABLE(vt) \
extern const widget_vtable_t g_##vt##_vtable; \
const widget_vtable_t* vt##_get_widget_vtable(void) { return &g_##vt##_vtable; } \
#define TK_DECL_VTABLE(vt) \
extern const widget_vtable_t g_##vt##_vtable; \
const widget_vtable_t* vt##_get_widget_vtable(void) { \
return &g_##vt##_vtable; \
} \
const widget_vtable_t g_##vt##_vtable
#define TK_EXTERN_VTABLE(vt) const widget_vtable_t* vt##_get_widget_vtable(void);

View File

@ -2249,7 +2249,7 @@ ret_t widget_set_prop(widget_t* widget, const char* name, const value_t* v) {
} else {
log_debug("not found event %s\n", name);
}
} else
} else
#endif /*WITHOUT_FSCRIPT*/
{
ret = tk_object_set_prop(widget->custom_props, name, v);

View File

@ -327,4 +327,3 @@ TK_DECL_VTABLE(widget) = {.size = sizeof(widget_t),
.set_prop = widget_set_prop_default,
.find_target = widget_find_target_default,
.on_destroy = widget_on_destroy_default};

View File

@ -91,7 +91,7 @@ typedef struct _candidates_t {
* style名称
*/
char* button_style;
/**
* @property {bool_t} enable_preview
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]

View File

@ -54,15 +54,12 @@ static ret_t line_number_do_paint_self(widget_t* widget, canvas_t* c) {
if (style_is_valid(style)) {
uint32_t line_index = 0;
color_t trans = color_init(0, 0, 0, 0);
widget_prepare_text_style_ex(widget, c, trans, NULL, TK_DEFAULT_FONT_SIZE,
ALIGN_H_RIGHT, ALIGN_V_TOP);
color_t active_bg =
style_get_color(style, LINE_NUMBER_STYLE_ACTIVE_LINE_BG_COLOR, trans);
color_t highlight_bg =
style_get_color(style, LINE_NUMBER_STYLE_HIGHLIGHT_LINE_BG_COLOR, trans);
const char* highlight_shape =
style_get_str(style, LINE_NUMBER_STYLE_HIGHLIGHT_LINE_SHAPE,
LINE_NUMBER_STYLE_HIGHLIGHT_LINE_SHAPE_CIRCLE);
widget_prepare_text_style_ex(widget, c, trans, NULL, TK_DEFAULT_FONT_SIZE, ALIGN_H_RIGHT,
ALIGN_V_TOP);
color_t active_bg = style_get_color(style, LINE_NUMBER_STYLE_ACTIVE_LINE_BG_COLOR, trans);
color_t highlight_bg = style_get_color(style, LINE_NUMBER_STYLE_HIGHLIGHT_LINE_BG_COLOR, trans);
const char* highlight_shape = style_get_str(style, LINE_NUMBER_STYLE_HIGHLIGHT_LINE_SHAPE,
LINE_NUMBER_STYLE_HIGHLIGHT_LINE_SHAPE_CIRCLE);
while (1) {
if (line > 0) {
@ -89,16 +86,16 @@ static ret_t line_number_do_paint_self(widget_t* widget, canvas_t* c) {
canvas_set_fill_color(c, highlight_bg);
if (highlight_shape[0] == 'c') {
rect_t save_r = r;
int32_t size = tk_min(r.w, r.h)/2;
int32_t dx = (r.w - size)/2;
int32_t dy = (r.h - size)/2;
int32_t rr = size/2;
int32_t size = tk_min(r.w, r.h) / 2;
int32_t dx = (r.w - size) / 2;
int32_t dy = (r.h - size) / 2;
int32_t rr = size / 2;
r.x += dx;
r.y += dy;
r.w = size;
r.h = size;
canvas_fill_rounded_rect(c, &r, &r, &highlight_bg, rr);
canvas_fill_rounded_rect(c, &r, &r, &highlight_bg, rr);
r = save_r;
} else {
canvas_fill_rect(c, r.x, r.y, r.w, r.h);

View File

@ -955,7 +955,8 @@ static ret_t mledit_on_scroll_bar_value_changed(void* ctx, event_t* e) {
return_value_if_fail(vscroll_bar != NULL && scroll_bar != NULL, RET_BAD_PARAMS);
value = widget_get_value(vscroll_bar);
value = (int64_t)(scroll_bar->virtual_size - vscroll_bar->h) * (int64_t)value / scroll_bar->virtual_size;
value = (int64_t)(scroll_bar->virtual_size - vscroll_bar->h) * (int64_t)value /
scroll_bar->virtual_size;
if (mledit->overwrite && mledit->max_chars == 0 && mledit->max_lines != 0) {
if (value == scroll_bar->virtual_size - vscroll_bar->h) {

View File

@ -179,7 +179,7 @@ static ret_t list_view_on_event(widget_t* widget, event_t* e) {
}
break;
}
case EVT_KEY_UP :
case EVT_KEY_UP:
case EVT_POINTER_UP: {
pointer_event_t* evt = (pointer_event_t*)e;
list_view_on_pointer_up(list_view, evt);

View File

@ -933,8 +933,9 @@ static ret_t slide_view_set_active_animate(widget_t* widget, uint32_t active) {
}
old_active = slide_view->active;
if ((old_active < active && !(slide_view->loop && old_active == 0 && active == widget->children->size - 1)) ||
(slide_view->loop && active == 0 && old_active == widget->children->size - 1)) {
if ((old_active < active &&
!(slide_view->loop && old_active == 0 && active == widget->children->size - 1)) ||
(slide_view->loop && active == 0 && old_active == widget->children->size - 1)) {
slide_view->prev = widget_get_child(widget, old_active);
slide_view->next = widget_get_child(widget, active);
xoffset_end = slide_view->vertical ? 0 : widget->w;

View File

@ -58,7 +58,7 @@ static ret_t func_bit_set(fscript_t* fscript, fscript_args_t* args, value_t* res
FSCRIPT_FUNC_CHECK(args->size == 2, RET_BAD_PARAMS);
value = args->args;
n = value_uint32(args->args + 1);
return value_set_bit(value, result, n, TRUE);
}
@ -95,7 +95,7 @@ static ret_t func_bit_get(fscript_t* fscript, fscript_args_t* args, value_t* res
value = args->args;
n = value_uint32(args->args + 1);
return value_get_bit(value, result, n);
return value_get_bit(value, result, n);
}
static ret_t func_bit_and(fscript_t* fscript, fscript_args_t* args, value_t* result) {

View File

@ -77,7 +77,7 @@ tk_object_t* fscript_module_create_with_data(const char* data) {
value_set_int(&v, 0);
fscript_exec(fscript, &v);
value_reset(&v);
/*fix loop ref count*/
o->ref_count = 1;

View File

@ -212,7 +212,8 @@ static ret_t main_loop_sdl2_dispatch_window_event(main_loop_simple_t* loop, SDL_
native_window_info_t info;
event_t e = event_init(EVT_NATIVE_WINDOW_RESIZED, NULL);
SDL_Window* win = SDL_GetWindowFromID(event->window.windowID);
native_window_t* native_window = (native_window_t*)widget_get_prop_pointer(window_manager(), WIDGET_PROP_NATIVE_WINDOW);
native_window_t* native_window =
(native_window_t*)widget_get_prop_pointer(window_manager(), WIDGET_PROP_NATIVE_WINDOW);
native_window_get_info(native_window, &info);
system_info_set_lcd_w(system_info(), info.w);
system_info_set_lcd_h(system_info(), info.h);

View File

@ -1181,7 +1181,7 @@ static ret_t fscript_parser_parse_id_or_number(fscript_parser_t* parser, token_t
if (tk_isxdigit(c) || tk_isdigit(c) || tk_isalpha(c) || c == '.' || c == '_' || c == '[' ||
c == ']' || c == '#') {
str_append_char(str, c);
} else if(tk_isspace(c)) {
} else if (tk_isspace(c)) {
break;
} else {
int32_t n = tk_utf8_get_bytes_of_leading((uint8_t)c);

View File

@ -973,7 +973,8 @@ ret_t tk_object_set_prop_uint64(tk_object_t* obj, const char* name, uint64_t val
*
* @return {ret_t} RET_OK表示成功
*/
ret_t tk_object_to_json(tk_object_t* obj, str_t* json, uint32_t indent, uint32_t level, bool_t oneline);
ret_t tk_object_to_json(tk_object_t* obj, str_t* json, uint32_t indent, uint32_t level,
bool_t oneline);
/**
* @method tk_object_get_child_object

View File

@ -408,7 +408,7 @@ enum { TK_NAME_LEN = 31, TK_FUNC_NAME_LEN = 63 };
#endif /*M_PI*/
#ifndef M_E
#define M_E 2.71828f
#define M_E 2.71828f
#endif /*M_E*/
#ifndef M_SQRT2

View File

@ -59,7 +59,7 @@ wchar_t* wcs_cpy(wchar_t* s1, const wchar_t* s2) {
return s1;
}
int wcs_ncmp(const wchar_t *s1, const wchar_t *s2, uint32_t n) {
int wcs_ncmp(const wchar_t* s1, const wchar_t* s2, uint32_t n) {
wchar_t c1 = L'\0';
wchar_t c2 = L'\0';
return_value_if_fail(s1 != NULL && s2 != NULL, -1);

View File

@ -97,7 +97,7 @@ typedef struct _button_t {
*
*/
bool_t enable_long_press;
/**
* @property {bool_t} enable_preview
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]

View File

@ -58,7 +58,8 @@ static ret_t check_button_on_event(widget_t* widget, event_t* e) {
pointer_event_t* evt = (pointer_event_t*)e;
if (check_button->pressed && widget_is_point_in(widget, evt->x, evt->y, FALSE)) {
pointer_event_t click;
ret = widget_dispatch(widget, pointer_event_init(&click, EVT_CLICK, widget, evt->x, evt->y));
ret =
widget_dispatch(widget, pointer_event_init(&click, EVT_CLICK, widget, evt->x, evt->y));
}
check_button->pressed = FALSE;

View File

@ -599,7 +599,8 @@ ret_t combo_box_combobox_popup_on_close_func(void* ctx, event_t* e) {
combo_box_t* combo_box = COMBO_BOX(ctx);
return_value_if_fail(combo_box != NULL, RET_BAD_PARAMS);
widget_off_by_func(window_manager(), EVT_WIDGET_WILL_RESTACK_CHILD, combo_box_popup_restack, combo_box);
widget_off_by_func(window_manager(), EVT_WIDGET_WILL_RESTACK_CHILD, combo_box_popup_restack,
combo_box);
combo_box->combobox_popup = NULL;
return RET_OK;

View File

@ -147,7 +147,8 @@ widget_t* digit_clock_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
digit_clock_update_time(widget);
widget_add_timer(widget, digit_clock_on_timer, 1000);
wstr_init(&(digit_clock->last_time), 32);
digit_clock->local_changed_event_id = locale_info_on(locale_info(), EVT_LOCALE_CHANGED, digit_clock_on_display_time, widget);
digit_clock->local_changed_event_id =
locale_info_on(locale_info(), EVT_LOCALE_CHANGED, digit_clock_on_display_time, widget);
return widget;
}

View File

@ -436,7 +436,7 @@ TEST(FScript, bit_xor) {
fscript_eval(obj, "^(1, 1)", &v);
ASSERT_EQ(value_int(&v), 0);
value_reset(&v);
fscript_eval(obj, "^(1, 0)", &v);
ASSERT_EQ(value_int(&v), 1);
value_reset(&v);
@ -3147,11 +3147,10 @@ TEST(FScript, id1) {
fscript_eval(obj, "var t = 2 \n//aa\n//bb\nt", &v);
ASSERT_EQ(value_int(&v), 2);
value_reset(&v);
fscript_eval(obj, "var t = 3 \t//aa\n//bb\nt", &v);
ASSERT_EQ(value_int(&v), 3);
value_reset(&v);
TK_OBJECT_UNREF(obj);
}

View File

@ -644,11 +644,11 @@ TEST(ObjectDefault, to_json1) {
tk_object_t* obj = object_default_create();
str_init(&str, 100);
str_clear(&str);
tk_object_to_json(obj, &str, 0, 0, TRUE);
ASSERT_STREQ(str.str, "{}");
str_clear(&str);
tk_object_to_json(obj, &str, 2, 0, FALSE);
ASSERT_STREQ(str.str, "{\n}");
@ -657,32 +657,32 @@ TEST(ObjectDefault, to_json1) {
str_clear(&str);
tk_object_to_json(obj, &str, 2, 0, TRUE);
ASSERT_STREQ(str.str, "{\"name\": \"jim\"}");
str_clear(&str);
tk_object_to_json(obj, &str, 1, 0, FALSE);
ASSERT_STREQ(str.str, "{\n \"name\": \"jim\"\n}");
str_clear(&str);
tk_object_to_json(obj, &str, 2, 0, FALSE);
ASSERT_STREQ(str.str, "{\n \"name\": \"jim\"\n}");
str_clear(&str);
tk_object_to_json(obj, &str, 2, 1, FALSE);
ASSERT_STREQ(str.str, " {\n \"name\": \"jim\"\n }");
tk_object_set_prop_int(obj, "age", 100);
str_clear(&str);
tk_object_to_json(obj, &str, 2, 0, TRUE);
ASSERT_STREQ(str.str, "{\"age\": \"100\",\"name\": \"jim\"}");
str_clear(&str);
tk_object_to_json(obj, &str, 1, 0, FALSE);
ASSERT_STREQ(str.str, "{\n \"age\": \"100\",\n \"name\": \"jim\"\n}");
str_clear(&str);
tk_object_to_json(obj, &str, 2, 0, FALSE);
ASSERT_STREQ(str.str, "{\n \"age\": \"100\",\n \"name\": \"jim\"\n}");
str_clear(&str);
tk_object_to_json(obj, &str, 2, 1, FALSE);
ASSERT_STREQ(str.str, " {\n \"age\": \"100\",\n \"name\": \"jim\"\n }");
@ -690,10 +690,12 @@ TEST(ObjectDefault, to_json1) {
tk_object_t* detail = object_default_create();
tk_object_set_prop_str(detail, "city", "sz");
tk_object_set_prop_object(obj, "detail", detail);
str_clear(&str);
tk_object_to_json(obj, &str, 2, 0, FALSE);
ASSERT_STREQ(str.str, "{\n \"age\": \"100\",\n \"detail\": {\n \"city\": \"sz\"\n },\n \"name\": \"jim\"\n}");
ASSERT_STREQ(str.str,
"{\n \"age\": \"100\",\n \"detail\": {\n \"city\": \"sz\"\n },\n "
"\"name\": \"jim\"\n}");
str_reset(&str);
TK_OBJECT_UNREF(obj);

View File

@ -630,25 +630,25 @@ TEST(Str, from) {
ASSERT_EQ(str_from_int(s, 123), RET_OK);
ASSERT_EQ(str_eq(s, "123"), TRUE);
ASSERT_EQ(str_from_int(s, -123), RET_OK);
ASSERT_EQ(str_eq(s, "-123"), TRUE);
ASSERT_EQ(str_from_uint32(s, 123), RET_OK);
ASSERT_EQ(str_eq(s, "123"), TRUE);
ASSERT_EQ(str_from_uint32(s, 0xffffffff), RET_OK);
ASSERT_EQ(tk_atoul(s->str), 0xffffffff);
ASSERT_EQ(tk_atoul(s->str), 0xffffffff);
ASSERT_EQ(str_from_int64(s, 1234), RET_OK);
ASSERT_EQ(str_eq(s, "1234"), TRUE);
ASSERT_EQ(str_from_int64(s, -1234), RET_OK);
ASSERT_EQ(str_eq(s, "-1234"), TRUE);
ASSERT_EQ(str_from_uint64(s, 12345), RET_OK);
ASSERT_EQ(str_eq(s, "12345"), TRUE);
ASSERT_EQ(str_from_float(s, 1.1), RET_OK);
ASSERT_STREQ(s->str, "1.100000");