1
<refentry id="GtkScale">
3
<refentrytitle role="top_of_page">GtkScale</refentrytitle>
4
<manvolnum>3</manvolnum>
5
<refmiscinfo>GTK Library</refmiscinfo>
9
<refname>GtkScale</refname>
10
<refpurpose>Base class for GtkHScale and GtkVScale</refpurpose>
11
<!--[<xref linkend="desc" endterm="desc.title"/>]-->
14
<refsynopsisdiv role="synopsis">
15
<title role="synopsis.title">Synopsis</title>
19
#include <gtk/gtk.h>
22
<link linkend="GtkScale-struct">GtkScale</link>;
23
<link linkend="void">void</link> <link linkend="gtk-scale-set-digits">gtk_scale_set_digits</link> (<link linkend="GtkScale">GtkScale</link> *scale,
24
<link linkend="gint">gint</link> digits);
25
<link linkend="void">void</link> <link linkend="gtk-scale-set-draw-value">gtk_scale_set_draw_value</link> (<link linkend="GtkScale">GtkScale</link> *scale,
26
<link linkend="gboolean">gboolean</link> draw_value);
27
<link linkend="void">void</link> <link linkend="gtk-scale-set-value-pos">gtk_scale_set_value_pos</link> (<link linkend="GtkScale">GtkScale</link> *scale,
28
<link linkend="GtkPositionType">GtkPositionType</link> pos);
29
<link linkend="gint">gint</link> <link linkend="gtk-scale-get-digits">gtk_scale_get_digits</link> (<link linkend="GtkScale">GtkScale</link> *scale);
30
<link linkend="gboolean">gboolean</link> <link linkend="gtk-scale-get-draw-value">gtk_scale_get_draw_value</link> (<link linkend="GtkScale">GtkScale</link> *scale);
31
<link linkend="GtkPositionType">GtkPositionType</link> <link linkend="gtk-scale-get-value-pos">gtk_scale_get_value_pos</link> (<link linkend="GtkScale">GtkScale</link> *scale);
32
<link linkend="PangoLayout">PangoLayout</link>* <link linkend="gtk-scale-get-layout">gtk_scale_get_layout</link> (<link linkend="GtkScale">GtkScale</link> *scale);
33
<link linkend="void">void</link> <link linkend="gtk-scale-get-layout-offsets">gtk_scale_get_layout_offsets</link> (<link linkend="GtkScale">GtkScale</link> *scale,
34
<link linkend="gint">gint</link> *x,
35
<link linkend="gint">gint</link> *y);
41
<refsect1 role="object_hierarchy">
42
<title role="object_hierarchy.title">Object Hierarchy</title>
45
<link linkend="GObject">GObject</link>
46
+----<link linkend="GInitiallyUnowned">GInitiallyUnowned</link>
47
+----<link linkend="GtkObject">GtkObject</link>
48
+----<link linkend="GtkWidget">GtkWidget</link>
49
+----<link linkend="GtkRange">GtkRange</link>
51
+----<link linkend="GtkHScale">GtkHScale</link>
52
+----<link linkend="GtkVScale">GtkVScale</link>
59
<refsect1 role="impl_interfaces">
60
<title role="impl_interfaces.title">Implemented Interfaces</title>
63
<link linkend="AtkImplementorIface">AtkImplementorIface</link>.</para>
68
<refsect1 role="properties">
69
<title role="properties.title">Properties</title>
72
"<link linkend="GtkScale--digits">digits</link>" <link linkend="gint">gint</link> : Read / Write
73
"<link linkend="GtkScale--draw-value">draw-value</link>" <link linkend="gboolean">gboolean</link> : Read / Write
74
"<link linkend="GtkScale--value-pos">value-pos</link>" <link linkend="GtkPositionType">GtkPositionType</link> : Read / Write
77
<refsect1 role="style_properties">
78
<title role="style_properties.title">Style Properties</title>
81
"<link linkend="GtkScale--slider-length">slider-length</link>" <link linkend="gint">gint</link> : Read
82
"<link linkend="GtkScale--value-spacing">value-spacing</link>" <link linkend="gint">gint</link> : Read
86
<refsect1 role="signal_proto">
87
<title role="signal_proto.title">Signals</title>
90
"<link linkend="GtkScale-format-value">format-value</link>" : Run Last
95
<refsect1 role="desc">
96
<title role="desc.title">Description</title>
98
A <link linkend="GtkScale"><type>GtkScale</type></link> is a slider control used to select a numeric value.
99
To use it, you'll probably want to investigate the methods on
100
its base class, <link linkend="GtkRange"><type>GtkRange</type></link>, in addition to the methods for <link linkend="GtkScale"><type>GtkScale</type></link> itself.
101
To set the value of a scale, you would normally use <link linkend="gtk-range-set-value"><function>gtk_range_set_value()</function></link>.
102
To detect changes to the value, you would normally use the "value_changed"
106
The <link linkend="GtkScale"><type>GtkScale</type></link> widget is an abstract class, used only for deriving the
107
subclasses <link linkend="GtkHScale"><type>GtkHScale</type></link> and <link linkend="GtkVScale"><type>GtkVScale</type></link>. To create a scale widget,
108
call <link linkend="gtk-hscale-new-with-range"><function>gtk_hscale_new_with_range()</function></link> or <link linkend="gtk-vscale-new-with-range"><function>gtk_vscale_new_with_range()</function></link>.
112
<refsect1 role="details">
113
<title role="details.title">Details</title>
115
<title><anchor id="GtkScale-struct" role="struct"/>GtkScale</title>
116
<indexterm><primary>GtkScale</primary></indexterm><programlisting>typedef struct _GtkScale GtkScale;</programlisting>
118
The <link linkend="GtkScale-struct"><type>GtkScale</type></link> struct contains the following fields.
119
(These fields should be considered read-only. They should never be set by
122
<informaltable pgwide="1" frame="none" role="struct">
123
<tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
127
<entry><link linkend="guint"><type>guint</type></link> <structfield>draw_value</structfield>;</entry>
128
<entry>non-zero if the scale's current value is displayed next to the
133
<entry><link linkend="guint"><type>guint</type></link> <structfield>value_pos</structfield>;</entry>
134
<entry>the position in which the textual value is displayed, selected from
135
<link linkend="GtkPositionType"><type>GtkPositionType</type></link>.</entry>
138
</tbody></tgroup></informaltable>
141
<title><anchor id="gtk-scale-set-digits" role="function"/>gtk_scale_set_digits ()</title>
142
<indexterm><primary>gtk_scale_set_digits</primary></indexterm><programlisting><link linkend="void">void</link> gtk_scale_set_digits (<link linkend="GtkScale">GtkScale</link> *scale,
143
<link linkend="gint">gint</link> digits);</programlisting>
145
Sets the number of decimal places that are displayed in the value. Also causes
146
the value of the adjustment to be rounded off to this number of digits, so the
147
retrieved value matches the value the user saw.
148
</para><variablelist role="params">
149
<varlistentry><term><parameter>scale</parameter> :</term>
150
<listitem><simpara>a <link linkend="GtkScale"><type>GtkScale</type></link>.
151
</simpara></listitem></varlistentry>
152
<varlistentry><term><parameter>digits</parameter> :</term>
153
<listitem><simpara>the number of decimal places to display, e.g. use 1 to display 1.0,
154
2 to display 1.00 etc.
157
</simpara></listitem></varlistentry>
158
</variablelist></refsect2>
160
<title><anchor id="gtk-scale-set-draw-value" role="function"/>gtk_scale_set_draw_value ()</title>
161
<indexterm><primary>gtk_scale_set_draw_value</primary></indexterm><programlisting><link linkend="void">void</link> gtk_scale_set_draw_value (<link linkend="GtkScale">GtkScale</link> *scale,
162
<link linkend="gboolean">gboolean</link> draw_value);</programlisting>
164
Specifies whether the current value is displayed as a string next to the
166
</para><variablelist role="params">
167
<varlistentry><term><parameter>scale</parameter> :</term>
168
<listitem><simpara>a <link linkend="GtkScale"><type>GtkScale</type></link>.
169
</simpara></listitem></varlistentry>
170
<varlistentry><term><parameter>draw_value</parameter> :</term>
171
<listitem><simpara>a boolean.
174
</simpara></listitem></varlistentry>
175
</variablelist></refsect2>
177
<title><anchor id="gtk-scale-set-value-pos" role="function"/>gtk_scale_set_value_pos ()</title>
178
<indexterm><primary>gtk_scale_set_value_pos</primary></indexterm><programlisting><link linkend="void">void</link> gtk_scale_set_value_pos (<link linkend="GtkScale">GtkScale</link> *scale,
179
<link linkend="GtkPositionType">GtkPositionType</link> pos);</programlisting>
181
Sets the position in which the current value is displayed.
182
</para><variablelist role="params">
183
<varlistentry><term><parameter>scale</parameter> :</term>
184
<listitem><simpara>a <link linkend="GtkScale"><type>GtkScale</type></link>.
185
</simpara></listitem></varlistentry>
186
<varlistentry><term><parameter>pos</parameter> :</term>
187
<listitem><simpara>the position in which the current value is displayed.
190
</simpara></listitem></varlistentry>
191
</variablelist></refsect2>
193
<title><anchor id="gtk-scale-get-digits" role="function"/>gtk_scale_get_digits ()</title>
194
<indexterm><primary>gtk_scale_get_digits</primary></indexterm><programlisting><link linkend="gint">gint</link> gtk_scale_get_digits (<link linkend="GtkScale">GtkScale</link> *scale);</programlisting>
196
Gets the number of decimal places that are displayed in the value.
197
</para><variablelist role="params">
198
<varlistentry><term><parameter>scale</parameter> :</term>
199
<listitem><simpara>a <link linkend="GtkScale"><type>GtkScale</type></link>.
200
</simpara></listitem></varlistentry>
201
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the number of decimal places that are displayed.
204
</simpara></listitem></varlistentry>
205
</variablelist></refsect2>
207
<title><anchor id="gtk-scale-get-draw-value" role="function"/>gtk_scale_get_draw_value ()</title>
208
<indexterm><primary>gtk_scale_get_draw_value</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> gtk_scale_get_draw_value (<link linkend="GtkScale">GtkScale</link> *scale);</programlisting>
210
Returns whether the current value is displayed as a string next to the
212
</para><variablelist role="params">
213
<varlistentry><term><parameter>scale</parameter> :</term>
214
<listitem><simpara>a <link linkend="GtkScale"><type>GtkScale</type></link>.
215
</simpara></listitem></varlistentry>
216
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>whether the current value is displayed as a string.
219
</simpara></listitem></varlistentry>
220
</variablelist></refsect2>
222
<title><anchor id="gtk-scale-get-value-pos" role="function"/>gtk_scale_get_value_pos ()</title>
223
<indexterm><primary>gtk_scale_get_value_pos</primary></indexterm><programlisting><link linkend="GtkPositionType">GtkPositionType</link> gtk_scale_get_value_pos (<link linkend="GtkScale">GtkScale</link> *scale);</programlisting>
225
Gets the position in which the current value is displayed.
226
</para><variablelist role="params">
227
<varlistentry><term><parameter>scale</parameter> :</term>
228
<listitem><simpara>a <link linkend="GtkScale"><type>GtkScale</type></link>.
229
</simpara></listitem></varlistentry>
230
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the position in which the current value is displayed.
233
</simpara></listitem></varlistentry>
234
</variablelist></refsect2>
236
<title><anchor id="gtk-scale-get-layout" role="function" condition="since:2.4"/>gtk_scale_get_layout ()</title>
237
<indexterm role="2.4"><primary>gtk_scale_get_layout</primary></indexterm><programlisting><link linkend="PangoLayout">PangoLayout</link>* gtk_scale_get_layout (<link linkend="GtkScale">GtkScale</link> *scale);</programlisting>
239
Gets the <link linkend="PangoLayout"><type>PangoLayout</type></link> used to display the scale. The returned object
240
is owned by the scale so does not need to be freed by the caller.</para>
243
</para><variablelist role="params">
244
<varlistentry><term><parameter>scale</parameter> :</term>
245
<listitem><simpara> A <link linkend="GtkScale"><type>GtkScale</type></link>
246
</simpara></listitem></varlistentry>
247
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the <link linkend="PangoLayout"><type>PangoLayout</type></link> for this scale, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if the draw_value property
248
is <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>.
250
</simpara></listitem></varlistentry>
251
</variablelist><para role="since">Since 2.4
254
<title><anchor id="gtk-scale-get-layout-offsets" role="function" condition="since:2.4"/>gtk_scale_get_layout_offsets ()</title>
255
<indexterm role="2.4"><primary>gtk_scale_get_layout_offsets</primary></indexterm><programlisting><link linkend="void">void</link> gtk_scale_get_layout_offsets (<link linkend="GtkScale">GtkScale</link> *scale,
256
<link linkend="gint">gint</link> *x,
257
<link linkend="gint">gint</link> *y);</programlisting>
259
Obtains the coordinates where the scale will draw the <link linkend="PangoLayout"><type>PangoLayout</type></link>
260
representing the text in the scale. Remember
261
when using the <link linkend="PangoLayout"><type>PangoLayout</type></link> function you need to convert to
262
and from pixels using <link linkend="PANGO-PIXELS:CAPS"><function>PANGO_PIXELS()</function></link> or <link linkend="PANGO-SCALE:CAPS"><type>PANGO_SCALE</type></link>.
265
If the draw_value property is <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>, the return values are
269
</para><variablelist role="params">
270
<varlistentry><term><parameter>scale</parameter> :</term>
271
<listitem><simpara> a <link linkend="GtkScale"><type>GtkScale</type></link>
272
</simpara></listitem></varlistentry>
273
<varlistentry><term><parameter>x</parameter> :</term>
274
<listitem><simpara> location to store X offset of layout, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>
275
</simpara></listitem></varlistentry>
276
<varlistentry><term><parameter>y</parameter> :</term>
277
<listitem><simpara> location to store Y offset of layout, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>
278
</simpara></listitem></varlistentry>
279
</variablelist><para role="since">Since 2.4
283
<refsect1 role="property_details">
284
<title role="property_details.title">Property Details</title>
285
<refsect2><title><anchor id="GtkScale--digits"/>The "<literal>digits</literal>" property</title>
286
<indexterm><primary>GtkScale:digits</primary></indexterm><programlisting> "digits" <link linkend="gint">gint</link> : Read / Write</programlisting>
287
<para>The number of decimal places that are displayed in the value.</para><para>Allowed values: [-1,64]</para>
288
<para>Default value: 1</para>
290
<refsect2><title><anchor id="GtkScale--draw-value"/>The "<literal>draw-value</literal>" property</title>
291
<indexterm><primary>GtkScale:draw-value</primary></indexterm><programlisting> "draw-value" <link linkend="gboolean">gboolean</link> : Read / Write</programlisting>
292
<para>Whether the current value is displayed as a string next to the slider.</para><para>Default value: TRUE</para>
294
<refsect2><title><anchor id="GtkScale--value-pos"/>The "<literal>value-pos</literal>" property</title>
295
<indexterm><primary>GtkScale:value-pos</primary></indexterm><programlisting> "value-pos" <link linkend="GtkPositionType">GtkPositionType</link> : Read / Write</programlisting>
296
<para>The position in which the current value is displayed.</para><para>Default value: GTK_POS_TOP</para>
300
<refsect1 role="style_properties_details">
301
<title role="style_properties_details.title">Style Property Details</title>
302
<refsect2><title><anchor id="GtkScale--slider-length"/>The "<literal>slider-length</literal>" style property</title>
303
<indexterm><primary>GtkScale:slider-length</primary></indexterm><programlisting> "slider-length" <link linkend="gint">gint</link> : Read</programlisting>
304
<para>Length of scale's slider.</para><para>Allowed values: >= 0</para>
305
<para>Default value: 31</para>
307
<refsect2><title><anchor id="GtkScale--value-spacing"/>The "<literal>value-spacing</literal>" style property</title>
308
<indexterm><primary>GtkScale:value-spacing</primary></indexterm><programlisting> "value-spacing" <link linkend="gint">gint</link> : Read</programlisting>
309
<para>Space between value text and the slider/trough area.</para><para>Allowed values: >= 0</para>
310
<para>Default value: 2</para>
315
<refsect1 role="signals">
316
<title role="signals.title">Signal Details</title>
317
<refsect2><title><anchor id="GtkScale-format-value"/>The "format-value" signal</title>
318
<indexterm><primary>GtkScale::format-value</primary></indexterm><programlisting><link linkend="gchar">gchar</link>* user_function (<link linkend="GtkScale">GtkScale</link> *scale,
319
<link linkend="gdouble">gdouble</link> arg1,
320
<link linkend="gpointer">gpointer</link> user_data) : Run Last</programlisting>
322
Signal which allows you to change how the scale value is displayed. Connect a
323
signal handler which returns an allocated string representing <parameter>value</parameter>.
324
That string will then be used to display the scale's value.
325
Here's an example signal handler which displays a value 1.0 as
326
with "-->1.0<--".
327
<informalexample><programlisting>
329
format_value_callback (GtkScale *scale,
332
return g_strdup_printf ("-->%0.*g<--",
333
gtk_scale_get_digits (scale), value);
335
</programlisting></informalexample>
336
</para><variablelist role="params">
337
<varlistentry><term><parameter>scale</parameter> :</term>
338
<listitem><simpara>the object which received the signal.
339
</simpara></listitem></varlistentry>
340
<varlistentry><term><parameter>arg1</parameter> :</term>
342
</simpara></listitem></varlistentry>
343
<varlistentry><term><parameter>user_data</parameter> :</term>
344
<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>
345
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>allocated string representing <parameter>value</parameter>
346
</simpara></listitem></varlistentry>
347
</variablelist></refsect2>