Skip to main content

atk/auto/
value.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::Range;
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem, mem::transmute, ptr};
12
13glib::wrapper! {
14    /// The ATK interface implemented by valuators and components which display or select a value from a bounded range of values.
15    ///
16    /// [`Value`][crate::Value] should be implemented for components which either display
17    /// a value from a bounded range, or which allow the user to specify a
18    /// value from a bounded range, or both. For instance, most sliders and
19    /// range controls, as well as dials, should have [`Object`][crate::Object]
20    /// representations which implement [`Value`][crate::Value] on the component's
21    /// behalf. `AtKValues` may be read-only, in which case attempts to
22    /// alter the value return would fail.
23    ///
24    /// <refsect1 id="current-value-text">
25    /// `<title>`On the subject of current value text`</title>`
26    /// `<para>`
27    /// In addition to providing the current value, implementors can
28    /// optionally provide an end-user-consumable textual description
29    /// associated with this value. This description should be included
30    /// when the numeric value fails to convey the full, on-screen
31    /// representation seen by users.
32    /// `</para>`
33    ///
34    /// `<example>`
35    /// `<title>`Password strength`</title>`
36    /// A password strength meter whose value changes as the user types
37    /// their new password. Red is used for values less than 4.0, yellow
38    /// for values between 4.0 and 7.0, and green for values greater than
39    /// 7.0. In this instance, value text should be provided by the
40    /// implementor. Appropriate value text would be "weak", "acceptable,"
41    /// and "strong" respectively.
42    /// `</example>`
43    ///
44    /// A level bar whose value changes to reflect the battery charge. The
45    /// color remains the same regardless of the charge and there is no
46    /// on-screen text reflecting the fullness of the battery. In this
47    /// case, because the position within the bar is the only indication
48    /// the user has of the current charge, value text should not be
49    /// provided by the implementor.
50    ///
51    /// <refsect2 id="implementor-notes">
52    /// `<title>`Implementor Notes`</title>`
53    /// `<para>`
54    /// Implementors should bear in mind that assistive technologies will
55    /// likely prefer the value text provided over the numeric value when
56    /// presenting a widget's value. As a result, strings not intended for
57    /// end users should not be exposed in the value text, and strings
58    /// which are exposed should be localized. In the case of widgets which
59    /// display value text on screen, for instance through a separate label
60    /// in close proximity to the value-displaying widget, it is still
61    /// expected that implementors will expose the value text using the
62    /// above API.
63    /// `</para>`
64    ///
65    /// `<para>`
66    /// [`Value`][crate::Value] should NOT be implemented for widgets whose displayed
67    /// value is not reflective of a meaningful amount. For instance, a
68    /// progress pulse indicator whose value alternates between 0.0 and 1.0
69    /// to indicate that some process is still taking place should not
70    /// implement [`Value`][crate::Value] because the current value does not reflect
71    /// progress towards completion.
72    /// `</para>`
73    /// `</refsect2>`
74    /// `</refsect1>`
75    ///
76    /// <refsect1 id="ranges">
77    /// `<title>`On the subject of ranges`</title>`
78    /// `<para>`
79    /// In addition to providing the minimum and maximum values,
80    /// implementors can optionally provide details about subranges
81    /// associated with the widget. These details should be provided by the
82    /// implementor when both of the following are communicated visually to
83    /// the end user:
84    /// `</para>`
85    /// `<itemizedlist>`
86    ///  `<listitem>`The existence of distinct ranges such as "weak",
87    ///  "acceptable", and "strong" indicated by color, bar tick marks,
88    ///  and/or on-screen text.`</listitem>`
89    ///  `<listitem>`Where the current value stands within a given subrange,
90    ///  for instance illustrating progression from very "weak" towards
91    ///  nearly "acceptable" through changes in shade and/or position on
92    ///  the bar within the "weak" subrange.`</listitem>`
93    /// `</itemizedlist>`
94    /// `<para>`
95    /// If both of the above do not apply to the widget, it should be
96    /// sufficient to expose the numeric value, along with the value text
97    /// if appropriate, to make the widget accessible.
98    /// `</para>`
99    ///
100    /// <refsect2 id="ranges-implementor-notes">
101    /// `<title>`Implementor Notes`</title>`
102    /// `<para>`
103    /// If providing subrange details is deemed necessary, all possible
104    /// values of the widget are expected to fall within one of the
105    /// subranges defined by the implementor.
106    /// `</para>`
107    /// `</refsect2>`
108    /// `</refsect1>`
109    ///
110    /// <refsect1 id="localization">
111    /// `<title>`On the subject of localization of end-user-consumable text
112    /// values`</title>`
113    /// `<para>`
114    /// Because value text and subrange descriptors are human-consumable,
115    /// implementors are expected to provide localized strings which can be
116    /// directly presented to end users via their assistive technology. In
117    /// order to simplify this for implementors, implementors can use
118    /// [`ValueType::localized_name()`][crate::ValueType::localized_name()] with the following
119    /// already-localized constants for commonly-needed values can be used:
120    /// `</para>`
121    ///
122    /// `<itemizedlist>`
123    ///  `<listitem>`ATK_VALUE_VERY_WEAK`</listitem>`
124    ///  `<listitem>`ATK_VALUE_WEAK`</listitem>`
125    ///  `<listitem>`ATK_VALUE_ACCEPTABLE`</listitem>`
126    ///  `<listitem>`ATK_VALUE_STRONG`</listitem>`
127    ///  `<listitem>`ATK_VALUE_VERY_STRONG`</listitem>`
128    ///  `<listitem>`ATK_VALUE_VERY_LOW`</listitem>`
129    ///  `<listitem>`ATK_VALUE_LOW`</listitem>`
130    ///  `<listitem>`ATK_VALUE_MEDIUM`</listitem>`
131    ///  `<listitem>`ATK_VALUE_HIGH`</listitem>`
132    ///  `<listitem>`ATK_VALUE_VERY_HIGH`</listitem>`
133    ///  `<listitem>`ATK_VALUE_VERY_BAD`</listitem>`
134    ///  `<listitem>`ATK_VALUE_BAD`</listitem>`
135    ///  `<listitem>`ATK_VALUE_GOOD`</listitem>`
136    ///  `<listitem>`ATK_VALUE_VERY_GOOD`</listitem>`
137    ///  `<listitem>`ATK_VALUE_BEST`</listitem>`
138    ///  `<listitem>`ATK_VALUE_SUBSUBOPTIMAL`</listitem>`
139    ///  `<listitem>`ATK_VALUE_SUBOPTIMAL`</listitem>`
140    ///  `<listitem>`ATK_VALUE_OPTIMAL`</listitem>`
141    /// `</itemizedlist>`
142    /// `<para>`
143    /// Proposals for additional constants, along with their use cases,
144    /// should be submitted to the GNOME Accessibility Team.
145    /// `</para>`
146    /// `</refsect1>`
147    ///
148    /// <refsect1 id="changes">
149    /// `<title>`On the subject of changes`</title>`
150    /// `<para>`
151    /// Note that if there is a textual description associated with the new
152    /// numeric value, that description should be included regardless of
153    /// whether or not it has also changed.
154    /// `</para>`
155    /// `</refsect1>`
156    ///
157    /// ## Signals
158    ///
159    ///
160    /// #### `value-changed`
161    ///  The 'value-changed' signal is emitted when the current value
162    /// that represent the object changes. `value` is the numerical
163    /// representation of this new value. `text` is the human
164    /// readable text alternative of `value`, and can be NULL if it is
165    /// not available. Note that if there is a textual description
166    /// associated with the new numeric value, that description
167    /// should be included regardless of whether or not it has also
168    /// changed.
169    ///
170    /// Example: a password meter whose value changes as the user
171    /// types their new password. Appropiate value text would be
172    /// "weak", "acceptable" and "strong".
173    ///
174    ///
175    ///
176    /// # Implements
177    ///
178    /// [`ValueExt`][trait@crate::prelude::ValueExt]
179    #[doc(alias = "AtkValue")]
180    pub struct Value(Interface<ffi::AtkValue, ffi::AtkValueIface>);
181
182    match fn {
183        type_ => || ffi::atk_value_get_type(),
184    }
185}
186
187impl Value {
188    pub const NONE: Option<&'static Value> = None;
189}
190
191mod sealed {
192    pub trait Sealed {}
193    impl<T: super::IsA<super::Value>> Sealed for T {}
194}
195
196/// Trait containing all [`struct@Value`] methods.
197///
198/// # Implementors
199///
200/// [`NoOpObject`][struct@crate::NoOpObject], [`Value`][struct@crate::Value]
201pub trait ValueExt: IsA<Value> + sealed::Sealed + 'static {
202    /// Gets the value of this object.
203    ///
204    /// # Deprecated
205    ///
206    /// Since 2.12. Use [`value_and_text()`][Self::value_and_text()]
207    /// instead.
208    ///
209    /// # Returns
210    ///
211    ///
212    /// ## `value`
213    /// a [`glib::Value`][crate::glib::Value] representing the current accessible value
214    #[doc(alias = "atk_value_get_current_value")]
215    #[doc(alias = "get_current_value")]
216    fn current_value(&self) -> glib::Value {
217        unsafe {
218            let mut value = glib::Value::uninitialized();
219            ffi::atk_value_get_current_value(
220                self.as_ref().to_glib_none().0,
221                value.to_glib_none_mut().0,
222            );
223            value
224        }
225    }
226
227    /// Gets the minimum increment by which the value of this object may be
228    /// changed. If zero, the minimum increment is undefined, which may
229    /// mean that it is limited only by the floating point precision of the
230    /// platform.
231    ///
232    /// # Returns
233    ///
234    /// the minimum increment by which the value of this
235    /// object may be changed. zero if undefined.
236    #[doc(alias = "atk_value_get_increment")]
237    #[doc(alias = "get_increment")]
238    fn increment(&self) -> f64 {
239        unsafe { ffi::atk_value_get_increment(self.as_ref().to_glib_none().0) }
240    }
241
242    /// Gets the maximum value of this object.
243    ///
244    /// # Deprecated
245    ///
246    /// Since 2.12. Use [`range()`][Self::range()] instead.
247    ///
248    /// # Returns
249    ///
250    ///
251    /// ## `value`
252    /// a [`glib::Value`][crate::glib::Value] representing the maximum accessible value
253    #[doc(alias = "atk_value_get_maximum_value")]
254    #[doc(alias = "get_maximum_value")]
255    fn maximum_value(&self) -> glib::Value {
256        unsafe {
257            let mut value = glib::Value::uninitialized();
258            ffi::atk_value_get_maximum_value(
259                self.as_ref().to_glib_none().0,
260                value.to_glib_none_mut().0,
261            );
262            value
263        }
264    }
265
266    /// Gets the minimum increment by which the value of this object may be changed. If zero,
267    /// the minimum increment is undefined, which may mean that it is limited only by the
268    /// floating point precision of the platform.
269    ///
270    /// # Deprecated
271    ///
272    /// Since 2.12. Use [`increment()`][Self::increment()] instead.
273    ///
274    /// # Returns
275    ///
276    ///
277    /// ## `value`
278    /// a [`glib::Value`][crate::glib::Value] representing the minimum increment by which the accessible value may be changed
279    #[doc(alias = "atk_value_get_minimum_increment")]
280    #[doc(alias = "get_minimum_increment")]
281    fn minimum_increment(&self) -> glib::Value {
282        unsafe {
283            let mut value = glib::Value::uninitialized();
284            ffi::atk_value_get_minimum_increment(
285                self.as_ref().to_glib_none().0,
286                value.to_glib_none_mut().0,
287            );
288            value
289        }
290    }
291
292    /// Gets the minimum value of this object.
293    ///
294    /// # Deprecated
295    ///
296    /// Since 2.12. Use [`range()`][Self::range()] instead.
297    ///
298    /// # Returns
299    ///
300    ///
301    /// ## `value`
302    /// a [`glib::Value`][crate::glib::Value] representing the minimum accessible value
303    #[doc(alias = "atk_value_get_minimum_value")]
304    #[doc(alias = "get_minimum_value")]
305    fn minimum_value(&self) -> glib::Value {
306        unsafe {
307            let mut value = glib::Value::uninitialized();
308            ffi::atk_value_get_minimum_value(
309                self.as_ref().to_glib_none().0,
310                value.to_glib_none_mut().0,
311            );
312            value
313        }
314    }
315
316    /// Gets the range of this object.
317    ///
318    /// # Returns
319    ///
320    /// a newly allocated [`Range`][crate::Range]
321    /// that represents the minimum, maximum and descriptor (if available)
322    /// of `self`. NULL if that range is not defined.
323    #[doc(alias = "atk_value_get_range")]
324    #[doc(alias = "get_range")]
325    fn range(&self) -> Option<Range> {
326        unsafe { from_glib_full(ffi::atk_value_get_range(self.as_ref().to_glib_none().0)) }
327    }
328
329    /// Gets the list of subranges defined for this object. See [`Value`][crate::Value]
330    /// introduction for examples of subranges and when to expose them.
331    ///
332    /// # Returns
333    ///
334    /// an `GSList` of
335    /// [`Range`][crate::Range] which each of the subranges defined for this object. Free
336    /// the returns list with `g_slist_free()`.
337    #[doc(alias = "atk_value_get_sub_ranges")]
338    #[doc(alias = "get_sub_ranges")]
339    fn sub_ranges(&self) -> Vec<Range> {
340        unsafe {
341            FromGlibPtrContainer::from_glib_full(ffi::atk_value_get_sub_ranges(
342                self.as_ref().to_glib_none().0,
343            ))
344        }
345    }
346
347    /// Gets the current value and the human readable text alternative of
348    /// `self`. `text` is a newly created string, that must be freed by the
349    /// caller. Can be NULL if no descriptor is available.
350    ///
351    /// # Returns
352    ///
353    ///
354    /// ## `value`
355    /// address of `gdouble` to put the current value of `self`
356    ///
357    /// ## `text`
358    /// address of `gchar` to put the human
359    /// readable text alternative for `value`
360    #[doc(alias = "atk_value_get_value_and_text")]
361    #[doc(alias = "get_value_and_text")]
362    fn value_and_text(&self) -> (f64, glib::GString) {
363        unsafe {
364            let mut value = mem::MaybeUninit::uninit();
365            let mut text = ptr::null_mut();
366            ffi::atk_value_get_value_and_text(
367                self.as_ref().to_glib_none().0,
368                value.as_mut_ptr(),
369                &mut text,
370            );
371            (value.assume_init(), from_glib_full(text))
372        }
373    }
374
375    /// Sets the value of this object.
376    ///
377    /// # Deprecated
378    ///
379    /// Since 2.12. Use [`set_value()`][Self::set_value()] instead.
380    /// ## `value`
381    /// a [`glib::Value`][crate::glib::Value] which is the desired new accessible value.
382    ///
383    /// # Returns
384    ///
385    /// [`true`] if new value is successfully set, [`false`] otherwise.
386    #[doc(alias = "atk_value_set_current_value")]
387    fn set_current_value(&self, value: &glib::Value) -> bool {
388        unsafe {
389            from_glib(ffi::atk_value_set_current_value(
390                self.as_ref().to_glib_none().0,
391                value.to_glib_none().0,
392            ))
393        }
394    }
395
396    /// Sets the value of this object.
397    ///
398    /// This method is intended to provide a way to change the value of the
399    /// object. In any case, it is possible that the value can't be
400    /// modified (ie: a read-only component). If the value changes due this
401    /// call, it is possible that the text could change, and will trigger
402    /// an [`value-changed`][struct@crate::Value#value-changed] signal emission.
403    ///
404    /// Note for implementors: the deprecated [`set_current_value()`][Self::set_current_value()]
405    /// method returned TRUE or FALSE depending if the value was assigned
406    /// or not. In the practice several implementors were not able to
407    /// decide it, and returned TRUE in any case. For that reason it is not
408    /// required anymore to return if the value was properly assigned or
409    /// not.
410    /// ## `new_value`
411    /// a double which is the desired new accessible value.
412    #[doc(alias = "atk_value_set_value")]
413    fn set_value(&self, new_value: f64) {
414        unsafe {
415            ffi::atk_value_set_value(self.as_ref().to_glib_none().0, new_value);
416        }
417    }
418
419    /// The 'value-changed' signal is emitted when the current value
420    /// that represent the object changes. `value` is the numerical
421    /// representation of this new value. `text` is the human
422    /// readable text alternative of `value`, and can be NULL if it is
423    /// not available. Note that if there is a textual description
424    /// associated with the new numeric value, that description
425    /// should be included regardless of whether or not it has also
426    /// changed.
427    ///
428    /// Example: a password meter whose value changes as the user
429    /// types their new password. Appropiate value text would be
430    /// "weak", "acceptable" and "strong".
431    /// ## `value`
432    /// the new value in a numerical form.
433    /// ## `text`
434    /// human readable text alternative (also called
435    /// description) of this object. NULL if not available.
436    #[doc(alias = "value-changed")]
437    fn connect_value_changed<F: Fn(&Self, f64, &str) + 'static>(&self, f: F) -> SignalHandlerId {
438        unsafe extern "C" fn value_changed_trampoline<
439            P: IsA<Value>,
440            F: Fn(&P, f64, &str) + 'static,
441        >(
442            this: *mut ffi::AtkValue,
443            value: libc::c_double,
444            text: *mut libc::c_char,
445            f: glib::ffi::gpointer,
446        ) {
447            let f: &F = &*(f as *const F);
448            f(
449                Value::from_glib_borrow(this).unsafe_cast_ref(),
450                value,
451                &glib::GString::from_glib_borrow(text),
452            )
453        }
454        unsafe {
455            let f: Box_<F> = Box_::new(f);
456            connect_raw(
457                self.as_ptr() as *mut _,
458                b"value-changed\0".as_ptr() as *const _,
459                Some(transmute::<_, unsafe extern "C" fn()>(
460                    value_changed_trampoline::<Self, F> as *const (),
461                )),
462                Box_::into_raw(f),
463            )
464        }
465    }
466}
467
468impl<O: IsA<Value>> ValueExt for O {}
469
470impl fmt::Display for Value {
471    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
472        f.write_str("Value")
473    }
474}