improve layout

This commit is contained in:
lixianjing 2023-11-15 17:54:27 +08:00
parent 04e8acf1f4
commit c959d931ea
4 changed files with 16 additions and 14 deletions

View File

@ -1,4 +1,7 @@
# 最新动态
2023/11/15
* 修复layout的auto\_adjust\_size不触发修改事件的问题以及增加判断auto\_adjust\_size(感谢智明提供补丁)
2023/11/14
* 导出darray\_bsearch\_index\_ex接口(感谢雨欣提供补丁)
* 完善生态页面内容(感谢陈谭提供补丁)

View File

@ -34,7 +34,7 @@ const char* self_layouter_to_string(self_layouter_t* layouter) {
ret_t self_layouter_layout(self_layouter_t* layouter, widget_t* widget, rect_t* area) {
if (layouter == NULL) {
if (widget->vt->auto_adjust_size != NULL) {
if (widget->auto_adjust_size && widget->vt->auto_adjust_size != NULL) {
widget->vt->auto_adjust_size(widget);
}

View File

@ -404,7 +404,7 @@ ret_t widget_layout_self_with_rect(self_layouter_t* layouter, widget_t* widget,
(widget->auto_adjust_size && widget_get_prop_int(widget, WIDGET_PROP_MAX_W, 0) != 0);
/*如果有指定max_w需要在layout之前先计算需要的高宽。*/
if (has_max_w && widget->vt->auto_adjust_size != NULL) {
if (has_max_w && widget->auto_adjust_size && widget->vt->auto_adjust_size != NULL) {
widget->vt->auto_adjust_size(widget);
r.w = widget->w;
r.h = widget->h;
@ -415,20 +415,22 @@ ret_t widget_layout_self_with_rect(self_layouter_t* layouter, widget_t* widget,
widget_layout_calc(l, &r, area->w, area->h);
/*如果没有指定max_w需要在layout之后根据layout的高宽计算实际需要的高宽。*/
if (!has_max_w && widget->vt->auto_adjust_size != NULL) {
if (!has_max_w && widget->auto_adjust_size && widget->vt->auto_adjust_size != NULL) {
wh_t w = widget->w;
wh_t h = widget->h;
widget->w = r.w;
widget->h = r.h;
widget->vt->auto_adjust_size(widget);
r.w = widget->w;
r.h = widget->h;
if (widget->auto_adjust_size) {
if (l->x_attr != X_ATTR_UNDEF && area->w > 0) {
r.x = tk_roundi(widget_layout_calc_by_x(l->x_attr, l->x, (double)r.w, area->w));
}
if (l->y_attr != Y_ATTR_UNDEF && area->h > 0) {
r.y = tk_roundi(widget_layout_calc_by_y(l->y_attr, l->y, (double)r.h, area->h));
}
if (l->x_attr != X_ATTR_UNDEF && area->w > 0) {
r.x = tk_roundi(widget_layout_calc_by_x(l->x_attr, l->x, (double)r.w, area->w));
}
if (l->y_attr != Y_ATTR_UNDEF && area->h > 0) {
r.y = tk_roundi(widget_layout_calc_by_y(l->y_attr, l->y, (double)r.h, area->h));
}
widget->w = w;
widget->h = h;
}
widget_move_resize_ex(widget, r.x + area->x, r.y + area->y, r.w, r.h, FALSE);

View File

@ -388,10 +388,7 @@ static ret_t button_auto_adjust_size(widget_t* widget) {
widget_prepare_text_style(widget, c);
h = c->font_size + margin_top + margin_bottom;
w = canvas_measure_text(c, widget->text.str, widget->text.size) + margin_left + margin_right;
widget->w = w;
widget->h = h;
return RET_OK;
return widget_move_resize_ex(widget, widget->x, widget->y, w, h, FALSE);
}
}