summaryrefslogtreecommitdiff
path: root/gtk/gtklevelbar.c
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2016-01-02 17:54:06 -0800
committerCosimo Cecchi <cosimoc@gnome.org>2016-01-03 00:45:43 -0800
commit424898e071d909d0771713c7456f9460f52d12f9 (patch)
treebc466259f9f417b0cb7eda63d69a5ac62d64111a /gtk/gtklevelbar.c
parenta6e7e72d53fb1dfb29c3e1c52f42821a1457d8bc (diff)
downloadgtk+-424898e071d909d0771713c7456f9460f52d12f9.tar.gz
levelbar: consolidate code into single function
Diffstat (limited to 'gtk/gtklevelbar.c')
-rw-r--r--gtk/gtklevelbar.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c
index 961d5c3adb..61323aaef5 100644
--- a/gtk/gtklevelbar.c
+++ b/gtk/gtklevelbar.c
@@ -283,6 +283,15 @@ gtk_level_bar_get_num_blocks (GtkLevelBar *self)
return 0;
}
+static gint
+gtk_level_bar_get_num_block_nodes (GtkLevelBar *self)
+{
+ if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS)
+ return 2;
+ else
+ return gtk_level_bar_get_num_blocks (self);
+}
+
static gboolean
gtk_level_bar_get_real_inverted (GtkLevelBar *self)
{
@@ -536,10 +545,7 @@ update_block_nodes (GtkLevelBar *self)
guint n_blocks;
guint i;
- if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS)
- n_blocks = 2;
- else
- n_blocks = MAX (1, (gint) (round (priv->max_value) - round (priv->min_value)));
+ n_blocks = gtk_level_bar_get_num_block_nodes (self);
if (priv->n_blocks == n_blocks)
return;
@@ -644,19 +650,12 @@ update_level_style_classes (GtkLevelBar *self)
gboolean inverted;
inverted = gtk_level_bar_get_real_inverted (self);
+ num_blocks = gtk_level_bar_get_num_block_nodes (self);
if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS)
- {
- num_filled = 1;
- num_blocks = 2;
- }
+ num_filled = 1;
else
- {
- num_filled = (gint) round (priv->cur_value) - (gint) round (priv->min_value);
- num_blocks = (gint) round (priv->max_value) - (gint) round (priv->min_value);
- }
-
- num_filled = MIN (num_blocks, num_filled);
+ num_filled = MIN (num_blocks, (gint) round (priv->cur_value) - (gint) round (priv->min_value));
classes[0] = "filled";
classes[1] = value_class;