[mutter] clutter/box-layout: Don't cast children sizes to integers



commit abecf557bfefecf30760f7b760973dbd19e1fb48
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Sun Feb 13 21:46:14 2022 +0100

    clutter/box-layout: Don't cast children sizes to integers
    
    The distribute_natural_allocation() function was copied over from Gtk to
    Clutter 11 years ago with commit e636a0bbce2b24fdb4e99dcf2d4385eb25d0247a.
    Gtk only supports integers sizes in its layout machinery, while Clutter
    does everything using floats.
    
    Since this function sets the minimum_size (the size we allocate the
    children in the end) to an integer, this means we're implicitly
    typecasting floats to integers here, effectively floor()'ing all sizes
    that we allocate the box children.
    
    A bug this caused in gnome-shell was that a scrollView (like the one in
    the endSessionDialog) was showing scrollbars even though the content
    perfectly fit inside the view: Say the content and its scrollView parent
    request a size of 63.9 px, but get allocated a size of 63 px by a box
    layout. Now the scrollView notices that its allocated size is smaller
    than the requested size and thus shows a scrollbar.
    
    So fix that and use floats in distribute_natural_allocation() instead of
    integers, as we do everywhere else in the layout machinery.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2284>

 clutter/clutter/clutter-box-layout.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter/clutter-box-layout.c b/clutter/clutter/clutter-box-layout.c
index 85e1d05cd9..f263eb4d5c 100644
--- a/clutter/clutter/clutter-box-layout.c
+++ b/clutter/clutter/clutter-box-layout.c
@@ -596,17 +596,17 @@ distribute_natural_allocation (float          extra_space,
   /* Distribute available space.
    * This master piece of a loop was conceived by Behdad Esfahbod.
    */
-  for (i = n_requested_sizes - 1; extra_space > 0 && i >= 0; --i)
+  for (i = n_requested_sizes - 1; extra_space > 0.0 && i >= 0; --i)
     {
       /* Divide remaining space by number of remaining children.
        * Sort order and reducing remaining space by assigned space
        * ensures that space is distributed equally.
        */
-      int glue = (extra_space + i) / (i + 1);
-      int gap = sizes[(spreading[i])].natural_size
-              - sizes[(spreading[i])].minimum_size;
+      float glue = (extra_space + i) / (i + 1.0);
+      float gap =
+        sizes[(spreading[i])].natural_size - sizes[(spreading[i])].minimum_size;
 
-      int extra = MIN (glue, gap);
+      float extra = MIN (glue, gap);
 
       sizes[spreading[i]].minimum_size += extra;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]