gtk4/auto/level_bar.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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::{Accessible, AccessibleRange};
8use crate::{
9 AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, LevelBarMode, Orientable,
10 Orientation, Overflow, Widget, ffi,
11};
12use glib::{
13 object::ObjectType as _,
14 prelude::*,
15 signal::{SignalHandlerId, connect_raw},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20#[cfg(feature = "v4_10")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
22glib::wrapper! {
23 ///
24 /// ```text
25 ///
26 /// [`LevelBar`][crate::LevelBar] has a main CSS node with name levelbar and one of the style
27 /// classes .discrete or .continuous and a subnode with name trough. Below the
28 /// trough node are a number of nodes with name block and style class .filled
29 /// or .empty. In continuous mode, there is exactly one node of each, in discrete
30 /// mode, the number of filled and unfilled nodes corresponds to blocks that are
31 /// drawn. The block.filled nodes also get a style class .level-name corresponding
32 /// to the level for the current value.
33 ///
34 /// In horizontal orientation, the nodes are always arranged from left to right,
35 /// regardless of text direction.
36 ///
37 /// # Accessibility
38 ///
39 /// [`LevelBar`][crate::LevelBar] uses the [enum@Gtk.AccessibleRole.meter] role.
40 ///
41 /// ## Properties
42 ///
43 ///
44 /// #### `inverted`
45 /// Whether the `GtkLeveBar` is inverted.
46 ///
47 /// Level bars normally grow from top to bottom or left to right.
48 /// Inverted level bars grow in the opposite direction.
49 ///
50 /// Readable | Writable
51 ///
52 ///
53 /// #### `max-value`
54 /// Determines the maximum value of the interval that can be displayed by the bar.
55 ///
56 /// Readable | Writable
57 ///
58 ///
59 /// #### `min-value`
60 /// Determines the minimum value of the interval that can be displayed by the bar.
61 ///
62 /// Readable | Writable
63 ///
64 ///
65 /// #### `mode`
66 /// Determines the way [`LevelBar`][crate::LevelBar] interprets the value properties to draw the
67 /// level fill area.
68 ///
69 /// Specifically, when the value is [`LevelBarMode::Continuous`][crate::LevelBarMode::Continuous],
70 /// [`LevelBar`][crate::LevelBar] will draw a single block representing the current value in
71 /// that area; when the value is [`LevelBarMode::Discrete`][crate::LevelBarMode::Discrete],
72 /// the widget will draw a succession of separate blocks filling the
73 /// draw area, with the number of blocks being equal to the units separating
74 /// the integral roundings of [`min-value`][struct@crate::LevelBar#min-value] and
75 /// [`max-value`][struct@crate::LevelBar#max-value].
76 ///
77 /// Readable | Writable
78 ///
79 ///
80 /// #### `value`
81 /// Determines the currently filled value of the level bar.
82 ///
83 /// Readable | Writable
84 /// <details><summary><h4>Widget</h4></summary>
85 ///
86 ///
87 /// #### `can-focus`
88 /// Whether the widget or any of its descendents can accept
89 /// the input focus.
90 ///
91 /// This property is meant to be set by widget implementations,
92 /// typically in their instance init function.
93 ///
94 /// Readable | Writable
95 ///
96 ///
97 /// #### `can-target`
98 /// Whether the widget can receive pointer events.
99 ///
100 /// Readable | Writable
101 ///
102 ///
103 /// #### `css-classes`
104 /// A list of css classes applied to this widget.
105 ///
106 /// Readable | Writable
107 ///
108 ///
109 /// #### `css-name`
110 /// The name of this widget in the CSS tree.
111 ///
112 /// This property is meant to be set by widget implementations,
113 /// typically in their instance init function.
114 ///
115 /// Readable | Writable | Construct Only
116 ///
117 ///
118 /// #### `cursor`
119 /// The cursor used by @widget.
120 ///
121 /// Readable | Writable
122 ///
123 ///
124 /// #### `focus-on-click`
125 /// Whether the widget should grab focus when it is clicked with the mouse.
126 ///
127 /// This property is only relevant for widgets that can take focus.
128 ///
129 /// Readable | Writable
130 ///
131 ///
132 /// #### `focusable`
133 /// Whether this widget itself will accept the input focus.
134 ///
135 /// Readable | Writable
136 ///
137 ///
138 /// #### `halign`
139 /// How to distribute horizontal space if widget gets extra space.
140 ///
141 /// Readable | Writable
142 ///
143 ///
144 /// #### `has-default`
145 /// Whether the widget is the default widget.
146 ///
147 /// Readable
148 ///
149 ///
150 /// #### `has-focus`
151 /// Whether the widget has the input focus.
152 ///
153 /// Readable
154 ///
155 ///
156 /// #### `has-tooltip`
157 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
158 /// signal on @widget.
159 ///
160 /// A true value indicates that @widget can have a tooltip, in this case
161 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
162 /// determine whether it will provide a tooltip or not.
163 ///
164 /// Readable | Writable
165 ///
166 ///
167 /// #### `height-request`
168 /// Overrides for height request of the widget.
169 ///
170 /// If this is -1, the natural request will be used.
171 ///
172 /// Readable | Writable
173 ///
174 ///
175 /// #### `hexpand`
176 /// Whether to expand horizontally.
177 ///
178 /// Readable | Writable
179 ///
180 ///
181 /// #### `hexpand-set`
182 /// Whether to use the `hexpand` property.
183 ///
184 /// Readable | Writable
185 ///
186 ///
187 /// #### `layout-manager`
188 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
189 /// the preferred size of the widget, and allocate its children.
190 ///
191 /// This property is meant to be set by widget implementations,
192 /// typically in their instance init function.
193 ///
194 /// Readable | Writable
195 ///
196 ///
197 /// #### `limit-events`
198 /// Makes this widget act like a modal dialog, with respect to
199 /// event delivery.
200 ///
201 /// Global event controllers will not handle events with targets
202 /// inside the widget, unless they are set up to ignore propagation
203 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
204 ///
205 /// Readable | Writable
206 ///
207 ///
208 /// #### `margin-bottom`
209 /// Margin on bottom side of widget.
210 ///
211 /// This property adds margin outside of the widget's normal size
212 /// request, the margin will be added in addition to the size from
213 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
214 ///
215 /// Readable | Writable
216 ///
217 ///
218 /// #### `margin-end`
219 /// Margin on end of widget, horizontally.
220 ///
221 /// This property supports left-to-right and right-to-left text
222 /// directions.
223 ///
224 /// This property adds margin outside of the widget's normal size
225 /// request, the margin will be added in addition to the size from
226 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
227 ///
228 /// Readable | Writable
229 ///
230 ///
231 /// #### `margin-start`
232 /// Margin on start of widget, horizontally.
233 ///
234 /// This property supports left-to-right and right-to-left text
235 /// directions.
236 ///
237 /// This property adds margin outside of the widget's normal size
238 /// request, the margin will be added in addition to the size from
239 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
240 ///
241 /// Readable | Writable
242 ///
243 ///
244 /// #### `margin-top`
245 /// Margin on top side of widget.
246 ///
247 /// This property adds margin outside of the widget's normal size
248 /// request, the margin will be added in addition to the size from
249 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
250 ///
251 /// Readable | Writable
252 ///
253 ///
254 /// #### `name`
255 /// The name of the widget.
256 ///
257 /// Readable | Writable
258 ///
259 ///
260 /// #### `opacity`
261 /// The requested opacity of the widget.
262 ///
263 /// Readable | Writable
264 ///
265 ///
266 /// #### `overflow`
267 /// How content outside the widget's content area is treated.
268 ///
269 /// This property is meant to be set by widget implementations,
270 /// typically in their instance init function.
271 ///
272 /// Readable | Writable
273 ///
274 ///
275 /// #### `parent`
276 /// The parent widget of this widget.
277 ///
278 /// Readable
279 ///
280 ///
281 /// #### `receives-default`
282 /// Whether the widget will receive the default action when it is focused.
283 ///
284 /// Readable | Writable
285 ///
286 ///
287 /// #### `root`
288 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
289 ///
290 /// This will be `NULL` if the widget is not contained in a root widget.
291 ///
292 /// Readable
293 ///
294 ///
295 /// #### `scale-factor`
296 /// The scale factor of the widget.
297 ///
298 /// Readable
299 ///
300 ///
301 /// #### `sensitive`
302 /// Whether the widget responds to input.
303 ///
304 /// Readable | Writable
305 ///
306 ///
307 /// #### `tooltip-markup`
308 /// Sets the text of tooltip to be the given string, which is marked up
309 /// with Pango markup.
310 ///
311 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
312 ///
313 /// This is a convenience property which will take care of getting the
314 /// tooltip shown if the given string is not `NULL`:
315 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
316 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
317 /// the default signal handler.
318 ///
319 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
320 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
321 ///
322 /// Readable | Writable
323 ///
324 ///
325 /// #### `tooltip-text`
326 /// Sets the text of tooltip to be the given string.
327 ///
328 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
329 ///
330 /// This is a convenience property which will take care of getting the
331 /// tooltip shown if the given string is not `NULL`:
332 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
333 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
334 /// the default signal handler.
335 ///
336 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
337 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
338 ///
339 /// Readable | Writable
340 ///
341 ///
342 /// #### `valign`
343 /// How to distribute vertical space if widget gets extra space.
344 ///
345 /// Readable | Writable
346 ///
347 ///
348 /// #### `vexpand`
349 /// Whether to expand vertically.
350 ///
351 /// Readable | Writable
352 ///
353 ///
354 /// #### `vexpand-set`
355 /// Whether to use the `vexpand` property.
356 ///
357 /// Readable | Writable
358 ///
359 ///
360 /// #### `visible`
361 /// Whether the widget is visible.
362 ///
363 /// Readable | Writable
364 ///
365 ///
366 /// #### `width-request`
367 /// Overrides for width request of the widget.
368 ///
369 /// If this is -1, the natural request will be used.
370 ///
371 /// Readable | Writable
372 /// </details>
373 /// <details><summary><h4>Accessible</h4></summary>
374 ///
375 ///
376 /// #### `accessible-role`
377 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
378 ///
379 /// The accessible role cannot be changed once set.
380 ///
381 /// Readable | Writable
382 /// </details>
383 /// <details><summary><h4>Orientable</h4></summary>
384 ///
385 ///
386 /// #### `orientation`
387 /// The orientation of the orientable.
388 ///
389 /// Readable | Writable
390 /// </details>
391 ///
392 /// ## Signals
393 ///
394 ///
395 /// #### `offset-changed`
396 /// Emitted when an offset specified on the bar changes value.
397 ///
398 /// This typically is the result of a [`LevelBar::add_offset_value()`][crate::LevelBar::add_offset_value()]
399 /// call.
400 ///
401 /// The signal supports detailed connections; you can connect to the
402 /// detailed signal "changed::x" in order to only receive callbacks when
403 /// the value of offset "x" changes.
404 ///
405 /// Detailed
406 /// <details><summary><h4>Widget</h4></summary>
407 ///
408 ///
409 /// #### `destroy`
410 /// Signals that all holders of a reference to the widget should release
411 /// the reference that they hold.
412 ///
413 /// May result in finalization of the widget if all references are released.
414 ///
415 /// This signal is not suitable for saving widget state.
416 ///
417 ///
418 ///
419 ///
420 /// #### `direction-changed`
421 /// Emitted when the text direction of a widget changes.
422 ///
423 ///
424 ///
425 ///
426 /// #### `hide`
427 /// Emitted when @widget is hidden.
428 ///
429 ///
430 ///
431 ///
432 /// #### `keynav-failed`
433 /// Emitted if keyboard navigation fails.
434 ///
435 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
436 ///
437 ///
438 ///
439 ///
440 /// #### `map`
441 /// Emitted when @widget is going to be mapped.
442 ///
443 /// A widget is mapped when the widget is visible (which is controlled with
444 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
445 /// are also visible.
446 ///
447 /// The `::map` signal can be used to determine whether a widget will be drawn,
448 /// for instance it can resume an animation that was stopped during the
449 /// emission of [`unmap`][struct@crate::Widget#unmap].
450 ///
451 ///
452 ///
453 ///
454 /// #### `mnemonic-activate`
455 /// Emitted when a widget is activated via a mnemonic.
456 ///
457 /// The default handler for this signal activates @widget if @group_cycling
458 /// is false, or just makes @widget grab focus if @group_cycling is true.
459 ///
460 ///
461 ///
462 ///
463 /// #### `move-focus`
464 /// to move backward.
465 ///
466 /// Action
467 ///
468 ///
469 /// #### `query-tooltip`
470 /// s tooltip is about to be shown.
471 ///
472 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
473 /// is true and the hover timeout has expired with the cursor hovering
474 /// above @widget; or emitted when @widget got focus in keyboard mode.
475 ///
476 /// Using the given coordinates, the signal handler should determine
477 /// whether a tooltip should be shown for @widget. If this is the case
478 /// true should be returned, false otherwise. Note that if @keyboard_mode
479 /// is true, the values of @x and @y are undefined and should not be used.
480 ///
481 /// The signal handler is free to manipulate @tooltip with the therefore
482 /// destined function calls.
483 ///
484 ///
485 ///
486 ///
487 /// #### `realize`
488 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
489 ///
490 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
491 /// or the widget has been mapped (that is, it is going to be drawn).
492 ///
493 ///
494 ///
495 ///
496 /// #### `show`
497 /// Emitted when @widget is shown.
498 ///
499 ///
500 ///
501 ///
502 /// #### `state-flags-changed`
503 /// Emitted when the widget state changes.
504 ///
505 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
506 ///
507 ///
508 ///
509 ///
510 /// #### `unmap`
511 /// Emitted when @widget is going to be unmapped.
512 ///
513 /// A widget is unmapped when either it or any of its parents up to the
514 /// toplevel widget have been set as hidden.
515 ///
516 /// As `::unmap` indicates that a widget will not be shown any longer,
517 /// it can be used to, for example, stop an animation on the widget.
518 ///
519 ///
520 ///
521 ///
522 /// #### `unrealize`
523 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
524 ///
525 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
526 /// or the widget has been unmapped (that is, it is going to be hidden).
527 ///
528 ///
529 /// </details>
530 ///
531 /// # Implements
532 ///
533 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`AccessibleRangeExt`][trait@crate::prelude::AccessibleRangeExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
534 #[doc(alias = "GtkLevelBar")]
535 pub struct LevelBar(Object<ffi::GtkLevelBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
536
537 match fn {
538 type_ => || ffi::gtk_level_bar_get_type(),
539 }
540}
541
542#[cfg(not(feature = "v4_10"))]
543glib::wrapper! {
544 #[doc(alias = "GtkLevelBar")]
545 pub struct LevelBar(Object<ffi::GtkLevelBar>) @extends Widget, @implements Buildable, ConstraintTarget, Orientable;
546
547 match fn {
548 type_ => || ffi::gtk_level_bar_get_type(),
549 }
550}
551
552impl LevelBar {
553 /// Creates a new [`LevelBar`][crate::LevelBar].
554 ///
555 /// # Returns
556 ///
557 /// a [`LevelBar`][crate::LevelBar].
558 #[doc(alias = "gtk_level_bar_new")]
559 pub fn new() -> LevelBar {
560 assert_initialized_main_thread!();
561 unsafe { Widget::from_glib_none(ffi::gtk_level_bar_new()).unsafe_cast() }
562 }
563
564 /// Creates a new [`LevelBar`][crate::LevelBar] for the specified interval.
565 /// ## `min_value`
566 /// a positive value
567 /// ## `max_value`
568 /// a positive value
569 ///
570 /// # Returns
571 ///
572 /// a [`LevelBar`][crate::LevelBar]
573 #[doc(alias = "gtk_level_bar_new_for_interval")]
574 #[doc(alias = "new_for_interval")]
575 pub fn for_interval(min_value: f64, max_value: f64) -> LevelBar {
576 assert_initialized_main_thread!();
577 unsafe {
578 Widget::from_glib_none(ffi::gtk_level_bar_new_for_interval(min_value, max_value))
579 .unsafe_cast()
580 }
581 }
582
583 // rustdoc-stripper-ignore-next
584 /// Creates a new builder-pattern struct instance to construct [`LevelBar`] objects.
585 ///
586 /// This method returns an instance of [`LevelBarBuilder`](crate::builders::LevelBarBuilder) which can be used to create [`LevelBar`] objects.
587 pub fn builder() -> LevelBarBuilder {
588 LevelBarBuilder::new()
589 }
590
591 /// Adds a new offset marker on @self at the position specified by @value.
592 ///
593 /// When the bar value is in the interval topped by @value (or between @value
594 /// and [`max-value`][struct@crate::LevelBar#max-value] in case the offset is the last one
595 /// on the bar) a style class named `level-`@name will be applied
596 /// when rendering the level bar fill.
597 ///
598 /// If another offset marker named @name exists, its value will be
599 /// replaced by @value.
600 /// ## `name`
601 /// the name of the new offset
602 /// ## `value`
603 /// the value for the new offset
604 #[doc(alias = "gtk_level_bar_add_offset_value")]
605 pub fn add_offset_value(&self, name: &str, value: f64) {
606 unsafe {
607 ffi::gtk_level_bar_add_offset_value(
608 self.to_glib_none().0,
609 name.to_glib_none().0,
610 value,
611 );
612 }
613 }
614
615 /// Returns whether the levelbar is inverted.
616 ///
617 /// # Returns
618 ///
619 /// [`true`] if the level bar is inverted
620 #[doc(alias = "gtk_level_bar_get_inverted")]
621 #[doc(alias = "get_inverted")]
622 #[doc(alias = "inverted")]
623 pub fn is_inverted(&self) -> bool {
624 unsafe { from_glib(ffi::gtk_level_bar_get_inverted(self.to_glib_none().0)) }
625 }
626
627 /// Returns the `max-value` of the [`LevelBar`][crate::LevelBar].
628 ///
629 /// # Returns
630 ///
631 /// a positive value
632 #[doc(alias = "gtk_level_bar_get_max_value")]
633 #[doc(alias = "get_max_value")]
634 #[doc(alias = "max-value")]
635 pub fn max_value(&self) -> f64 {
636 unsafe { ffi::gtk_level_bar_get_max_value(self.to_glib_none().0) }
637 }
638
639 /// Returns the `min-value` of the [`LevelBar`][crate::LevelBar].
640 ///
641 /// # Returns
642 ///
643 /// a positive value
644 #[doc(alias = "gtk_level_bar_get_min_value")]
645 #[doc(alias = "get_min_value")]
646 #[doc(alias = "min-value")]
647 pub fn min_value(&self) -> f64 {
648 unsafe { ffi::gtk_level_bar_get_min_value(self.to_glib_none().0) }
649 }
650
651 /// Returns the `mode` of the [`LevelBar`][crate::LevelBar].
652 ///
653 /// # Returns
654 ///
655 /// a [`LevelBarMode`][crate::LevelBarMode]
656 #[doc(alias = "gtk_level_bar_get_mode")]
657 #[doc(alias = "get_mode")]
658 pub fn mode(&self) -> LevelBarMode {
659 unsafe { from_glib(ffi::gtk_level_bar_get_mode(self.to_glib_none().0)) }
660 }
661
662 /// Fetches the value specified for the offset marker @name in @self.
663 /// ## `name`
664 /// the name of an offset in the bar
665 ///
666 /// # Returns
667 ///
668 /// [`true`] if the specified offset is found
669 ///
670 /// ## `value`
671 /// location where to store the value
672 #[doc(alias = "gtk_level_bar_get_offset_value")]
673 #[doc(alias = "get_offset_value")]
674 pub fn offset_value(&self, name: Option<&str>) -> Option<f64> {
675 unsafe {
676 let mut value = std::mem::MaybeUninit::uninit();
677 let ret = from_glib(ffi::gtk_level_bar_get_offset_value(
678 self.to_glib_none().0,
679 name.to_glib_none().0,
680 value.as_mut_ptr(),
681 ));
682 if ret { Some(value.assume_init()) } else { None }
683 }
684 }
685
686 /// Returns the `value` of the [`LevelBar`][crate::LevelBar].
687 ///
688 /// # Returns
689 ///
690 /// a value in the interval between
691 /// [`min-value`][struct@crate::LevelBar#min-value] and [`max-value`][struct@crate::LevelBar#max-value]
692 #[doc(alias = "gtk_level_bar_get_value")]
693 #[doc(alias = "get_value")]
694 pub fn value(&self) -> f64 {
695 unsafe { ffi::gtk_level_bar_get_value(self.to_glib_none().0) }
696 }
697
698 /// Removes an offset marker from a [`LevelBar`][crate::LevelBar].
699 ///
700 /// The marker must have been previously added with
701 /// [`add_offset_value()`][Self::add_offset_value()].
702 /// ## `name`
703 /// the name of an offset in the bar
704 #[doc(alias = "gtk_level_bar_remove_offset_value")]
705 pub fn remove_offset_value(&self, name: Option<&str>) {
706 unsafe {
707 ffi::gtk_level_bar_remove_offset_value(self.to_glib_none().0, name.to_glib_none().0);
708 }
709 }
710
711 /// Sets whether the [`LevelBar`][crate::LevelBar] is inverted.
712 /// ## `inverted`
713 /// [`true`] to invert the level bar
714 #[doc(alias = "gtk_level_bar_set_inverted")]
715 #[doc(alias = "inverted")]
716 pub fn set_inverted(&self, inverted: bool) {
717 unsafe {
718 ffi::gtk_level_bar_set_inverted(self.to_glib_none().0, inverted.into_glib());
719 }
720 }
721
722 /// Sets the `max-value` of the [`LevelBar`][crate::LevelBar].
723 ///
724 /// You probably want to update preexisting level offsets after calling
725 /// this function.
726 /// ## `value`
727 /// a positive value
728 #[doc(alias = "gtk_level_bar_set_max_value")]
729 #[doc(alias = "max-value")]
730 pub fn set_max_value(&self, value: f64) {
731 unsafe {
732 ffi::gtk_level_bar_set_max_value(self.to_glib_none().0, value);
733 }
734 }
735
736 /// Sets the `min-value` of the [`LevelBar`][crate::LevelBar].
737 ///
738 /// You probably want to update preexisting level offsets after calling
739 /// this function.
740 /// ## `value`
741 /// a positive value
742 #[doc(alias = "gtk_level_bar_set_min_value")]
743 #[doc(alias = "min-value")]
744 pub fn set_min_value(&self, value: f64) {
745 unsafe {
746 ffi::gtk_level_bar_set_min_value(self.to_glib_none().0, value);
747 }
748 }
749
750 /// Sets the `mode` of the [`LevelBar`][crate::LevelBar].
751 /// ## `mode`
752 /// a [`LevelBarMode`][crate::LevelBarMode]
753 #[doc(alias = "gtk_level_bar_set_mode")]
754 #[doc(alias = "mode")]
755 pub fn set_mode(&self, mode: LevelBarMode) {
756 unsafe {
757 ffi::gtk_level_bar_set_mode(self.to_glib_none().0, mode.into_glib());
758 }
759 }
760
761 /// Sets the value of the [`LevelBar`][crate::LevelBar].
762 /// ## `value`
763 /// a value in the interval between
764 /// [`min-value`][struct@crate::LevelBar#min-value] and [`max-value`][struct@crate::LevelBar#max-value]
765 #[doc(alias = "gtk_level_bar_set_value")]
766 #[doc(alias = "value")]
767 pub fn set_value(&self, value: f64) {
768 unsafe {
769 ffi::gtk_level_bar_set_value(self.to_glib_none().0, value);
770 }
771 }
772
773 /// Emitted when an offset specified on the bar changes value.
774 ///
775 /// This typically is the result of a [`add_offset_value()`][Self::add_offset_value()]
776 /// call.
777 ///
778 /// The signal supports detailed connections; you can connect to the
779 /// detailed signal "changed::x" in order to only receive callbacks when
780 /// the value of offset "x" changes.
781 /// ## `name`
782 /// the name of the offset that changed value
783 #[doc(alias = "offset-changed")]
784 pub fn connect_offset_changed<F: Fn(&Self, &str) + 'static>(
785 &self,
786 detail: Option<&str>,
787 f: F,
788 ) -> SignalHandlerId {
789 unsafe extern "C" fn offset_changed_trampoline<F: Fn(&LevelBar, &str) + 'static>(
790 this: *mut ffi::GtkLevelBar,
791 name: *mut std::ffi::c_char,
792 f: glib::ffi::gpointer,
793 ) {
794 unsafe {
795 let f: &F = &*(f as *const F);
796 f(
797 &from_glib_borrow(this),
798 &glib::GString::from_glib_borrow(name),
799 )
800 }
801 }
802 unsafe {
803 let f: Box_<F> = Box_::new(f);
804 let detailed_signal_name = detail.map(|name| format!("offset-changed::{name}\0"));
805 let signal_name = detailed_signal_name
806 .as_ref()
807 .map_or(c"offset-changed", |n| {
808 std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
809 });
810 connect_raw(
811 self.as_ptr() as *mut _,
812 signal_name.as_ptr(),
813 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
814 offset_changed_trampoline::<F> as *const (),
815 )),
816 Box_::into_raw(f),
817 )
818 }
819 }
820
821 #[doc(alias = "inverted")]
822 pub fn connect_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
823 unsafe extern "C" fn notify_inverted_trampoline<F: Fn(&LevelBar) + 'static>(
824 this: *mut ffi::GtkLevelBar,
825 _param_spec: glib::ffi::gpointer,
826 f: glib::ffi::gpointer,
827 ) {
828 unsafe {
829 let f: &F = &*(f as *const F);
830 f(&from_glib_borrow(this))
831 }
832 }
833 unsafe {
834 let f: Box_<F> = Box_::new(f);
835 connect_raw(
836 self.as_ptr() as *mut _,
837 c"notify::inverted".as_ptr(),
838 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
839 notify_inverted_trampoline::<F> as *const (),
840 )),
841 Box_::into_raw(f),
842 )
843 }
844 }
845
846 #[doc(alias = "max-value")]
847 pub fn connect_max_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
848 unsafe extern "C" fn notify_max_value_trampoline<F: Fn(&LevelBar) + 'static>(
849 this: *mut ffi::GtkLevelBar,
850 _param_spec: glib::ffi::gpointer,
851 f: glib::ffi::gpointer,
852 ) {
853 unsafe {
854 let f: &F = &*(f as *const F);
855 f(&from_glib_borrow(this))
856 }
857 }
858 unsafe {
859 let f: Box_<F> = Box_::new(f);
860 connect_raw(
861 self.as_ptr() as *mut _,
862 c"notify::max-value".as_ptr(),
863 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
864 notify_max_value_trampoline::<F> as *const (),
865 )),
866 Box_::into_raw(f),
867 )
868 }
869 }
870
871 #[doc(alias = "min-value")]
872 pub fn connect_min_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
873 unsafe extern "C" fn notify_min_value_trampoline<F: Fn(&LevelBar) + 'static>(
874 this: *mut ffi::GtkLevelBar,
875 _param_spec: glib::ffi::gpointer,
876 f: glib::ffi::gpointer,
877 ) {
878 unsafe {
879 let f: &F = &*(f as *const F);
880 f(&from_glib_borrow(this))
881 }
882 }
883 unsafe {
884 let f: Box_<F> = Box_::new(f);
885 connect_raw(
886 self.as_ptr() as *mut _,
887 c"notify::min-value".as_ptr(),
888 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
889 notify_min_value_trampoline::<F> as *const (),
890 )),
891 Box_::into_raw(f),
892 )
893 }
894 }
895
896 #[doc(alias = "mode")]
897 pub fn connect_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
898 unsafe extern "C" fn notify_mode_trampoline<F: Fn(&LevelBar) + 'static>(
899 this: *mut ffi::GtkLevelBar,
900 _param_spec: glib::ffi::gpointer,
901 f: glib::ffi::gpointer,
902 ) {
903 unsafe {
904 let f: &F = &*(f as *const F);
905 f(&from_glib_borrow(this))
906 }
907 }
908 unsafe {
909 let f: Box_<F> = Box_::new(f);
910 connect_raw(
911 self.as_ptr() as *mut _,
912 c"notify::mode".as_ptr(),
913 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
914 notify_mode_trampoline::<F> as *const (),
915 )),
916 Box_::into_raw(f),
917 )
918 }
919 }
920
921 #[doc(alias = "value")]
922 pub fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
923 unsafe extern "C" fn notify_value_trampoline<F: Fn(&LevelBar) + 'static>(
924 this: *mut ffi::GtkLevelBar,
925 _param_spec: glib::ffi::gpointer,
926 f: glib::ffi::gpointer,
927 ) {
928 unsafe {
929 let f: &F = &*(f as *const F);
930 f(&from_glib_borrow(this))
931 }
932 }
933 unsafe {
934 let f: Box_<F> = Box_::new(f);
935 connect_raw(
936 self.as_ptr() as *mut _,
937 c"notify::value".as_ptr(),
938 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
939 notify_value_trampoline::<F> as *const (),
940 )),
941 Box_::into_raw(f),
942 )
943 }
944 }
945}
946
947impl Default for LevelBar {
948 fn default() -> Self {
949 Self::new()
950 }
951}
952
953// rustdoc-stripper-ignore-next
954/// A [builder-pattern] type to construct [`LevelBar`] objects.
955///
956/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
957#[must_use = "The builder must be built to be used"]
958pub struct LevelBarBuilder {
959 builder: glib::object::ObjectBuilder<'static, LevelBar>,
960}
961
962impl LevelBarBuilder {
963 fn new() -> Self {
964 Self {
965 builder: glib::object::Object::builder(),
966 }
967 }
968
969 /// Whether the `GtkLeveBar` is inverted.
970 ///
971 /// Level bars normally grow from top to bottom or left to right.
972 /// Inverted level bars grow in the opposite direction.
973 pub fn inverted(self, inverted: bool) -> Self {
974 Self {
975 builder: self.builder.property("inverted", inverted),
976 }
977 }
978
979 /// Determines the maximum value of the interval that can be displayed by the bar.
980 pub fn max_value(self, max_value: f64) -> Self {
981 Self {
982 builder: self.builder.property("max-value", max_value),
983 }
984 }
985
986 /// Determines the minimum value of the interval that can be displayed by the bar.
987 pub fn min_value(self, min_value: f64) -> Self {
988 Self {
989 builder: self.builder.property("min-value", min_value),
990 }
991 }
992
993 /// Determines the way [`LevelBar`][crate::LevelBar] interprets the value properties to draw the
994 /// level fill area.
995 ///
996 /// Specifically, when the value is [`LevelBarMode::Continuous`][crate::LevelBarMode::Continuous],
997 /// [`LevelBar`][crate::LevelBar] will draw a single block representing the current value in
998 /// that area; when the value is [`LevelBarMode::Discrete`][crate::LevelBarMode::Discrete],
999 /// the widget will draw a succession of separate blocks filling the
1000 /// draw area, with the number of blocks being equal to the units separating
1001 /// the integral roundings of [`min-value`][struct@crate::LevelBar#min-value] and
1002 /// [`max-value`][struct@crate::LevelBar#max-value].
1003 pub fn mode(self, mode: LevelBarMode) -> Self {
1004 Self {
1005 builder: self.builder.property("mode", mode),
1006 }
1007 }
1008
1009 /// Determines the currently filled value of the level bar.
1010 pub fn value(self, value: f64) -> Self {
1011 Self {
1012 builder: self.builder.property("value", value),
1013 }
1014 }
1015
1016 /// Whether the widget or any of its descendents can accept
1017 /// the input focus.
1018 ///
1019 /// This property is meant to be set by widget implementations,
1020 /// typically in their instance init function.
1021 pub fn can_focus(self, can_focus: bool) -> Self {
1022 Self {
1023 builder: self.builder.property("can-focus", can_focus),
1024 }
1025 }
1026
1027 /// Whether the widget can receive pointer events.
1028 pub fn can_target(self, can_target: bool) -> Self {
1029 Self {
1030 builder: self.builder.property("can-target", can_target),
1031 }
1032 }
1033
1034 /// A list of css classes applied to this widget.
1035 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
1036 Self {
1037 builder: self.builder.property("css-classes", css_classes.into()),
1038 }
1039 }
1040
1041 /// The name of this widget in the CSS tree.
1042 ///
1043 /// This property is meant to be set by widget implementations,
1044 /// typically in their instance init function.
1045 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
1046 Self {
1047 builder: self.builder.property("css-name", css_name.into()),
1048 }
1049 }
1050
1051 /// The cursor used by @widget.
1052 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
1053 Self {
1054 builder: self.builder.property("cursor", cursor.clone()),
1055 }
1056 }
1057
1058 /// Whether the widget should grab focus when it is clicked with the mouse.
1059 ///
1060 /// This property is only relevant for widgets that can take focus.
1061 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1062 Self {
1063 builder: self.builder.property("focus-on-click", focus_on_click),
1064 }
1065 }
1066
1067 /// Whether this widget itself will accept the input focus.
1068 pub fn focusable(self, focusable: bool) -> Self {
1069 Self {
1070 builder: self.builder.property("focusable", focusable),
1071 }
1072 }
1073
1074 /// How to distribute horizontal space if widget gets extra space.
1075 pub fn halign(self, halign: Align) -> Self {
1076 Self {
1077 builder: self.builder.property("halign", halign),
1078 }
1079 }
1080
1081 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1082 /// signal on @widget.
1083 ///
1084 /// A true value indicates that @widget can have a tooltip, in this case
1085 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1086 /// determine whether it will provide a tooltip or not.
1087 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1088 Self {
1089 builder: self.builder.property("has-tooltip", has_tooltip),
1090 }
1091 }
1092
1093 /// Overrides for height request of the widget.
1094 ///
1095 /// If this is -1, the natural request will be used.
1096 pub fn height_request(self, height_request: i32) -> Self {
1097 Self {
1098 builder: self.builder.property("height-request", height_request),
1099 }
1100 }
1101
1102 /// Whether to expand horizontally.
1103 pub fn hexpand(self, hexpand: bool) -> Self {
1104 Self {
1105 builder: self.builder.property("hexpand", hexpand),
1106 }
1107 }
1108
1109 /// Whether to use the `hexpand` property.
1110 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1111 Self {
1112 builder: self.builder.property("hexpand-set", hexpand_set),
1113 }
1114 }
1115
1116 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1117 /// the preferred size of the widget, and allocate its children.
1118 ///
1119 /// This property is meant to be set by widget implementations,
1120 /// typically in their instance init function.
1121 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1122 Self {
1123 builder: self
1124 .builder
1125 .property("layout-manager", layout_manager.clone().upcast()),
1126 }
1127 }
1128
1129 /// Makes this widget act like a modal dialog, with respect to
1130 /// event delivery.
1131 ///
1132 /// Global event controllers will not handle events with targets
1133 /// inside the widget, unless they are set up to ignore propagation
1134 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1135 #[cfg(feature = "v4_18")]
1136 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1137 pub fn limit_events(self, limit_events: bool) -> Self {
1138 Self {
1139 builder: self.builder.property("limit-events", limit_events),
1140 }
1141 }
1142
1143 /// Margin on bottom side of widget.
1144 ///
1145 /// This property adds margin outside of the widget's normal size
1146 /// request, the margin will be added in addition to the size from
1147 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1148 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1149 Self {
1150 builder: self.builder.property("margin-bottom", margin_bottom),
1151 }
1152 }
1153
1154 /// Margin on end of widget, horizontally.
1155 ///
1156 /// This property supports left-to-right and right-to-left text
1157 /// directions.
1158 ///
1159 /// This property adds margin outside of the widget's normal size
1160 /// request, the margin will be added in addition to the size from
1161 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1162 pub fn margin_end(self, margin_end: i32) -> Self {
1163 Self {
1164 builder: self.builder.property("margin-end", margin_end),
1165 }
1166 }
1167
1168 /// Margin on start of widget, horizontally.
1169 ///
1170 /// This property supports left-to-right and right-to-left text
1171 /// directions.
1172 ///
1173 /// This property adds margin outside of the widget's normal size
1174 /// request, the margin will be added in addition to the size from
1175 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1176 pub fn margin_start(self, margin_start: i32) -> Self {
1177 Self {
1178 builder: self.builder.property("margin-start", margin_start),
1179 }
1180 }
1181
1182 /// Margin on top side of widget.
1183 ///
1184 /// This property adds margin outside of the widget's normal size
1185 /// request, the margin will be added in addition to the size from
1186 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1187 pub fn margin_top(self, margin_top: i32) -> Self {
1188 Self {
1189 builder: self.builder.property("margin-top", margin_top),
1190 }
1191 }
1192
1193 /// The name of the widget.
1194 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1195 Self {
1196 builder: self.builder.property("name", name.into()),
1197 }
1198 }
1199
1200 /// The requested opacity of the widget.
1201 pub fn opacity(self, opacity: f64) -> Self {
1202 Self {
1203 builder: self.builder.property("opacity", opacity),
1204 }
1205 }
1206
1207 /// How content outside the widget's content area is treated.
1208 ///
1209 /// This property is meant to be set by widget implementations,
1210 /// typically in their instance init function.
1211 pub fn overflow(self, overflow: Overflow) -> Self {
1212 Self {
1213 builder: self.builder.property("overflow", overflow),
1214 }
1215 }
1216
1217 /// Whether the widget will receive the default action when it is focused.
1218 pub fn receives_default(self, receives_default: bool) -> Self {
1219 Self {
1220 builder: self.builder.property("receives-default", receives_default),
1221 }
1222 }
1223
1224 /// Whether the widget responds to input.
1225 pub fn sensitive(self, sensitive: bool) -> Self {
1226 Self {
1227 builder: self.builder.property("sensitive", sensitive),
1228 }
1229 }
1230
1231 /// Sets the text of tooltip to be the given string, which is marked up
1232 /// with Pango markup.
1233 ///
1234 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1235 ///
1236 /// This is a convenience property which will take care of getting the
1237 /// tooltip shown if the given string is not `NULL`:
1238 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1239 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1240 /// the default signal handler.
1241 ///
1242 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1243 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1244 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1245 Self {
1246 builder: self
1247 .builder
1248 .property("tooltip-markup", tooltip_markup.into()),
1249 }
1250 }
1251
1252 /// Sets the text of tooltip to be the given string.
1253 ///
1254 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1255 ///
1256 /// This is a convenience property which will take care of getting the
1257 /// tooltip shown if the given string is not `NULL`:
1258 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1259 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1260 /// the default signal handler.
1261 ///
1262 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1263 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1264 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1265 Self {
1266 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1267 }
1268 }
1269
1270 /// How to distribute vertical space if widget gets extra space.
1271 pub fn valign(self, valign: Align) -> Self {
1272 Self {
1273 builder: self.builder.property("valign", valign),
1274 }
1275 }
1276
1277 /// Whether to expand vertically.
1278 pub fn vexpand(self, vexpand: bool) -> Self {
1279 Self {
1280 builder: self.builder.property("vexpand", vexpand),
1281 }
1282 }
1283
1284 /// Whether to use the `vexpand` property.
1285 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1286 Self {
1287 builder: self.builder.property("vexpand-set", vexpand_set),
1288 }
1289 }
1290
1291 /// Whether the widget is visible.
1292 pub fn visible(self, visible: bool) -> Self {
1293 Self {
1294 builder: self.builder.property("visible", visible),
1295 }
1296 }
1297
1298 /// Overrides for width request of the widget.
1299 ///
1300 /// If this is -1, the natural request will be used.
1301 pub fn width_request(self, width_request: i32) -> Self {
1302 Self {
1303 builder: self.builder.property("width-request", width_request),
1304 }
1305 }
1306
1307 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1308 ///
1309 /// The accessible role cannot be changed once set.
1310 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1311 Self {
1312 builder: self.builder.property("accessible-role", accessible_role),
1313 }
1314 }
1315
1316 /// The orientation of the orientable.
1317 pub fn orientation(self, orientation: Orientation) -> Self {
1318 Self {
1319 builder: self.builder.property("orientation", orientation),
1320 }
1321 }
1322
1323 // rustdoc-stripper-ignore-next
1324 /// Build the [`LevelBar`].
1325 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1326 pub fn build(self) -> LevelBar {
1327 assert_initialized_main_thread!();
1328 self.builder.build()
1329 }
1330}