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