summaryrefslogtreecommitdiff
path: root/dw/widget.cc
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2023-12-31 20:15:36 +0100
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-01-08 22:16:27 +0100
commitfb23343442bc3c6d85584edfc8cda3dd36a81182 (patch)
tree7876932f824f6d2b50693a525b4ee9dd3f60222a /dw/widget.cc
parent24bcd67df29a5418d05600b038a9283a00e555d2 (diff)
Constraint width in calcFinalWitdh()
Then min-width or max-width is given in the CSS style for the current widget, the returned width should be clamped by those values. The condition *finalValue != 1 was used to clamp with min-width, but it doesn't capture the situation when the finalValue was not yet set. Similarly, for the max-width, the finalWidth was only set when *finalValue == -1, which prevented the clamping when the width is set. The change always perform the clamp when finalWidth is not set or when the value exceeds the min or max value. When both min-width and max-width are given but width is -1, the resulting width is the min-witdh, as the max-width clamp rule won't trigger after setting the *finalValue to the min-witdh.
Diffstat (limited to 'dw/widget.cc')
-rw-r--r--dw/widget.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/dw/widget.cc b/dw/widget.cc
index 795b4f46..fd9daa3f 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -872,6 +872,16 @@ void Widget::correctExtremes (Extremes *extremes, bool useAdjustmentWidth)
DBG_OBJ_LEAVE_VAL ("%d / %d", extremes->minWidth, extremes->maxWidth);
}
+/** Computes a width value in pixels from cssValue.
+ *
+ * If cssValue is absolute, the absolute value is used.
+ * If cssValue is relative, then it is applied to refWidth.
+ * Otherwise, -1 is used.
+ *
+ * In any case, the returned value is clamped so that is not smaller
+ * than limitMinWidth.
+ *
+ */
int Widget::calcWidth (style::Length cssValue, int refWidth, Widget *refWidget,
int limitMinWidth, bool forceValue)
{
@@ -912,6 +922,10 @@ int Widget::calcWidth (style::Length cssValue, int refWidth, Widget *refWidget,
}
// *finalWidth may be -1.
+/*
+ * If style has minWidth or maxWidth set, the returned value in
+ * *finalWidth is constrained to not exceed any of the set limits.
+ * */
void Widget::calcFinalWidth (style::Style *style, int refWidth,
Widget *refWidget, int limitMinWidth,
bool forceValue, int *finalWidth)
@@ -931,9 +945,12 @@ void Widget::calcFinalWidth (style::Style *style, int refWidth,
if (width != -1)
*finalWidth = width;
- if (minWidth != -1 && *finalWidth != -1 && *finalWidth < minWidth)
+
+ /* Set the width if the min or max value is set and finalWidth is
+ * still -1 or exceeds the limit */
+ if (minWidth != -1 && (*finalWidth == -1 || *finalWidth < minWidth))
*finalWidth = minWidth;
- if (maxWidth != -1 && *finalWidth == -1 && *finalWidth > maxWidth)
+ if (maxWidth != -1 && (*finalWidth == -1 || *finalWidth > maxWidth))
*finalWidth = maxWidth;
DBG_OBJ_LEAVE_VAL ("%d", *finalWidth);