[gtk+] gtk: Allow hiding the trough/slider in GtkScale
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk: Allow hiding the trough/slider in GtkScale
- Date: Wed, 1 Dec 2010 16:03:03 +0000 (UTC)
commit 959fc60c47f56f42aef8407c06f17723f89c02e6
Author: Bastien Nocera <hadess hadess net>
Date: Mon Nov 22 17:46:25 2010 +0000
gtk: Allow hiding the trough/slider in GtkScale
When setting a GtkRange's upper and lower values to the same
value, the slider will not be drawn any more.
https://bugzilla.gnome.org/show_bug.cgi?id=549720
gtk/gtkrange.c | 20 +++++++++++++++++++-
gtk/gtkscale.c | 5 +++++
tests/testscale.c | 24 ++++++++++++++++++++++++
3 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 6cbbdd6..27e8a74 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -1280,7 +1280,7 @@ gtk_range_set_range (GtkRange *range,
gdouble value;
g_return_if_fail (GTK_IS_RANGE (range));
- g_return_if_fail (min < max);
+ g_return_if_fail (min <= max);
priv = range->priv;
@@ -2016,11 +2016,16 @@ gtk_range_draw (GtkWidget *widget,
gint focus_line_width = 0;
gint focus_padding = 0;
gboolean touchscreen;
+ gboolean draw_trough = TRUE;
g_object_get (gtk_widget_get_settings (widget),
"gtk-touchscreen-mode", &touchscreen,
NULL);
+ if (GTK_IS_SCALE (widget) &&
+ priv->adjustment->upper == priv->adjustment->lower)
+ draw_trough = FALSE;
+
style = gtk_widget_get_style (widget);
if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
gtk_widget_style_get (GTK_WIDGET (range),
@@ -2112,6 +2117,7 @@ gtk_range_draw (GtkWidget *widget,
}
}
+ if (draw_trough)
{
gint trough_change_pos_x = width;
gint trough_change_pos_y = height;
@@ -2147,6 +2153,17 @@ gtk_range_draw (GtkWidget *widget,
width - trough_change_pos_x,
height - trough_change_pos_y);
}
+ else
+ {
+ gtk_paint_box (style, cr,
+ sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
+ GTK_SHADOW_IN,
+ GTK_WIDGET (range),
+ "trough-upper",
+ x, y,
+ width,
+ height);
+ }
if (priv->show_fill_level &&
priv->adjustment->upper - priv->adjustment->page_size -
@@ -2236,6 +2253,7 @@ gtk_range_draw (GtkWidget *widget,
gdk_cairo_rectangle (cr, &priv->slider);
cairo_clip (cr);
+ if (draw_trough)
{
gtk_paint_slider (style,
cr,
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 51a4111..cd00b2e 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -55,6 +55,11 @@
* To detect changes to the value, you would normally use the
* #GtkRange::value-changed signal.
*
+ * Note that using the same upper and lower bounds for the #GtkScale (through
+ * the #GtkRange methods) will hide the slider itself. This is useful for
+ * applications that want to show an undeterminate value on the scale, without
+ * changing the layout of the application (such as movie or music players).
+ *
* <refsect2 id="GtkScale-BUILDER-UI"><title>GtkScale as GtkBuildable</title>
* GtkScale supports a custom <marks> element, which
* can contain multiple <mark> elements. The "value" and "position"
diff --git a/tests/testscale.c b/tests/testscale.c
index 8621c3f..0756607 100755
--- a/tests/testscale.c
+++ b/tests/testscale.c
@@ -20,6 +20,16 @@
#include <gtk/gtk.h>
+static void
+show_trough_toggled (GtkToggleButton *button,
+ GtkScale *scale)
+{
+ gboolean value;
+
+ value = gtk_toggle_button_get_active (button);
+ gtk_range_set_range (GTK_RANGE (scale), 0., value ? 100.0 : 0.);
+}
+
int main (int argc, char *argv[])
{
GtkWidget *window;
@@ -27,6 +37,7 @@ int main (int argc, char *argv[])
GtkWidget *box2;
GtkWidget *frame;
GtkWidget *scale;
+ GtkWidget *toggle;
gdouble marks[3] = { 0.0, 50.0, 100.0 };
const gchar *labels[3] = {
"<small>Left</small>",
@@ -96,6 +107,19 @@ int main (int argc, char *argv[])
gtk_container_add (GTK_CONTAINER (frame), scale);
gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
+ frame = gtk_frame_new ("Show/hide trough");
+ box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+ scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
+ 0, 100, 1);
+ gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
+ toggle = gtk_toggle_button_new_with_label ("Show slider trough");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
+ g_signal_connect (G_OBJECT (toggle), "toggled",
+ G_CALLBACK (show_trough_toggled), scale);
+ gtk_box_pack_start (GTK_BOX (box2), toggle, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (frame), box2);
+ gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
+
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]