From: Daniel Boles Date: Mon, 21 May 2018 20:45:27 +0000 (+0100) Subject: SizeRequest: Round px values up for min CSS sizes X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~22^2~212 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3396c5e983289682965c2f1f0d75a1aba04cb088;p=gtk4.git SizeRequest: Round px values up for min CSS sizes Otherwise, requesting a min size in em where the equivalent in px had a fractional part would lead to the widget 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 --- diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c index b53acffb3e..f85f989337 100644 --- a/gtk/gtksizerequest.c +++ b/gtk/gtksizerequest.c @@ -82,6 +82,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) @@ -166,15 +174,15 @@ gtk_widget_query_size_for_orientation (GtkWidget *widget, { css_extra_size = margin.left + margin.right + border.left + border.right + padding.left + padding.right; css_extra_for_size = margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom; - css_min_size = get_number (style, GTK_CSS_PROPERTY_MIN_WIDTH); - css_min_for_size = get_number (style, GTK_CSS_PROPERTY_MIN_HEIGHT); + css_min_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_WIDTH); + css_min_for_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_HEIGHT); } else { css_extra_size = margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom; css_extra_for_size = margin.left + margin.right + border.left + border.right + padding.left + padding.right; - css_min_size = get_number (style, GTK_CSS_PROPERTY_MIN_HEIGHT); - css_min_for_size = get_number (style, GTK_CSS_PROPERTY_MIN_WIDTH); + css_min_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_HEIGHT); + css_min_for_size = get_number_ceil (style, GTK_CSS_PROPERTY_MIN_WIDTH); } if (for_size < 0)