progressbar: add empty and full classes on trough based on fill-level

Pointed out in https://bugzilla.gnome.org/show_bug.cgi?id=774695
This commit is contained in:
Simon Steinbeiss 2016-11-18 23:43:09 +01:00 committed by Benjamin Otte
parent ca47c75272
commit a1deb8e459

View File

@ -75,7 +75,7 @@
*
* |[<!-- language="plain" -->
* progressbar[.osd]
* trough
* trough[.empty][.full]
* [text]
* progress[.pulse]
* ]|
@ -324,6 +324,36 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
gtk_widget_class_set_css_name (widget_class, "progressbar");
}
static void
update_fraction_classes (GtkProgressBar *pbar)
{
GtkProgressBarPrivate *priv = pbar->priv;
gboolean empty = FALSE;
gboolean full = FALSE;
/* Here we set classes based on fill-level unless we're in activity-mode.
*/
if (!priv->activity_mode)
{
if (priv->fraction <= 0.0)
empty = TRUE;
if (priv->fraction >= 1.0)
full = TRUE;
}
if (empty)
gtk_css_gadget_add_class (priv->trough_gadget, "empty");
else
gtk_css_gadget_remove_class (priv->trough_gadget, "empty");
if (full)
gtk_css_gadget_add_class (priv->trough_gadget, "full");
else
gtk_css_gadget_remove_class (priv->trough_gadget, "full");
}
static void
update_node_classes (GtkProgressBar *pbar)
{
@ -392,6 +422,8 @@ update_node_classes (GtkProgressBar *pbar)
gtk_css_gadget_add_class (priv->progress_gadget, GTK_STYLE_CLASS_BOTTOM);
else
gtk_css_gadget_remove_class (priv->progress_gadget, GTK_STYLE_CLASS_BOTTOM);
update_fraction_classes (pbar);
}
static void
@ -1196,6 +1228,7 @@ gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
priv->fraction = CLAMP (fraction, 0.0, 1.0);
gtk_progress_bar_set_activity_mode (pbar, FALSE);
gtk_widget_queue_allocate (GTK_WIDGET (pbar));
update_fraction_classes (pbar);
g_object_notify_by_pspec (G_OBJECT (pbar), progress_props[PROP_FRACTION]);
}