gtk4/auto/tree_expander.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::{
6 Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7 TreeListRow, Widget, ffi,
8};
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 /// Provides an expander for a tree-like list.
18 ///
19 /// It is typically placed as a bottommost child into a [`ListView`][crate::ListView]
20 /// to allow users to expand and collapse children in a list with a
21 /// [`TreeListModel`][crate::TreeListModel]. [`TreeExpander`][crate::TreeExpander] provides the common UI
22 /// elements, gestures and keybindings for this purpose.
23 ///
24 /// On top of this, the "listitem.expand", "listitem.collapse" and
25 /// "listitem.toggle-expand" actions are provided to allow adding custom
26 /// UI for managing expanded state.
27 ///
28 /// It is important to mention that you want to set the
29 /// [`focusable`][struct@crate::ListItem#focusable] property to FALSE when using this
30 /// widget, as you want the keyboard focus to be in the treexpander, and not
31 /// inside the list to make use of the keybindings.
32 ///
33 /// The [`TreeListModel`][crate::TreeListModel] must be set to not be passthrough. Then it
34 /// will provide [`TreeListRow`][crate::TreeListRow] items which can be set via
35 /// [`set_list_row()`][Self::set_list_row()] on the expander.
36 /// The expander will then watch that row item automatically.
37 /// [`set_child()`][Self::set_child()] sets the widget that displays
38 /// the actual row contents.
39 ///
40 /// [`TreeExpander`][crate::TreeExpander] can be modified with properties such as
41 /// [`indent-for-icon`][struct@crate::TreeExpander#indent-for-icon],
42 /// [`indent-for-depth`][struct@crate::TreeExpander#indent-for-depth], and
43 /// [`hide-expander`][struct@crate::TreeExpander#hide-expander] to achieve a different appearance.
44 /// This can even be done to influence individual rows, for example by binding
45 /// the [`hide-expander`][struct@crate::TreeExpander#hide-expander] property to the item count of
46 /// the model of the treelistrow, to hide the expander for rows without children,
47 /// even if the row is expandable.
48 ///
49 /// ## Shortcuts and Gestures
50 ///
51 /// [`TreeExpander`][crate::TreeExpander] supports the following keyboard shortcuts:
52 ///
53 /// - <kbd>+</kbd> or <kbd>*</kbd> expands the expander.
54 /// - <kbd>-</kbd> or <kbd>/</kbd> collapses the expander.
55 /// - Left and right arrow keys, when combined with <kbd>Shift</kbd> or
56 /// <kbd>Ctrl</kbd>+<kbd>Shift</kbd>, will expand or collapse, depending on
57 /// the locale's text direction.
58 /// - <kbd>Ctrl</kbd>+<kbd>␣</kbd> toggles the expander state.
59 ///
60 /// The row can also expand on drag gestures.
61 ///
62 /// ## Actions
63 ///
64 /// [`TreeExpander`][crate::TreeExpander] defines a set of built-in actions:
65 ///
66 /// - `listitem.expand` expands the expander if it can be expanded.
67 /// - `listitem.collapse` collapses the expander.
68 /// - `listitem.toggle-expand` tries to expand the expander if it was collapsed
69 /// or collapses it if it was expanded.
70 ///
71 /// ## CSS nodes
72 ///
73 /// ```text
74 /// treeexpander
75 /// ├── [indent]*
76 /// ├── [expander]
77 /// ╰── <child>
78 /// ```
79 ///
80 /// [`TreeExpander`][crate::TreeExpander] has zero or one CSS nodes with the name "expander" that
81 /// should display the expander icon. The node will be `:checked` when it
82 /// is expanded. If the node is not expandable, an "indent" node will be
83 /// displayed instead.
84 ///
85 /// For every level of depth, another "indent" node is prepended.
86 ///
87 /// ## Accessibility
88 ///
89 /// Until GTK 4.10, [`TreeExpander`][crate::TreeExpander] used the [enum@Gtk.AccessibleRole.group] role.
90 ///
91 /// Since GTK 4.12, [`TreeExpander`][crate::TreeExpander] uses the [enum@Gtk.AccessibleRole.button] role.
92 /// Toggling it will change the `GTK_ACCESSIBLE_STATE_EXPANDED` state.
93 ///
94 /// ## Properties
95 ///
96 ///
97 /// #### `child`
98 /// The child widget with the actual contents.
99 ///
100 /// Readable | Writeable
101 ///
102 ///
103 /// #### `hide-expander`
104 /// Whether the expander icon should be hidden in a GtkTreeListRow.
105 /// Note that this property simply hides the icon. The actions and keybinding
106 /// (i.e. collapse and expand) are not affected by this property.
107 ///
108 /// A common use for this property would be to bind to the number of children in a
109 /// GtkTreeListRow's model in order to hide the expander when a row has no children.
110 ///
111 /// Readable | Writeable
112 ///
113 ///
114 /// #### `indent-for-depth`
115 /// TreeExpander indents the child according to its depth.
116 ///
117 /// Readable | Writeable
118 ///
119 ///
120 /// #### `indent-for-icon`
121 /// TreeExpander indents the child by the width of an expander-icon if it is not expandable.
122 ///
123 /// Readable | Writeable
124 ///
125 ///
126 /// #### `item`
127 /// The item held by this expander's row.
128 ///
129 /// Readable
130 ///
131 ///
132 /// #### `list-row`
133 /// The list row to track for expander state.
134 ///
135 /// Readable | Writeable
136 /// <details><summary><h4>Widget</h4></summary>
137 ///
138 ///
139 /// #### `can-focus`
140 /// Whether the widget or any of its descendents can accept
141 /// the input focus.
142 ///
143 /// This property is meant to be set by widget implementations,
144 /// typically in their instance init function.
145 ///
146 /// Readable | Writeable
147 ///
148 ///
149 /// #### `can-target`
150 /// Whether the widget can receive pointer events.
151 ///
152 /// Readable | Writeable
153 ///
154 ///
155 /// #### `css-classes`
156 /// A list of css classes applied to this widget.
157 ///
158 /// Readable | Writeable
159 ///
160 ///
161 /// #### `css-name`
162 /// The name of this widget in the CSS tree.
163 ///
164 /// This property is meant to be set by widget implementations,
165 /// typically in their instance init function.
166 ///
167 /// Readable | Writeable | Construct Only
168 ///
169 ///
170 /// #### `cursor`
171 /// The cursor used by @widget.
172 ///
173 /// Readable | Writeable
174 ///
175 ///
176 /// #### `focus-on-click`
177 /// Whether the widget should grab focus when it is clicked with the mouse.
178 ///
179 /// This property is only relevant for widgets that can take focus.
180 ///
181 /// Readable | Writeable
182 ///
183 ///
184 /// #### `focusable`
185 /// Whether this widget itself will accept the input focus.
186 ///
187 /// Readable | Writeable
188 ///
189 ///
190 /// #### `halign`
191 /// How to distribute horizontal space if widget gets extra space.
192 ///
193 /// Readable | Writeable
194 ///
195 ///
196 /// #### `has-default`
197 /// Whether the widget is the default widget.
198 ///
199 /// Readable
200 ///
201 ///
202 /// #### `has-focus`
203 /// Whether the widget has the input focus.
204 ///
205 /// Readable
206 ///
207 ///
208 /// #### `has-tooltip`
209 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
210 /// signal on @widget.
211 ///
212 /// A true value indicates that @widget can have a tooltip, in this case
213 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
214 /// determine whether it will provide a tooltip or not.
215 ///
216 /// Readable | Writeable
217 ///
218 ///
219 /// #### `height-request`
220 /// Overrides for height request of the widget.
221 ///
222 /// If this is -1, the natural request will be used.
223 ///
224 /// Readable | Writeable
225 ///
226 ///
227 /// #### `hexpand`
228 /// Whether to expand horizontally.
229 ///
230 /// Readable | Writeable
231 ///
232 ///
233 /// #### `hexpand-set`
234 /// Whether to use the `hexpand` property.
235 ///
236 /// Readable | Writeable
237 ///
238 ///
239 /// #### `layout-manager`
240 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
241 /// the preferred size of the widget, and allocate its children.
242 ///
243 /// This property is meant to be set by widget implementations,
244 /// typically in their instance init function.
245 ///
246 /// Readable | Writeable
247 ///
248 ///
249 /// #### `limit-events`
250 /// Makes this widget act like a modal dialog, with respect to
251 /// event delivery.
252 ///
253 /// Global event controllers will not handle events with targets
254 /// inside the widget, unless they are set up to ignore propagation
255 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
256 ///
257 /// Readable | Writeable
258 ///
259 ///
260 /// #### `margin-bottom`
261 /// Margin on bottom side of widget.
262 ///
263 /// This property adds margin outside of the widget's normal size
264 /// request, the margin will be added in addition to the size from
265 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
266 ///
267 /// Readable | Writeable
268 ///
269 ///
270 /// #### `margin-end`
271 /// Margin on end of widget, horizontally.
272 ///
273 /// This property supports left-to-right and right-to-left text
274 /// directions.
275 ///
276 /// This property adds margin outside of the widget's normal size
277 /// request, the margin will be added in addition to the size from
278 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
279 ///
280 /// Readable | Writeable
281 ///
282 ///
283 /// #### `margin-start`
284 /// Margin on start of widget, horizontally.
285 ///
286 /// This property supports left-to-right and right-to-left text
287 /// directions.
288 ///
289 /// This property adds margin outside of the widget's normal size
290 /// request, the margin will be added in addition to the size from
291 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
292 ///
293 /// Readable | Writeable
294 ///
295 ///
296 /// #### `margin-top`
297 /// Margin on top side of widget.
298 ///
299 /// This property adds margin outside of the widget's normal size
300 /// request, the margin will be added in addition to the size from
301 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
302 ///
303 /// Readable | Writeable
304 ///
305 ///
306 /// #### `name`
307 /// The name of the widget.
308 ///
309 /// Readable | Writeable
310 ///
311 ///
312 /// #### `opacity`
313 /// The requested opacity of the widget.
314 ///
315 /// Readable | Writeable
316 ///
317 ///
318 /// #### `overflow`
319 /// How content outside the widget's content area is treated.
320 ///
321 /// This property is meant to be set by widget implementations,
322 /// typically in their instance init function.
323 ///
324 /// Readable | Writeable
325 ///
326 ///
327 /// #### `parent`
328 /// The parent widget of this widget.
329 ///
330 /// Readable
331 ///
332 ///
333 /// #### `receives-default`
334 /// Whether the widget will receive the default action when it is focused.
335 ///
336 /// Readable | Writeable
337 ///
338 ///
339 /// #### `root`
340 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
341 ///
342 /// This will be `NULL` if the widget is not contained in a root widget.
343 ///
344 /// Readable
345 ///
346 ///
347 /// #### `scale-factor`
348 /// The scale factor of the widget.
349 ///
350 /// Readable
351 ///
352 ///
353 /// #### `sensitive`
354 /// Whether the widget responds to input.
355 ///
356 /// Readable | Writeable
357 ///
358 ///
359 /// #### `tooltip-markup`
360 /// Sets the text of tooltip to be the given string, which is marked up
361 /// with Pango markup.
362 ///
363 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
364 ///
365 /// This is a convenience property which will take care of getting the
366 /// tooltip shown if the given string is not `NULL`:
367 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
368 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
369 /// the default signal handler.
370 ///
371 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
372 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
373 ///
374 /// Readable | Writeable
375 ///
376 ///
377 /// #### `tooltip-text`
378 /// Sets the text of tooltip to be the given string.
379 ///
380 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
381 ///
382 /// This is a convenience property which will take care of getting the
383 /// tooltip shown if the given string is not `NULL`:
384 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
385 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
386 /// the default signal handler.
387 ///
388 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
389 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
390 ///
391 /// Readable | Writeable
392 ///
393 ///
394 /// #### `valign`
395 /// How to distribute vertical space if widget gets extra space.
396 ///
397 /// Readable | Writeable
398 ///
399 ///
400 /// #### `vexpand`
401 /// Whether to expand vertically.
402 ///
403 /// Readable | Writeable
404 ///
405 ///
406 /// #### `vexpand-set`
407 /// Whether to use the `vexpand` property.
408 ///
409 /// Readable | Writeable
410 ///
411 ///
412 /// #### `visible`
413 /// Whether the widget is visible.
414 ///
415 /// Readable | Writeable
416 ///
417 ///
418 /// #### `width-request`
419 /// Overrides for width request of the widget.
420 ///
421 /// If this is -1, the natural request will be used.
422 ///
423 /// Readable | Writeable
424 /// </details>
425 /// <details><summary><h4>Accessible</h4></summary>
426 ///
427 ///
428 /// #### `accessible-role`
429 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
430 ///
431 /// The accessible role cannot be changed once set.
432 ///
433 /// Readable | Writeable
434 /// </details>
435 ///
436 /// # Implements
437 ///
438 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
439 #[doc(alias = "GtkTreeExpander")]
440 pub struct TreeExpander(Object<ffi::GtkTreeExpander, ffi::GtkTreeExpanderClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
441
442 match fn {
443 type_ => || ffi::gtk_tree_expander_get_type(),
444 }
445}
446
447impl TreeExpander {
448 /// Creates a new [`TreeExpander`][crate::TreeExpander]
449 ///
450 /// # Returns
451 ///
452 /// a new [`TreeExpander`][crate::TreeExpander]
453 #[doc(alias = "gtk_tree_expander_new")]
454 pub fn new() -> TreeExpander {
455 assert_initialized_main_thread!();
456 unsafe { Widget::from_glib_none(ffi::gtk_tree_expander_new()).unsafe_cast() }
457 }
458
459 // rustdoc-stripper-ignore-next
460 /// Creates a new builder-pattern struct instance to construct [`TreeExpander`] objects.
461 ///
462 /// This method returns an instance of [`TreeExpanderBuilder`](crate::builders::TreeExpanderBuilder) which can be used to create [`TreeExpander`] objects.
463 pub fn builder() -> TreeExpanderBuilder {
464 TreeExpanderBuilder::new()
465 }
466
467 /// Gets the child widget displayed by @self.
468 ///
469 /// # Returns
470 ///
471 /// The child displayed by @self
472 #[doc(alias = "gtk_tree_expander_get_child")]
473 #[doc(alias = "get_child")]
474 pub fn child(&self) -> Option<Widget> {
475 unsafe { from_glib_none(ffi::gtk_tree_expander_get_child(self.to_glib_none().0)) }
476 }
477
478 /// Gets whether the TreeExpander should be hidden in a GtkTreeListRow.
479 ///
480 /// # Returns
481 ///
482 /// TRUE if the expander icon should be hidden. Otherwise FALSE.
483 #[cfg(feature = "v4_10")]
484 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
485 #[doc(alias = "gtk_tree_expander_get_hide_expander")]
486 #[doc(alias = "get_hide_expander")]
487 #[doc(alias = "hide-expander")]
488 pub fn hides_expander(&self) -> bool {
489 unsafe {
490 from_glib(ffi::gtk_tree_expander_get_hide_expander(
491 self.to_glib_none().0,
492 ))
493 }
494 }
495
496 /// TreeExpander indents each level of depth with an additional indent.
497 ///
498 /// # Returns
499 ///
500 /// TRUE if the child should be indented . Otherwise FALSE.
501 #[cfg(feature = "v4_10")]
502 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
503 #[doc(alias = "gtk_tree_expander_get_indent_for_depth")]
504 #[doc(alias = "get_indent_for_depth")]
505 #[doc(alias = "indent-for-depth")]
506 pub fn is_indent_for_depth(&self) -> bool {
507 unsafe {
508 from_glib(ffi::gtk_tree_expander_get_indent_for_depth(
509 self.to_glib_none().0,
510 ))
511 }
512 }
513
514 /// TreeExpander indents the child by the width of an expander-icon if it is not expandable.
515 ///
516 /// # Returns
517 ///
518 /// TRUE if the child should be indented when not expandable. Otherwise FALSE.
519 #[cfg(feature = "v4_6")]
520 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
521 #[doc(alias = "gtk_tree_expander_get_indent_for_icon")]
522 #[doc(alias = "get_indent_for_icon")]
523 #[doc(alias = "indent-for-icon")]
524 pub fn is_indent_for_icon(&self) -> bool {
525 unsafe {
526 from_glib(ffi::gtk_tree_expander_get_indent_for_icon(
527 self.to_glib_none().0,
528 ))
529 }
530 }
531
532 /// Forwards the item set on the [`TreeListRow`][crate::TreeListRow] that @self is managing.
533 ///
534 /// This call is essentially equivalent to calling:
535 ///
536 /// **⚠️ The following code is in c ⚠️**
537 ///
538 /// ```c
539 /// gtk_tree_list_row_get_item (gtk_tree_expander_get_list_row (@self));
540 /// ```
541 ///
542 /// # Returns
543 ///
544 /// The item of the row
545 #[doc(alias = "gtk_tree_expander_get_item")]
546 #[doc(alias = "get_item")]
547 pub fn item(&self) -> Option<glib::Object> {
548 unsafe { from_glib_full(ffi::gtk_tree_expander_get_item(self.to_glib_none().0)) }
549 }
550
551 /// Gets the list row managed by @self.
552 ///
553 /// # Returns
554 ///
555 /// The list row displayed by @self
556 #[doc(alias = "gtk_tree_expander_get_list_row")]
557 #[doc(alias = "get_list_row")]
558 #[doc(alias = "list-row")]
559 pub fn list_row(&self) -> Option<TreeListRow> {
560 unsafe { from_glib_none(ffi::gtk_tree_expander_get_list_row(self.to_glib_none().0)) }
561 }
562
563 /// Sets the content widget to display.
564 /// ## `child`
565 /// a [`Widget`][crate::Widget]
566 #[doc(alias = "gtk_tree_expander_set_child")]
567 #[doc(alias = "child")]
568 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
569 unsafe {
570 ffi::gtk_tree_expander_set_child(
571 self.to_glib_none().0,
572 child.map(|p| p.as_ref()).to_glib_none().0,
573 );
574 }
575 }
576
577 /// Sets whether the expander icon should be visible in a GtkTreeListRow.
578 /// ## `hide_expander`
579 /// TRUE if the expander should be hidden. Otherwise FALSE.
580 #[cfg(feature = "v4_10")]
581 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
582 #[doc(alias = "gtk_tree_expander_set_hide_expander")]
583 #[doc(alias = "hide-expander")]
584 pub fn set_hide_expander(&self, hide_expander: bool) {
585 unsafe {
586 ffi::gtk_tree_expander_set_hide_expander(
587 self.to_glib_none().0,
588 hide_expander.into_glib(),
589 );
590 }
591 }
592
593 /// Sets if the TreeExpander should indent the child according to its depth.
594 /// ## `indent_for_depth`
595 /// TRUE if the child should be indented. Otherwise FALSE.
596 #[cfg(feature = "v4_10")]
597 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
598 #[doc(alias = "gtk_tree_expander_set_indent_for_depth")]
599 #[doc(alias = "indent-for-depth")]
600 pub fn set_indent_for_depth(&self, indent_for_depth: bool) {
601 unsafe {
602 ffi::gtk_tree_expander_set_indent_for_depth(
603 self.to_glib_none().0,
604 indent_for_depth.into_glib(),
605 );
606 }
607 }
608
609 /// Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.
610 /// ## `indent_for_icon`
611 /// TRUE if the child should be indented without expander. Otherwise FALSE.
612 #[cfg(feature = "v4_6")]
613 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
614 #[doc(alias = "gtk_tree_expander_set_indent_for_icon")]
615 #[doc(alias = "indent-for-icon")]
616 pub fn set_indent_for_icon(&self, indent_for_icon: bool) {
617 unsafe {
618 ffi::gtk_tree_expander_set_indent_for_icon(
619 self.to_glib_none().0,
620 indent_for_icon.into_glib(),
621 );
622 }
623 }
624
625 /// Sets the tree list row that this expander should manage.
626 /// ## `list_row`
627 /// a [`TreeListRow`][crate::TreeListRow]
628 #[doc(alias = "gtk_tree_expander_set_list_row")]
629 #[doc(alias = "list-row")]
630 pub fn set_list_row(&self, list_row: Option<&TreeListRow>) {
631 unsafe {
632 ffi::gtk_tree_expander_set_list_row(self.to_glib_none().0, list_row.to_glib_none().0);
633 }
634 }
635
636 #[doc(alias = "child")]
637 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
638 unsafe extern "C" fn notify_child_trampoline<F: Fn(&TreeExpander) + 'static>(
639 this: *mut ffi::GtkTreeExpander,
640 _param_spec: glib::ffi::gpointer,
641 f: glib::ffi::gpointer,
642 ) {
643 unsafe {
644 let f: &F = &*(f as *const F);
645 f(&from_glib_borrow(this))
646 }
647 }
648 unsafe {
649 let f: Box_<F> = Box_::new(f);
650 connect_raw(
651 self.as_ptr() as *mut _,
652 c"notify::child".as_ptr() as *const _,
653 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
654 notify_child_trampoline::<F> as *const (),
655 )),
656 Box_::into_raw(f),
657 )
658 }
659 }
660
661 #[cfg(feature = "v4_10")]
662 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
663 #[doc(alias = "hide-expander")]
664 pub fn connect_hide_expander_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
665 unsafe extern "C" fn notify_hide_expander_trampoline<F: Fn(&TreeExpander) + 'static>(
666 this: *mut ffi::GtkTreeExpander,
667 _param_spec: glib::ffi::gpointer,
668 f: glib::ffi::gpointer,
669 ) {
670 unsafe {
671 let f: &F = &*(f as *const F);
672 f(&from_glib_borrow(this))
673 }
674 }
675 unsafe {
676 let f: Box_<F> = Box_::new(f);
677 connect_raw(
678 self.as_ptr() as *mut _,
679 c"notify::hide-expander".as_ptr() as *const _,
680 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
681 notify_hide_expander_trampoline::<F> as *const (),
682 )),
683 Box_::into_raw(f),
684 )
685 }
686 }
687
688 #[cfg(feature = "v4_10")]
689 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
690 #[doc(alias = "indent-for-depth")]
691 pub fn connect_indent_for_depth_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
692 unsafe extern "C" fn notify_indent_for_depth_trampoline<F: Fn(&TreeExpander) + 'static>(
693 this: *mut ffi::GtkTreeExpander,
694 _param_spec: glib::ffi::gpointer,
695 f: glib::ffi::gpointer,
696 ) {
697 unsafe {
698 let f: &F = &*(f as *const F);
699 f(&from_glib_borrow(this))
700 }
701 }
702 unsafe {
703 let f: Box_<F> = Box_::new(f);
704 connect_raw(
705 self.as_ptr() as *mut _,
706 c"notify::indent-for-depth".as_ptr() as *const _,
707 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
708 notify_indent_for_depth_trampoline::<F> as *const (),
709 )),
710 Box_::into_raw(f),
711 )
712 }
713 }
714
715 #[cfg(feature = "v4_6")]
716 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
717 #[doc(alias = "indent-for-icon")]
718 pub fn connect_indent_for_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
719 unsafe extern "C" fn notify_indent_for_icon_trampoline<F: Fn(&TreeExpander) + 'static>(
720 this: *mut ffi::GtkTreeExpander,
721 _param_spec: glib::ffi::gpointer,
722 f: glib::ffi::gpointer,
723 ) {
724 unsafe {
725 let f: &F = &*(f as *const F);
726 f(&from_glib_borrow(this))
727 }
728 }
729 unsafe {
730 let f: Box_<F> = Box_::new(f);
731 connect_raw(
732 self.as_ptr() as *mut _,
733 c"notify::indent-for-icon".as_ptr() as *const _,
734 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
735 notify_indent_for_icon_trampoline::<F> as *const (),
736 )),
737 Box_::into_raw(f),
738 )
739 }
740 }
741
742 #[doc(alias = "item")]
743 pub fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
744 unsafe extern "C" fn notify_item_trampoline<F: Fn(&TreeExpander) + 'static>(
745 this: *mut ffi::GtkTreeExpander,
746 _param_spec: glib::ffi::gpointer,
747 f: glib::ffi::gpointer,
748 ) {
749 unsafe {
750 let f: &F = &*(f as *const F);
751 f(&from_glib_borrow(this))
752 }
753 }
754 unsafe {
755 let f: Box_<F> = Box_::new(f);
756 connect_raw(
757 self.as_ptr() as *mut _,
758 c"notify::item".as_ptr() as *const _,
759 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
760 notify_item_trampoline::<F> as *const (),
761 )),
762 Box_::into_raw(f),
763 )
764 }
765 }
766
767 #[doc(alias = "list-row")]
768 pub fn connect_list_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
769 unsafe extern "C" fn notify_list_row_trampoline<F: Fn(&TreeExpander) + 'static>(
770 this: *mut ffi::GtkTreeExpander,
771 _param_spec: glib::ffi::gpointer,
772 f: glib::ffi::gpointer,
773 ) {
774 unsafe {
775 let f: &F = &*(f as *const F);
776 f(&from_glib_borrow(this))
777 }
778 }
779 unsafe {
780 let f: Box_<F> = Box_::new(f);
781 connect_raw(
782 self.as_ptr() as *mut _,
783 c"notify::list-row".as_ptr() as *const _,
784 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
785 notify_list_row_trampoline::<F> as *const (),
786 )),
787 Box_::into_raw(f),
788 )
789 }
790 }
791}
792
793impl Default for TreeExpander {
794 fn default() -> Self {
795 Self::new()
796 }
797}
798
799// rustdoc-stripper-ignore-next
800/// A [builder-pattern] type to construct [`TreeExpander`] objects.
801///
802/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
803#[must_use = "The builder must be built to be used"]
804pub struct TreeExpanderBuilder {
805 builder: glib::object::ObjectBuilder<'static, TreeExpander>,
806}
807
808impl TreeExpanderBuilder {
809 fn new() -> Self {
810 Self {
811 builder: glib::object::Object::builder(),
812 }
813 }
814
815 /// The child widget with the actual contents.
816 pub fn child(self, child: &impl IsA<Widget>) -> Self {
817 Self {
818 builder: self.builder.property("child", child.clone().upcast()),
819 }
820 }
821
822 /// Whether the expander icon should be hidden in a GtkTreeListRow.
823 /// Note that this property simply hides the icon. The actions and keybinding
824 /// (i.e. collapse and expand) are not affected by this property.
825 ///
826 /// A common use for this property would be to bind to the number of children in a
827 /// GtkTreeListRow's model in order to hide the expander when a row has no children.
828 #[cfg(feature = "v4_10")]
829 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
830 pub fn hide_expander(self, hide_expander: bool) -> Self {
831 Self {
832 builder: self.builder.property("hide-expander", hide_expander),
833 }
834 }
835
836 /// TreeExpander indents the child according to its depth.
837 #[cfg(feature = "v4_10")]
838 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
839 pub fn indent_for_depth(self, indent_for_depth: bool) -> Self {
840 Self {
841 builder: self.builder.property("indent-for-depth", indent_for_depth),
842 }
843 }
844
845 /// TreeExpander indents the child by the width of an expander-icon if it is not expandable.
846 #[cfg(feature = "v4_6")]
847 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
848 pub fn indent_for_icon(self, indent_for_icon: bool) -> Self {
849 Self {
850 builder: self.builder.property("indent-for-icon", indent_for_icon),
851 }
852 }
853
854 /// The list row to track for expander state.
855 pub fn list_row(self, list_row: &TreeListRow) -> Self {
856 Self {
857 builder: self.builder.property("list-row", list_row.clone()),
858 }
859 }
860
861 /// Whether the widget or any of its descendents can accept
862 /// the input focus.
863 ///
864 /// This property is meant to be set by widget implementations,
865 /// typically in their instance init function.
866 pub fn can_focus(self, can_focus: bool) -> Self {
867 Self {
868 builder: self.builder.property("can-focus", can_focus),
869 }
870 }
871
872 /// Whether the widget can receive pointer events.
873 pub fn can_target(self, can_target: bool) -> Self {
874 Self {
875 builder: self.builder.property("can-target", can_target),
876 }
877 }
878
879 /// A list of css classes applied to this widget.
880 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
881 Self {
882 builder: self.builder.property("css-classes", css_classes.into()),
883 }
884 }
885
886 /// The name of this widget in the CSS tree.
887 ///
888 /// This property is meant to be set by widget implementations,
889 /// typically in their instance init function.
890 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
891 Self {
892 builder: self.builder.property("css-name", css_name.into()),
893 }
894 }
895
896 /// The cursor used by @widget.
897 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
898 Self {
899 builder: self.builder.property("cursor", cursor.clone()),
900 }
901 }
902
903 /// Whether the widget should grab focus when it is clicked with the mouse.
904 ///
905 /// This property is only relevant for widgets that can take focus.
906 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
907 Self {
908 builder: self.builder.property("focus-on-click", focus_on_click),
909 }
910 }
911
912 /// Whether this widget itself will accept the input focus.
913 pub fn focusable(self, focusable: bool) -> Self {
914 Self {
915 builder: self.builder.property("focusable", focusable),
916 }
917 }
918
919 /// How to distribute horizontal space if widget gets extra space.
920 pub fn halign(self, halign: Align) -> Self {
921 Self {
922 builder: self.builder.property("halign", halign),
923 }
924 }
925
926 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
927 /// signal on @widget.
928 ///
929 /// A true value indicates that @widget can have a tooltip, in this case
930 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
931 /// determine whether it will provide a tooltip or not.
932 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
933 Self {
934 builder: self.builder.property("has-tooltip", has_tooltip),
935 }
936 }
937
938 /// Overrides for height request of the widget.
939 ///
940 /// If this is -1, the natural request will be used.
941 pub fn height_request(self, height_request: i32) -> Self {
942 Self {
943 builder: self.builder.property("height-request", height_request),
944 }
945 }
946
947 /// Whether to expand horizontally.
948 pub fn hexpand(self, hexpand: bool) -> Self {
949 Self {
950 builder: self.builder.property("hexpand", hexpand),
951 }
952 }
953
954 /// Whether to use the `hexpand` property.
955 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
956 Self {
957 builder: self.builder.property("hexpand-set", hexpand_set),
958 }
959 }
960
961 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
962 /// the preferred size of the widget, and allocate its children.
963 ///
964 /// This property is meant to be set by widget implementations,
965 /// typically in their instance init function.
966 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
967 Self {
968 builder: self
969 .builder
970 .property("layout-manager", layout_manager.clone().upcast()),
971 }
972 }
973
974 /// Makes this widget act like a modal dialog, with respect to
975 /// event delivery.
976 ///
977 /// Global event controllers will not handle events with targets
978 /// inside the widget, unless they are set up to ignore propagation
979 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
980 #[cfg(feature = "v4_18")]
981 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
982 pub fn limit_events(self, limit_events: bool) -> Self {
983 Self {
984 builder: self.builder.property("limit-events", limit_events),
985 }
986 }
987
988 /// Margin on bottom side of widget.
989 ///
990 /// This property adds margin outside of the widget's normal size
991 /// request, the margin will be added in addition to the size from
992 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
993 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
994 Self {
995 builder: self.builder.property("margin-bottom", margin_bottom),
996 }
997 }
998
999 /// Margin on end of widget, horizontally.
1000 ///
1001 /// This property supports left-to-right and right-to-left text
1002 /// directions.
1003 ///
1004 /// This property adds margin outside of the widget's normal size
1005 /// request, the margin will be added in addition to the size from
1006 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1007 pub fn margin_end(self, margin_end: i32) -> Self {
1008 Self {
1009 builder: self.builder.property("margin-end", margin_end),
1010 }
1011 }
1012
1013 /// Margin on start of widget, horizontally.
1014 ///
1015 /// This property supports left-to-right and right-to-left text
1016 /// directions.
1017 ///
1018 /// This property adds margin outside of the widget's normal size
1019 /// request, the margin will be added in addition to the size from
1020 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1021 pub fn margin_start(self, margin_start: i32) -> Self {
1022 Self {
1023 builder: self.builder.property("margin-start", margin_start),
1024 }
1025 }
1026
1027 /// Margin on top side of widget.
1028 ///
1029 /// This property adds margin outside of the widget's normal size
1030 /// request, the margin will be added in addition to the size from
1031 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1032 pub fn margin_top(self, margin_top: i32) -> Self {
1033 Self {
1034 builder: self.builder.property("margin-top", margin_top),
1035 }
1036 }
1037
1038 /// The name of the widget.
1039 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1040 Self {
1041 builder: self.builder.property("name", name.into()),
1042 }
1043 }
1044
1045 /// The requested opacity of the widget.
1046 pub fn opacity(self, opacity: f64) -> Self {
1047 Self {
1048 builder: self.builder.property("opacity", opacity),
1049 }
1050 }
1051
1052 /// How content outside the widget's content area is treated.
1053 ///
1054 /// This property is meant to be set by widget implementations,
1055 /// typically in their instance init function.
1056 pub fn overflow(self, overflow: Overflow) -> Self {
1057 Self {
1058 builder: self.builder.property("overflow", overflow),
1059 }
1060 }
1061
1062 /// Whether the widget will receive the default action when it is focused.
1063 pub fn receives_default(self, receives_default: bool) -> Self {
1064 Self {
1065 builder: self.builder.property("receives-default", receives_default),
1066 }
1067 }
1068
1069 /// Whether the widget responds to input.
1070 pub fn sensitive(self, sensitive: bool) -> Self {
1071 Self {
1072 builder: self.builder.property("sensitive", sensitive),
1073 }
1074 }
1075
1076 /// Sets the text of tooltip to be the given string, which is marked up
1077 /// with Pango markup.
1078 ///
1079 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1080 ///
1081 /// This is a convenience property which will take care of getting the
1082 /// tooltip shown if the given string is not `NULL`:
1083 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1084 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1085 /// the default signal handler.
1086 ///
1087 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1088 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1089 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1090 Self {
1091 builder: self
1092 .builder
1093 .property("tooltip-markup", tooltip_markup.into()),
1094 }
1095 }
1096
1097 /// Sets the text of tooltip to be the given string.
1098 ///
1099 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1100 ///
1101 /// This is a convenience property which will take care of getting the
1102 /// tooltip shown if the given string is not `NULL`:
1103 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1104 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1105 /// the default signal handler.
1106 ///
1107 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1108 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1109 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1110 Self {
1111 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1112 }
1113 }
1114
1115 /// How to distribute vertical space if widget gets extra space.
1116 pub fn valign(self, valign: Align) -> Self {
1117 Self {
1118 builder: self.builder.property("valign", valign),
1119 }
1120 }
1121
1122 /// Whether to expand vertically.
1123 pub fn vexpand(self, vexpand: bool) -> Self {
1124 Self {
1125 builder: self.builder.property("vexpand", vexpand),
1126 }
1127 }
1128
1129 /// Whether to use the `vexpand` property.
1130 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1131 Self {
1132 builder: self.builder.property("vexpand-set", vexpand_set),
1133 }
1134 }
1135
1136 /// Whether the widget is visible.
1137 pub fn visible(self, visible: bool) -> Self {
1138 Self {
1139 builder: self.builder.property("visible", visible),
1140 }
1141 }
1142
1143 /// Overrides for width request of the widget.
1144 ///
1145 /// If this is -1, the natural request will be used.
1146 pub fn width_request(self, width_request: i32) -> Self {
1147 Self {
1148 builder: self.builder.property("width-request", width_request),
1149 }
1150 }
1151
1152 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1153 ///
1154 /// The accessible role cannot be changed once set.
1155 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1156 Self {
1157 builder: self.builder.property("accessible-role", accessible_role),
1158 }
1159 }
1160
1161 // rustdoc-stripper-ignore-next
1162 /// Build the [`TreeExpander`].
1163 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1164 pub fn build(self) -> TreeExpander {
1165 assert_initialized_main_thread!();
1166 self.builder.build()
1167 }
1168}