diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-10-19 02:40:26 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-10-19 02:40:26 +0000 |
commit | 9965f26d97c7530e544018cd1adb73d9cf5ca045 (patch) | |
tree | 65ae2e46fd20038ce6bd2cae7f66bf22f89f02c5 | |
parent | bf5350e13c6238ef4cd7b3b573e09750389a7524 (diff) | |
parent | 1c5a4de176aefc313b7498320e54e586df5e7a52 (diff) | |
download | gtk+-9965f26d97c7530e544018cd1adb73d9cf5ca045.tar.gz |
Merge branch 'wip/exalm/levelbar' into 'master'
levelbar: Fill the whole space for discrete level bars
See merge request GNOME/gtk!4042
-rw-r--r-- | gtk/gtklevelbar.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c index 94e2e2b3d4..22b950067b 100644 --- a/gtk/gtklevelbar.c +++ b/gtk/gtklevelbar.c @@ -464,6 +464,7 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, GtkAllocation block_area; int num_blocks, i; int block_width, block_height; + int extra_space; gtk_level_bar_get_min_block_size (self, &block_width, &block_height); num_blocks = gtk_level_bar_get_num_blocks (self); @@ -473,13 +474,21 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, if (self->orientation == GTK_ORIENTATION_HORIZONTAL) { - block_width = MAX (block_width, (int) floor (width / num_blocks)); + block_width = MAX (block_width, (int) floor ((double) width / num_blocks)); block_height = height; + extra_space = width - block_width * num_blocks; + + if (extra_space > 0) + block_width++; } else { block_width = width; - block_height = MAX (block_height, (int) floor (height / num_blocks)); + block_height = MAX (block_height, (int) floor ((double) height / num_blocks)); + extra_space = height - block_height * num_blocks; + + if (extra_space > 0) + block_height++; } block_area.x = 0; @@ -489,6 +498,14 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, for (i = 0; i < num_blocks; i++) { + if (extra_space > 0 && i == extra_space) + { + if (self->orientation == GTK_ORIENTATION_HORIZONTAL) + block_area.width--; + else + block_area.height--; + } + gtk_widget_size_allocate (self->block_widget[i], &block_area, baseline); |