diff options
author | Daniel Boles <dboles.src@gmail.com> | 2018-05-21 21:40:39 +0100 |
---|---|---|
committer | Daniel Boles <dboles.src@gmail.com> | 2018-06-05 18:42:45 +0100 |
commit | daecee75b48b4f26e7c1d5169729aa763505f329 (patch) | |
tree | c1d27ad57ae865b9acd6d12cdd69516b0e643198 | |
parent | 700d167b9e4139a99912f65381836fa229e0594c (diff) | |
download | gtk+-daecee75b48b4f26e7c1d5169729aa763505f329.tar.gz |
CssGadget: Round px values up for min-width|height
Otherwise, requesting a min size in em where the equivalent in px had a
fractional part would lead to the gadget getting allocated 1 too few px.
You could see this in the CSS property vs. allocation in the Inspector.
Note that margin/border/padding are left alone: the rationale is that we
do as browsers do, and Benjamin said we already do that for those,
whereas his tests on min-(width|height) showed otherwise. My subsequent
analysis indicated it to be far less clear-cut than that, but he remains
unconvinced that we should ceil() all the things! So just do these ones.
https://gitlab.gnome.org/GNOME/gtk/issues/1088
-rw-r--r-- | gtk/gtkcssgadget.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/gtk/gtkcssgadget.c b/gtk/gtkcssgadget.c index 7d4ba9c73b..09e9fdfa38 100644 --- a/gtk/gtkcssgadget.c +++ b/gtk/gtkcssgadget.c @@ -459,6 +459,14 @@ get_number (GtkCssStyle *style, return floor (d); } +/* Special-case min-width|height to round upwards, to avoid underalloc by 1px */ +static int +get_number_ceil (GtkCssStyle *style, + guint property) +{ + return ceil (_gtk_css_number_value_get (gtk_css_style_get_value (style, property), 100)); +} + static void get_box_margin (GtkCssStyle *style, GtkBorder *margin) @@ -643,16 +651,16 @@ gtk_css_gadget_get_preferred_size (GtkCssGadget *gadget, extra_size = margin.left + margin.right + border.left + border.right + padding.left + padding.right; extra_opposite = margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom; extra_baseline = margin.left + border.left + padding.left; - min_size = get_number (style, GTK_CSS_PROPERTY_MIN_WIDTH); - min_for_size = get_number (style, GTK_CSS_PROPERTY_MIN_HEIGHT); + min_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_WIDTH); + min_for_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_HEIGHT); } else { extra_size = margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom; extra_opposite = margin.left + margin.right + border.left + border.right + padding.left + padding.right; extra_baseline = margin.top + border.top + padding.top; - min_size = get_number (style, GTK_CSS_PROPERTY_MIN_HEIGHT); - min_for_size = get_number (style, GTK_CSS_PROPERTY_MIN_WIDTH); + min_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_HEIGHT); + min_for_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_WIDTH); } if (for_size > -1) |