From c26370b91d13f5d3e4359c2032182655c00202bd Mon Sep 17 00:00:00 2001 From: lixianjing Date: Fri, 13 Dec 2024 15:47:40 +0800 Subject: [PATCH] fix deprecated warnings --- demos/demo_canvas_offline.c | 2 +- demos/demo_thread_app.c | 12 ++++---- demos/demo_window_animator.c | 4 +-- docs/changes.md | 1 + src/widgets/dialog_helper.c | 4 +-- tests/button_test.cc | 2 +- tests/fscript_widget_test.cc | 4 +-- tests/image_animation_test.cc | 2 +- tests/scroll_view_test.cc | 2 +- tests/self_layouter_default_test.cc | 48 ++++++++++++++--------------- tests/switch_test.cc | 2 +- tests/ui_serializer_test.cc | 4 +-- 12 files changed, 44 insertions(+), 43 deletions(-) diff --git a/demos/demo_canvas_offline.c b/demos/demo_canvas_offline.c index a93dc707d5..87900608ad 100644 --- a/demos/demo_canvas_offline.c +++ b/demos/demo_canvas_offline.c @@ -114,7 +114,7 @@ ret_t application_init() { widget_t* win = window_create(NULL, 0, 0, 0, 0); widget_t* canvas_widget = canvas_widget_create(win, 0, 0, win->w, win->h); widget_t* button = button_create(win, 0, 0, 0, 0); - widget_set_self_layout_params(button, "c", "b", "100", "40"); + widget_set_self_layout(button, "default(x=c,y=b,w=100,h=40)"); widget_on(win, EVT_DESTROY, window_on_destroy, NULL); /* 创建离线的 canvas */ diff --git a/demos/demo_thread_app.c b/demos/demo_thread_app.c index 7e98a3bbe6..c146541768 100644 --- a/demos/demo_thread_app.c +++ b/demos/demo_thread_app.c @@ -139,15 +139,15 @@ ret_t application_init() { widget_t* progress_bar4 = progress_bar_create(win, 0, 0, 0, 0); widget_set_text(label, L"Update progressbar in non GUI thread"); - widget_set_self_layout_params(label, "center", "middle:-90", "80%", "30"); + widget_set_self_layout(label, "default(x=center,y=middle:-90,w=80%,h=30)"); - widget_set_self_layout_params(progress_bar1, "center", "middle:-60", "80%", "20"); - widget_set_self_layout_params(progress_bar2, "center", "middle:-30", "80%", "20"); - widget_set_self_layout_params(progress_bar3, "center", "middle:0", "80%", "20"); - widget_set_self_layout_params(progress_bar4, "center", "middle:30", "80%", "20"); + widget_set_self_layout(progress_bar1, "default(x=center,y=middle:-60,w=80%,h=20)"); + widget_set_self_layout(progress_bar2, "default(x=center,y=middle:-30,w=80%,h=20)"); + widget_set_self_layout(progress_bar3, "default(x=center,y=middle:0,w=80%,h=20)"); + widget_set_self_layout(progress_bar4, "default(x=center,y=middle:30,w=80%,h=20)"); widget_set_text(close, L"close"); - widget_set_self_layout_params(close, "center", "bottom:30", "50%", "30"); + widget_set_self_layout(close, "default(x=center,y=bottom:30,w=50%,h=30)"); thread1 = tk_thread_create(test_thread1, progress_bar1); tk_thread_start(thread1); diff --git a/demos/demo_window_animator.c b/demos/demo_window_animator.c index 7cc7fb56fb..8a30c6e75f 100644 --- a/demos/demo_window_animator.c +++ b/demos/demo_window_animator.c @@ -87,9 +87,9 @@ static ret_t new_window_set_param(widget_t* new_win, widget_t* curr_win) { widget_set_prop_bool(new_win, WIDGET_PROP_DISABLE_ANIM, FALSE); widget_set_prop_str(new_win, WIDGET_PROP_ANIM_HINT, anim); if (tk_str_eq(anim_hint, "popup")) { - widget_set_self_layout_params(new_win, NULL, "b:20", NULL, NULL); + widget_set_self_layout(new_win, "default(y=b:20)"); } else if (tk_str_eq(anim_hint, "popdown")) { - widget_set_self_layout_params(new_win, NULL, "20", NULL, NULL); + widget_set_self_layout(new_win, "default(y=20)"); } log_debug("%s\r\n", anim); } else { diff --git a/docs/changes.md b/docs/changes.md index 904bd163a1..02b96240cb 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,7 @@ 2024/12/13 * 增加EVT\_NATIVE\_WINDOW\_FOCUS\_GAINED(感谢兆坤提供补丁) + * 用widget\_set\_self\_layout替换widget\_set\_self\_layout\_params(感谢兆坤提供补丁) 2024/12/10 * 修复scroll\_bar\_d不指定max时控件内的dragger不显示的问题(感谢雨欣提供补丁) diff --git a/src/widgets/dialog_helper.c b/src/widgets/dialog_helper.c index 57a2479158..a7461ebeeb 100644 --- a/src/widgets/dialog_helper.c +++ b/src/widgets/dialog_helper.c @@ -137,13 +137,13 @@ static widget_t* dialog_create_simple_ex(widget_t* parent, xy_t x, xy_t y, wh_t widget_set_name(title, DIALOG_CHILD_TITLE); widget_set_tr_text(title, stitle); - widget_set_self_layout_params(title, "0", "0", "100%", "30"); + widget_set_self_layout(title, "default(x=0,y=0,w=100%,h=30)"); client = dialog_client_create(widget, 0, 0, 0, 0); goto_error_if_fail(client != NULL); widget_set_name(client, DIALOG_CHILD_CLIENT); - widget_set_self_layout_params(client, "0", "bottom", "100%", "-30"); + widget_set_self_layout(client, "default(x=0,y=bottom,w=100%,h=-30)"); return widget; error: diff --git a/tests/button_test.cc b/tests/button_test.cc index 7215ffaab8..aa0f0f7711 100644 --- a/tests/button_test.cc +++ b/tests/button_test.cc @@ -54,7 +54,7 @@ TEST(Button, clone) { str_init(&str, 0); value_set_int(&v1, 200); ASSERT_EQ(widget_set_prop(w1, WIDGET_PROP_REPEAT, &v1), RET_OK); - widget_set_self_layout_params(w1, "1", "2", "3", "4"); + widget_set_self_layout(w1, "default(x=1,y=2,w=3,h=4)"); widget_set_children_layout(w1, "default(r=0,c=0,x=10,y=10,s=10)"); widget_set_sensitive(w1, FALSE); widget_set_floating(w1, TRUE); diff --git a/tests/fscript_widget_test.cc b/tests/fscript_widget_test.cc index c9c8c55099..5a0373f793 100644 --- a/tests/fscript_widget_test.cc +++ b/tests/fscript_widget_test.cc @@ -56,7 +56,7 @@ TEST(FScriptWidget, layout) { widget_t* win = window_create(NULL, 0, 0, 0, 0); widget_t* widget = progress_bar_create(win, 0, 0, w, h); - widget_set_self_layout_params(widget, "c", "m", NULL, NULL); + widget_set_self_layout(widget, "default(x=c,y=m)"); tk_object_set_prop_pointer(obj, STR_PROP_SELF, widget); fscript_eval(obj, "widget_layout('self')", &v); ASSERT_EQ(widget->x, (wm->w - w) / 2); @@ -65,7 +65,7 @@ TEST(FScriptWidget, layout) { ASSERT_EQ(widget->h, h); ((window_base_t*)win)->need_relayout = FALSE; - widget_set_self_layout_params(widget, "c:10", "m:10", NULL, NULL); + widget_set_self_layout(widget, "default(x=c:10,y=m:10)"); tk_object_set_prop_pointer(obj, STR_PROP_SELF, widget); fscript_eval(obj, "widget_request_relayout('self')", &v); ASSERT_EQ(widget->x, (wm->w - w) / 2); diff --git a/tests/image_animation_test.cc b/tests/image_animation_test.cc index 43c7276e3b..0a0f60cb22 100644 --- a/tests/image_animation_test.cc +++ b/tests/image_animation_test.cc @@ -60,7 +60,7 @@ TEST(ImageAnimation, clone) { value_set_int(&v1, 200); ASSERT_EQ(widget_set_prop(w1, IMAGE_ANIMATION_PROP_INTERVAL, &v1), RET_OK); - widget_set_self_layout_params(w1, "1", "2", "3", "4"); + widget_set_self_layout(w1, "default(x=1,y=2,w=3,h=4)"); widget_set_children_layout(w1, "default(r=0, c=0, x=10, y=10, s=10)"); ASSERT_EQ(image_animation_cast(w1), w1); diff --git a/tests/scroll_view_test.cc b/tests/scroll_view_test.cc index 313a2bcc72..b58d66e8c8 100644 --- a/tests/scroll_view_test.cc +++ b/tests/scroll_view_test.cc @@ -55,7 +55,7 @@ TEST(ScrollView, layout) { ASSERT_EQ(scroll_view_set_virtual_w(widget, 400), RET_OK); ASSERT_EQ(scroll_view_set_virtual_h(widget, 800), RET_OK); - widget_set_self_layout_params(button, "right", "bottom", "10%", "10%"); + widget_set_self_layout(button, "default(x=right,y=bottom,w=10%,h=10%)"); widget_layout(widget); ASSERT_EQ(button->x, 360); diff --git a/tests/self_layouter_default_test.cc b/tests/self_layouter_default_test.cc index 5631943711..fb1376e3ec 100644 --- a/tests/self_layouter_default_test.cc +++ b/tests/self_layouter_default_test.cc @@ -674,80 +674,80 @@ TEST(SelfLayoutDefault, reinit) { widget_destroy(w); } -TEST(SelfLayoutDefault, set_self_layout_params) { +TEST(SelfLayoutDefault, set_self_layout) { widget_t* win = window_create(NULL, 0, 0, 400, 300); widget_t* btn = button_create(win, 10, 20, 30, 40); - widget_set_self_layout_params(btn, "c:100", NULL, NULL, NULL); + widget_set_self_layout(btn, "default(x=c:100)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, "b:10", NULL, NULL); + widget_set_self_layout(btn, "default(y=b:10)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(y=b:10)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, NULL, "100%", NULL); + widget_set_self_layout(btn, "default(w=100%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(w=100%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, NULL, NULL, "10%"); + widget_set_self_layout(btn, "default(h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(h=10%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, "c:100", "b:10", NULL, NULL); + widget_set_self_layout(btn, "default(x=c:100, y=b:10)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100, y=b:10)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, "c:100", NULL, "100%", NULL); + widget_set_self_layout(btn, "default(x=c:100, w=100%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100, w=100%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, "c:100", NULL, NULL, "10%"); + widget_set_self_layout(btn, "default(x=c:100, h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100, h=10%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, "b:10", "100%", NULL); + widget_set_self_layout(btn, "default(y=b:10, w=100%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(y=b:10, w=100%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, "b:10", NULL, "10%"); + widget_set_self_layout(btn, "default(y=b:10, h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(y=b:10, h=10%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, NULL, "100%", "10%"); + widget_set_self_layout(btn, "default(w=100%, h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(w=100%, h=10%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, "c:100", "b:10", "100%", NULL); + widget_set_self_layout(btn, "default(x=c:100, y=b:10, w=100%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100, y=b:10, w=100%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, "c:100", "b:10", NULL, "10%"); + widget_set_self_layout(btn, "default(x=c:100, y=b:10, h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100, y=b:10, h=10%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, NULL, "b:10", "100%", "10%"); + widget_set_self_layout(btn, "default(y=b:10, w=100%, h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(y=b:10, w=100%, h=10%)"); self_layouter_destroy(btn->self_layout); btn->self_layout = NULL; - widget_set_self_layout_params(btn, "c:100", NULL, "100%", "10%"); + widget_set_self_layout(btn, "default(x=c:100, w=100%, h=10%)"); ASSERT_EQ(string(btn->self_layout->params.str), "default(x=c:100, w=100%, h=10%)"); } -TEST(SelfLayoutDefault, set_self_layout_params2) { +TEST(SelfLayoutDefault, set_self_layout2) { widget_t* win = overlay_create(NULL, 0, 0, 200, 100); widget_t* btn = button_create(win, 0, 0, 0, 0); widget_set_self_layout(btn, "default(x=r, y=b, w=50%, h=10%)"); @@ -761,22 +761,22 @@ TEST(SelfLayoutDefault, set_self_layout_params2) { ASSERT_EQ(widget_get_prop_int(btn, "w", 0), 100); ASSERT_EQ(widget_get_prop_int(btn, "h", 0), 10); - widget_set_self_layout_params(btn, "c", NULL, NULL, NULL); + widget_set_self_layout(btn, "default(x=c)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "x", 0), 50); - widget_set_self_layout_params(btn, NULL, "m", NULL, NULL); + widget_set_self_layout(btn, "default(x=c,y=m)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "x", 0), 50); ASSERT_EQ(widget_get_prop_int(btn, "y", 0), 45); - widget_set_self_layout_params(btn, NULL, NULL, "100%", NULL); + widget_set_self_layout(btn, "default(x=c,y=m,w=100%)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "x", 0), 0); ASSERT_EQ(widget_get_prop_int(btn, "y", 0), 45); ASSERT_EQ(widget_get_prop_int(btn, "w", 0), 200); - widget_set_self_layout_params(btn, NULL, NULL, NULL, "100%"); + widget_set_self_layout(btn, "default(x=c,y=m,w=100%,h=100%)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "x", 0), 0); ASSERT_EQ(widget_get_prop_int(btn, "y", 0), 0); @@ -802,18 +802,18 @@ TEST(SelfLayoutDefault, set_self_layout_params2) { ASSERT_EQ(self_layouter_get_param_int(layouter, "w_attr", 0), W_ATTR_UNDEF); ASSERT_EQ(self_layouter_get_param_int(layouter, "h_attr", 0), W_ATTR_UNDEF); - widget_set_self_layout_params(btn, "100", NULL, NULL, NULL); + widget_set_self_layout(btn, "default(x=100)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "x", 0), 100); - widget_set_self_layout_params(btn, "c", NULL, "100", NULL); + widget_set_self_layout(btn, "default(x=c,w=100)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "x", 0), 50); ASSERT_EQ(widget_get_prop_int(btn, "w", 0), 100); - widget_set_self_layout_params(btn, NULL, "10", NULL, NULL); + widget_set_self_layout(btn, "default(y=10)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "y", 0), 10); - widget_set_self_layout_params(btn, NULL, "m", NULL, "50"); + widget_set_self_layout(btn, "default(y=m,h=50)"); ASSERT_EQ(widget_layout_self(btn), RET_OK); ASSERT_EQ(widget_get_prop_int(btn, "y", 0), 25); ASSERT_EQ(widget_get_prop_int(btn, "h", 0), 50); diff --git a/tests/switch_test.cc b/tests/switch_test.cc index a5e9d1a614..92b6890f1e 100644 --- a/tests/switch_test.cc +++ b/tests/switch_test.cc @@ -37,7 +37,7 @@ TEST(Switch, clone) { value_set_int(&v1, 200); ASSERT_EQ(widget_set_prop(w1, WIDGET_PROP_REPEAT, &v1), RET_OK); - widget_set_self_layout_params(w1, "1", "2", "3", "4"); + widget_set_self_layout(w1, "default(x=1,y=2,w=3,h=4)"); widget_set_children_layout(w1, "default(r=0, c=0, x=10, y=10, s=10)"); ASSERT_EQ(switch_cast(w1), w1); diff --git a/tests/ui_serializer_test.cc b/tests/ui_serializer_test.cc index 0d686d8165..8394dacf7e 100644 --- a/tests/ui_serializer_test.cc +++ b/tests/ui_serializer_test.cc @@ -43,7 +43,7 @@ TEST(UISerializer, layout_self) { str_t str; widget_t* w = button_create(NULL, 10, 20, 30, 40); - widget_set_self_layout_params(w, "right:100", "middle:10", "fill", "10%"); + widget_set_self_layout(w, "default(x=right:100,y=middle:10,w=fill,h=10%)"); str_init(&str, 1024); widget_to_xml(w, &str); @@ -60,7 +60,7 @@ TEST(UISerializer, layout_self1) { str_t str; widget_t* w = button_create(NULL, 10, 20, 30, 40); - widget_set_self_layout_params(w, "center:100", "bottom:10", "fill", "10%"); + widget_set_self_layout(w, "default(x=center:100,y=bottom:10,w=fill,h=10%)"); str_init(&str, 1024); widget_to_xml(w, &str);