From d96c0ec5375d589c5fcba6ce173e424bf58f6143 Mon Sep 17 00:00:00 2001 From: jim Date: Mon, 12 Mar 2018 07:12:35 +0800 Subject: [PATCH] improve layout --- src/base/layout.c | 15 ++++++++------- src/ui_loader/ui_builder_default.c | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/base/layout.c b/src/base/layout.c index 9c8ef32dc..c3c368fd1 100644 --- a/src/base/layout.c +++ b/src/base/layout.c @@ -28,12 +28,12 @@ widget_layout_t* widget_layout_parse(widget_layout_t* layout, const char* x, con memset(layout, 0x00, sizeof(*layout)); if (x != NULL) { - if (strstr(x, "center") != NULL) { + if (x[0] == 'c') { if (x[6] == ':') { layout->x = atoi(x + 7); } layout->x_attr = X_ATTR_CENTER; - } else if (strstr(x, "right") != NULL) { + } else if (x[0] == 'r') { if (x[5] == ':') { layout->x = atoi(x + 6); } @@ -50,12 +50,12 @@ widget_layout_t* widget_layout_parse(widget_layout_t* layout, const char* x, con } if (y != NULL) { - if (strstr(y, "middle") != NULL) { + if (y[0] == 'm') { if (y[6] == ':') { layout->y = atoi(y + 7); } layout->y_attr = Y_ATTR_MIDDLE; - } else if (strstr(y, "bottom") != NULL) { + } else if (y[0] == 'b') { if (y[6] == ':') { layout->y = atoi(y + 7); } @@ -251,7 +251,7 @@ ret_t widget_layout_children(widget_t* widget) { iter = children[i]; widget_move_resize(iter, x, y, iter->w, h); x += iter->w + cell_spacing; - return_value_if_fail(x < widget->w, RET_BAD_PARAMS); + return_value_if_fail(x <= widget->w, RET_BAD_PARAMS); } for (i = 0; i < n; i++) { @@ -270,9 +270,9 @@ ret_t widget_layout_children(widget_t* widget) { for (i = 0; i < n; i++) { iter = children[i]; + return_value_if_fail(y <= widget->h, RET_BAD_PARAMS); widget_move_resize(iter, x, y, w, iter->h); y += iter->h + cell_spacing; - return_value_if_fail(y < widget->h, RET_BAD_PARAMS); } for (i = 0; i < n; i++) { @@ -293,6 +293,8 @@ ret_t widget_layout_children(widget_t* widget) { for (i = 0; i < n; i++) { iter = children[i]; + return_value_if_fail(y <= widget->h, RET_BAD_PARAMS); + widget_move_resize(iter, x, y, item_w, item_h); c++; if (c == cols) { @@ -303,7 +305,6 @@ ret_t widget_layout_children(widget_t* widget) { } else { x += item_w + cell_spacing; } - return_value_if_fail(y < widget->h, RET_BAD_PARAMS); } for (i = 0; i < n; i++) { diff --git a/src/ui_loader/ui_builder_default.c b/src/ui_loader/ui_builder_default.c index 0f0cf62c7..6e0ff712f 100644 --- a/src/ui_loader/ui_builder_default.c +++ b/src/ui_loader/ui_builder_default.c @@ -152,6 +152,9 @@ static ret_t ui_builder_default_on_widget_prop_end(ui_builder_t* b) { static ret_t ui_builder_default_on_widget_end(ui_builder_t* b) { b->widget = b->widget->parent; + if(b->widget == b->root) { + widget_layout(b->root); + } return RET_OK; } @@ -177,7 +180,6 @@ widget_t* window_open(const char* name) { ui_loader_load(loader, ui->data, ui->size, builder); resource_manager_unref(ui); - widget_layout(builder->root); return builder->root; }