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