Skip to content

Commit d14023e

Browse files
committed
fix(gui): widget width with margin is incorrectly calculated (#167)
1 parent 926684c commit d14023e

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/gui/widget_base.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* widget_base.c -- The widget base operation set.
33
*
44
* Copyright (c) 2018, Liu chao <lc-soft@live.cn> All rights reserved.
@@ -39,8 +39,8 @@
3939
#include <LCUI/gui/metrics.h>
4040

4141
static struct LCUI_WidgetModule {
42-
LCUI_Widget root; /**< 根级部件 */
43-
LinkedList trash; /**< 待删除的部件列表 */
42+
LCUI_Widget root; /**< 根级部件 */
43+
LinkedList trash; /**< 待删除的部件列表 */
4444
} LCUIWidget;
4545

4646
static inline float ToBorderBoxWidth(LCUI_Widget w, float content_width)
@@ -399,7 +399,6 @@ void Widget_UpdateOpacity(LCUI_Widget w)
399399
}
400400
w->computed_style.opacity = opacity;
401401
Widget_InvalidateArea(w, NULL, SV_GRAPH_BOX);
402-
DEBUG_MSG("opacity: %0.2f\n", opacity);
403402
}
404403

405404
void Widget_UpdateZIndex(LCUI_Widget w)
@@ -690,7 +689,6 @@ static void Widget_ComputeStaticContentSize(LCUI_Widget w, float *out_width,
690689
*out_height = content_height;
691690
}
692691
}
693-
694692
LCUI_BOOL Widget_HasAutoStyle(LCUI_Widget w, int key)
695693
{
696694
return !Widget_CheckStyleValid(w, key) ||
@@ -1149,16 +1147,20 @@ void Widget_UpdateProps(LCUI_Widget w)
11491147
float Widget_ComputeMaxAvaliableWidth(LCUI_Widget widget)
11501148
{
11511149
LCUI_Widget w;
1152-
float width = 0, padding = 0;
1150+
float width = 0, padding = 0, margin = 0;
1151+
11531152
for (w = widget->parent; w; w = w->parent) {
11541153
if (!Widget_HasAutoStyle(w, key_width) ||
11551154
w->computed_style.max_width >= 0) {
11561155
width = w->box.content.width;
11571156
break;
11581157
}
1158+
if (Widget_HasFillAvailableWidth(w)) {
1159+
margin += w->box.outer.width - w->box.border.width;
1160+
}
11591161
padding += w->box.border.width - w->box.content.width;
11601162
}
1161-
width -= padding;
1163+
width -= padding + margin;
11621164
if (Widget_HasAbsolutePosition(widget)) {
11631165
width += widget->padding.left + widget->padding.right;
11641166
}

0 commit comments

Comments
 (0)