gtk4/auto/grid.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 ffi, Accessible, AccessibleRole, Align, BaselinePosition, Buildable, ConstraintTarget,
7 LayoutManager, Orientable, Orientation, Overflow, PositionType, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 /// Arranges its child widgets in rows and columns.
18 ///
19 /// <picture>
20 /// <source srcset="grid-dark.png" media="(prefers-color-scheme: dark)">
21 /// <img alt="An example GtkGrid" src="grid.png">
22 /// </picture>
23 ///
24 /// It supports arbitrary positions and horizontal/vertical spans.
25 ///
26 /// Children are added using [`GridExt::attach()`][crate::prelude::GridExt::attach()]. They can span multiple
27 /// rows or columns. It is also possible to add a child next to an existing
28 /// child, using [`GridExt::attach_next_to()`][crate::prelude::GridExt::attach_next_to()]. To remove a child from the
29 /// grid, use [`GridExt::remove()`][crate::prelude::GridExt::remove()].
30 ///
31 /// The behaviour of [`Grid`][crate::Grid] when several children occupy the same grid
32 /// cell is undefined.
33 ///
34 /// # GtkGrid as GtkBuildable
35 ///
36 /// Every child in a [`Grid`][crate::Grid] has access to a custom [`Buildable`][crate::Buildable]
37 /// element, called `<layout>`. It can by used to specify a position in the
38 /// grid and optionally spans. All properties that can be used in the `<layout>`
39 /// element are implemented by [`GridLayoutChild`][crate::GridLayoutChild].
40 ///
41 /// It is implemented by [`Widget`][crate::Widget] using [`LayoutManager`][crate::LayoutManager].
42 ///
43 /// To showcase it, here is a simple example:
44 ///
45 /// ```xml
46 /// <object class="GtkGrid" id="my_grid">
47 /// <child>
48 /// <object class="GtkButton" id="button1">
49 /// <property name="label">Button 1</property>
50 /// <layout>
51 /// <property name="column">0</property>
52 /// <property name="row">0</property>
53 /// </layout>
54 /// </object>
55 /// </child>
56 /// <child>
57 /// <object class="GtkButton" id="button2">
58 /// <property name="label">Button 2</property>
59 /// <layout>
60 /// <property name="column">1</property>
61 /// <property name="row">0</property>
62 /// </layout>
63 /// </object>
64 /// </child>
65 /// <child>
66 /// <object class="GtkButton" id="button3">
67 /// <property name="label">Button 3</property>
68 /// <layout>
69 /// <property name="column">2</property>
70 /// <property name="row">0</property>
71 /// <property name="row-span">2</property>
72 /// </layout>
73 /// </object>
74 /// </child>
75 /// <child>
76 /// <object class="GtkButton" id="button4">
77 /// <property name="label">Button 4</property>
78 /// <layout>
79 /// <property name="column">0</property>
80 /// <property name="row">1</property>
81 /// <property name="column-span">2</property>
82 /// </layout>
83 /// </object>
84 /// </child>
85 /// </object>
86 /// ```
87 ///
88 /// It organizes the first two buttons side-by-side in one cell each.
89 /// The third button is in the last column but spans across two rows.
90 /// This is defined by the `row-span` property. The last button is
91 /// located in the second row and spans across two columns, which is
92 /// defined by the `column-span` property.
93 ///
94 /// # CSS nodes
95 ///
96 /// [`Grid`][crate::Grid] uses a single CSS node with name `grid`.
97 ///
98 /// # Accessibility
99 ///
100 /// Until GTK 4.10, [`Grid`][crate::Grid] used the [enum@Gtk.AccessibleRole.group] role.
101 ///
102 /// Starting from GTK 4.12, [`Grid`][crate::Grid] uses the [enum@Gtk.AccessibleRole.generic] role.
103 ///
104 /// ## Properties
105 ///
106 ///
107 /// #### `baseline-row`
108 /// The row to align to the baseline when valign is using baseline alignment.
109 ///
110 /// Readable | Writeable
111 ///
112 ///
113 /// #### `column-homogeneous`
114 /// If [`true`], the columns are all the same width.
115 ///
116 /// Readable | Writeable
117 ///
118 ///
119 /// #### `column-spacing`
120 /// The amount of space between two consecutive columns.
121 ///
122 /// Readable | Writeable
123 ///
124 ///
125 /// #### `row-homogeneous`
126 /// If [`true`], the rows are all the same height.
127 ///
128 /// Readable | Writeable
129 ///
130 ///
131 /// #### `row-spacing`
132 /// The amount of space between two consecutive rows.
133 ///
134 /// Readable | Writeable
135 /// <details><summary><h4>Widget</h4></summary>
136 ///
137 ///
138 /// #### `can-focus`
139 /// Whether the widget or any of its descendents can accept
140 /// the input focus.
141 ///
142 /// This property is meant to be set by widget implementations,
143 /// typically in their instance init function.
144 ///
145 /// Readable | Writeable
146 ///
147 ///
148 /// #### `can-target`
149 /// Whether the widget can receive pointer events.
150 ///
151 /// Readable | Writeable
152 ///
153 ///
154 /// #### `css-classes`
155 /// A list of css classes applied to this widget.
156 ///
157 /// Readable | Writeable
158 ///
159 ///
160 /// #### `css-name`
161 /// The name of this widget in the CSS tree.
162 ///
163 /// This property is meant to be set by widget implementations,
164 /// typically in their instance init function.
165 ///
166 /// Readable | Writeable | Construct Only
167 ///
168 ///
169 /// #### `cursor`
170 /// The cursor used by @widget.
171 ///
172 /// Readable | Writeable
173 ///
174 ///
175 /// #### `focus-on-click`
176 /// Whether the widget should grab focus when it is clicked with the mouse.
177 ///
178 /// This property is only relevant for widgets that can take focus.
179 ///
180 /// Readable | Writeable
181 ///
182 ///
183 /// #### `focusable`
184 /// Whether this widget itself will accept the input focus.
185 ///
186 /// Readable | Writeable
187 ///
188 ///
189 /// #### `halign`
190 /// How to distribute horizontal space if widget gets extra space.
191 ///
192 /// Readable | Writeable
193 ///
194 ///
195 /// #### `has-default`
196 /// Whether the widget is the default widget.
197 ///
198 /// Readable
199 ///
200 ///
201 /// #### `has-focus`
202 /// Whether the widget has the input focus.
203 ///
204 /// Readable
205 ///
206 ///
207 /// #### `has-tooltip`
208 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
209 /// signal on @widget.
210 ///
211 /// A true value indicates that @widget can have a tooltip, in this case
212 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
213 /// determine whether it will provide a tooltip or not.
214 ///
215 /// Readable | Writeable
216 ///
217 ///
218 /// #### `height-request`
219 /// Overrides for height request of the widget.
220 ///
221 /// If this is -1, the natural request will be used.
222 ///
223 /// Readable | Writeable
224 ///
225 ///
226 /// #### `hexpand`
227 /// Whether to expand horizontally.
228 ///
229 /// Readable | Writeable
230 ///
231 ///
232 /// #### `hexpand-set`
233 /// Whether to use the `hexpand` property.
234 ///
235 /// Readable | Writeable
236 ///
237 ///
238 /// #### `layout-manager`
239 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
240 /// the preferred size of the widget, and allocate its children.
241 ///
242 /// This property is meant to be set by widget implementations,
243 /// typically in their instance init function.
244 ///
245 /// Readable | Writeable
246 ///
247 ///
248 /// #### `limit-events`
249 /// Makes this widget act like a modal dialog, with respect to
250 /// event delivery.
251 ///
252 /// Global event controllers will not handle events with targets
253 /// inside the widget, unless they are set up to ignore propagation
254 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
255 ///
256 /// Readable | Writeable
257 ///
258 ///
259 /// #### `margin-bottom`
260 /// Margin on bottom side of widget.
261 ///
262 /// This property adds margin outside of the widget's normal size
263 /// request, the margin will be added in addition to the size from
264 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
265 ///
266 /// Readable | Writeable
267 ///
268 ///
269 /// #### `margin-end`
270 /// Margin on end of widget, horizontally.
271 ///
272 /// This property supports left-to-right and right-to-left text
273 /// directions.
274 ///
275 /// This property adds margin outside of the widget's normal size
276 /// request, the margin will be added in addition to the size from
277 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
278 ///
279 /// Readable | Writeable
280 ///
281 ///
282 /// #### `margin-start`
283 /// Margin on start of widget, horizontally.
284 ///
285 /// This property supports left-to-right and right-to-left text
286 /// directions.
287 ///
288 /// This property adds margin outside of the widget's normal size
289 /// request, the margin will be added in addition to the size from
290 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
291 ///
292 /// Readable | Writeable
293 ///
294 ///
295 /// #### `margin-top`
296 /// Margin on top side of widget.
297 ///
298 /// This property adds margin outside of the widget's normal size
299 /// request, the margin will be added in addition to the size from
300 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
301 ///
302 /// Readable | Writeable
303 ///
304 ///
305 /// #### `name`
306 /// The name of the widget.
307 ///
308 /// Readable | Writeable
309 ///
310 ///
311 /// #### `opacity`
312 /// The requested opacity of the widget.
313 ///
314 /// Readable | Writeable
315 ///
316 ///
317 /// #### `overflow`
318 /// How content outside the widget's content area is treated.
319 ///
320 /// This property is meant to be set by widget implementations,
321 /// typically in their instance init function.
322 ///
323 /// Readable | Writeable
324 ///
325 ///
326 /// #### `parent`
327 /// The parent widget of this widget.
328 ///
329 /// Readable
330 ///
331 ///
332 /// #### `receives-default`
333 /// Whether the widget will receive the default action when it is focused.
334 ///
335 /// Readable | Writeable
336 ///
337 ///
338 /// #### `root`
339 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
340 ///
341 /// This will be `NULL` if the widget is not contained in a root widget.
342 ///
343 /// Readable
344 ///
345 ///
346 /// #### `scale-factor`
347 /// The scale factor of the widget.
348 ///
349 /// Readable
350 ///
351 ///
352 /// #### `sensitive`
353 /// Whether the widget responds to input.
354 ///
355 /// Readable | Writeable
356 ///
357 ///
358 /// #### `tooltip-markup`
359 /// Sets the text of tooltip to be the given string, which is marked up
360 /// with Pango markup.
361 ///
362 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
363 ///
364 /// This is a convenience property which will take care of getting the
365 /// tooltip shown if the given string is not `NULL`:
366 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
367 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
368 /// the default signal handler.
369 ///
370 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
371 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
372 ///
373 /// Readable | Writeable
374 ///
375 ///
376 /// #### `tooltip-text`
377 /// Sets the text of tooltip to be the given string.
378 ///
379 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
380 ///
381 /// This is a convenience property which will take care of getting the
382 /// tooltip shown if the given string is not `NULL`:
383 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
384 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
385 /// the default signal handler.
386 ///
387 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
388 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
389 ///
390 /// Readable | Writeable
391 ///
392 ///
393 /// #### `valign`
394 /// How to distribute vertical space if widget gets extra space.
395 ///
396 /// Readable | Writeable
397 ///
398 ///
399 /// #### `vexpand`
400 /// Whether to expand vertically.
401 ///
402 /// Readable | Writeable
403 ///
404 ///
405 /// #### `vexpand-set`
406 /// Whether to use the `vexpand` property.
407 ///
408 /// Readable | Writeable
409 ///
410 ///
411 /// #### `visible`
412 /// Whether the widget is visible.
413 ///
414 /// Readable | Writeable
415 ///
416 ///
417 /// #### `width-request`
418 /// Overrides for width request of the widget.
419 ///
420 /// If this is -1, the natural request will be used.
421 ///
422 /// Readable | Writeable
423 /// </details>
424 /// <details><summary><h4>Accessible</h4></summary>
425 ///
426 ///
427 /// #### `accessible-role`
428 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
429 ///
430 /// The accessible role cannot be changed once set.
431 ///
432 /// Readable | Writeable
433 /// </details>
434 /// <details><summary><h4>Orientable</h4></summary>
435 ///
436 ///
437 /// #### `orientation`
438 /// The orientation of the orientable.
439 ///
440 /// Readable | Writeable
441 /// </details>
442 ///
443 /// # Implements
444 ///
445 /// [`GridExt`][trait@crate::prelude::GridExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
446 #[doc(alias = "GtkGrid")]
447 pub struct Grid(Object<ffi::GtkGrid, ffi::GtkGridClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
448
449 match fn {
450 type_ => || ffi::gtk_grid_get_type(),
451 }
452}
453
454impl Grid {
455 pub const NONE: Option<&'static Grid> = None;
456
457 /// Creates a new grid widget.
458 ///
459 /// # Returns
460 ///
461 /// the new [`Grid`][crate::Grid]
462 #[doc(alias = "gtk_grid_new")]
463 pub fn new() -> Grid {
464 assert_initialized_main_thread!();
465 unsafe { Widget::from_glib_none(ffi::gtk_grid_new()).unsafe_cast() }
466 }
467
468 // rustdoc-stripper-ignore-next
469 /// Creates a new builder-pattern struct instance to construct [`Grid`] objects.
470 ///
471 /// This method returns an instance of [`GridBuilder`](crate::builders::GridBuilder) which can be used to create [`Grid`] objects.
472 pub fn builder() -> GridBuilder {
473 GridBuilder::new()
474 }
475}
476
477impl Default for Grid {
478 fn default() -> Self {
479 Self::new()
480 }
481}
482
483// rustdoc-stripper-ignore-next
484/// A [builder-pattern] type to construct [`Grid`] objects.
485///
486/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
487#[must_use = "The builder must be built to be used"]
488pub struct GridBuilder {
489 builder: glib::object::ObjectBuilder<'static, Grid>,
490}
491
492impl GridBuilder {
493 fn new() -> Self {
494 Self {
495 builder: glib::object::Object::builder(),
496 }
497 }
498
499 /// The row to align to the baseline when valign is using baseline alignment.
500 pub fn baseline_row(self, baseline_row: i32) -> Self {
501 Self {
502 builder: self.builder.property("baseline-row", baseline_row),
503 }
504 }
505
506 /// If [`true`], the columns are all the same width.
507 pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
508 Self {
509 builder: self
510 .builder
511 .property("column-homogeneous", column_homogeneous),
512 }
513 }
514
515 /// The amount of space between two consecutive columns.
516 pub fn column_spacing(self, column_spacing: i32) -> Self {
517 Self {
518 builder: self.builder.property("column-spacing", column_spacing),
519 }
520 }
521
522 /// If [`true`], the rows are all the same height.
523 pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
524 Self {
525 builder: self.builder.property("row-homogeneous", row_homogeneous),
526 }
527 }
528
529 /// The amount of space between two consecutive rows.
530 pub fn row_spacing(self, row_spacing: i32) -> Self {
531 Self {
532 builder: self.builder.property("row-spacing", row_spacing),
533 }
534 }
535
536 /// Whether the widget or any of its descendents can accept
537 /// the input focus.
538 ///
539 /// This property is meant to be set by widget implementations,
540 /// typically in their instance init function.
541 pub fn can_focus(self, can_focus: bool) -> Self {
542 Self {
543 builder: self.builder.property("can-focus", can_focus),
544 }
545 }
546
547 /// Whether the widget can receive pointer events.
548 pub fn can_target(self, can_target: bool) -> Self {
549 Self {
550 builder: self.builder.property("can-target", can_target),
551 }
552 }
553
554 /// A list of css classes applied to this widget.
555 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
556 Self {
557 builder: self.builder.property("css-classes", css_classes.into()),
558 }
559 }
560
561 /// The name of this widget in the CSS tree.
562 ///
563 /// This property is meant to be set by widget implementations,
564 /// typically in their instance init function.
565 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
566 Self {
567 builder: self.builder.property("css-name", css_name.into()),
568 }
569 }
570
571 /// The cursor used by @widget.
572 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
573 Self {
574 builder: self.builder.property("cursor", cursor.clone()),
575 }
576 }
577
578 /// Whether the widget should grab focus when it is clicked with the mouse.
579 ///
580 /// This property is only relevant for widgets that can take focus.
581 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
582 Self {
583 builder: self.builder.property("focus-on-click", focus_on_click),
584 }
585 }
586
587 /// Whether this widget itself will accept the input focus.
588 pub fn focusable(self, focusable: bool) -> Self {
589 Self {
590 builder: self.builder.property("focusable", focusable),
591 }
592 }
593
594 /// How to distribute horizontal space if widget gets extra space.
595 pub fn halign(self, halign: Align) -> Self {
596 Self {
597 builder: self.builder.property("halign", halign),
598 }
599 }
600
601 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
602 /// signal on @widget.
603 ///
604 /// A true value indicates that @widget can have a tooltip, in this case
605 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
606 /// determine whether it will provide a tooltip or not.
607 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
608 Self {
609 builder: self.builder.property("has-tooltip", has_tooltip),
610 }
611 }
612
613 /// Overrides for height request of the widget.
614 ///
615 /// If this is -1, the natural request will be used.
616 pub fn height_request(self, height_request: i32) -> Self {
617 Self {
618 builder: self.builder.property("height-request", height_request),
619 }
620 }
621
622 /// Whether to expand horizontally.
623 pub fn hexpand(self, hexpand: bool) -> Self {
624 Self {
625 builder: self.builder.property("hexpand", hexpand),
626 }
627 }
628
629 /// Whether to use the `hexpand` property.
630 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
631 Self {
632 builder: self.builder.property("hexpand-set", hexpand_set),
633 }
634 }
635
636 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
637 /// the preferred size of the widget, and allocate its children.
638 ///
639 /// This property is meant to be set by widget implementations,
640 /// typically in their instance init function.
641 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
642 Self {
643 builder: self
644 .builder
645 .property("layout-manager", layout_manager.clone().upcast()),
646 }
647 }
648
649 /// Makes this widget act like a modal dialog, with respect to
650 /// event delivery.
651 ///
652 /// Global event controllers will not handle events with targets
653 /// inside the widget, unless they are set up to ignore propagation
654 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
655 #[cfg(feature = "v4_18")]
656 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
657 pub fn limit_events(self, limit_events: bool) -> Self {
658 Self {
659 builder: self.builder.property("limit-events", limit_events),
660 }
661 }
662
663 /// Margin on bottom side of widget.
664 ///
665 /// This property adds margin outside of the widget's normal size
666 /// request, the margin will be added in addition to the size from
667 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
668 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
669 Self {
670 builder: self.builder.property("margin-bottom", margin_bottom),
671 }
672 }
673
674 /// Margin on end of widget, horizontally.
675 ///
676 /// This property supports left-to-right and right-to-left text
677 /// directions.
678 ///
679 /// This property adds margin outside of the widget's normal size
680 /// request, the margin will be added in addition to the size from
681 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
682 pub fn margin_end(self, margin_end: i32) -> Self {
683 Self {
684 builder: self.builder.property("margin-end", margin_end),
685 }
686 }
687
688 /// Margin on start of widget, horizontally.
689 ///
690 /// This property supports left-to-right and right-to-left text
691 /// directions.
692 ///
693 /// This property adds margin outside of the widget's normal size
694 /// request, the margin will be added in addition to the size from
695 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
696 pub fn margin_start(self, margin_start: i32) -> Self {
697 Self {
698 builder: self.builder.property("margin-start", margin_start),
699 }
700 }
701
702 /// Margin on top side of widget.
703 ///
704 /// This property adds margin outside of the widget's normal size
705 /// request, the margin will be added in addition to the size from
706 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
707 pub fn margin_top(self, margin_top: i32) -> Self {
708 Self {
709 builder: self.builder.property("margin-top", margin_top),
710 }
711 }
712
713 /// The name of the widget.
714 pub fn name(self, name: impl Into<glib::GString>) -> Self {
715 Self {
716 builder: self.builder.property("name", name.into()),
717 }
718 }
719
720 /// The requested opacity of the widget.
721 pub fn opacity(self, opacity: f64) -> Self {
722 Self {
723 builder: self.builder.property("opacity", opacity),
724 }
725 }
726
727 /// How content outside the widget's content area is treated.
728 ///
729 /// This property is meant to be set by widget implementations,
730 /// typically in their instance init function.
731 pub fn overflow(self, overflow: Overflow) -> Self {
732 Self {
733 builder: self.builder.property("overflow", overflow),
734 }
735 }
736
737 /// Whether the widget will receive the default action when it is focused.
738 pub fn receives_default(self, receives_default: bool) -> Self {
739 Self {
740 builder: self.builder.property("receives-default", receives_default),
741 }
742 }
743
744 /// Whether the widget responds to input.
745 pub fn sensitive(self, sensitive: bool) -> Self {
746 Self {
747 builder: self.builder.property("sensitive", sensitive),
748 }
749 }
750
751 /// Sets the text of tooltip to be the given string, which is marked up
752 /// with Pango markup.
753 ///
754 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
755 ///
756 /// This is a convenience property which will take care of getting the
757 /// tooltip shown if the given string is not `NULL`:
758 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
759 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
760 /// the default signal handler.
761 ///
762 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
763 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
764 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
765 Self {
766 builder: self
767 .builder
768 .property("tooltip-markup", tooltip_markup.into()),
769 }
770 }
771
772 /// Sets the text of tooltip to be the given string.
773 ///
774 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
775 ///
776 /// This is a convenience property which will take care of getting the
777 /// tooltip shown if the given string is not `NULL`:
778 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
779 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
780 /// the default signal handler.
781 ///
782 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
783 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
784 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
785 Self {
786 builder: self.builder.property("tooltip-text", tooltip_text.into()),
787 }
788 }
789
790 /// How to distribute vertical space if widget gets extra space.
791 pub fn valign(self, valign: Align) -> Self {
792 Self {
793 builder: self.builder.property("valign", valign),
794 }
795 }
796
797 /// Whether to expand vertically.
798 pub fn vexpand(self, vexpand: bool) -> Self {
799 Self {
800 builder: self.builder.property("vexpand", vexpand),
801 }
802 }
803
804 /// Whether to use the `vexpand` property.
805 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
806 Self {
807 builder: self.builder.property("vexpand-set", vexpand_set),
808 }
809 }
810
811 /// Whether the widget is visible.
812 pub fn visible(self, visible: bool) -> Self {
813 Self {
814 builder: self.builder.property("visible", visible),
815 }
816 }
817
818 /// Overrides for width request of the widget.
819 ///
820 /// If this is -1, the natural request will be used.
821 pub fn width_request(self, width_request: i32) -> Self {
822 Self {
823 builder: self.builder.property("width-request", width_request),
824 }
825 }
826
827 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
828 ///
829 /// The accessible role cannot be changed once set.
830 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
831 Self {
832 builder: self.builder.property("accessible-role", accessible_role),
833 }
834 }
835
836 /// The orientation of the orientable.
837 pub fn orientation(self, orientation: Orientation) -> Self {
838 Self {
839 builder: self.builder.property("orientation", orientation),
840 }
841 }
842
843 // rustdoc-stripper-ignore-next
844 /// Build the [`Grid`].
845 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
846 pub fn build(self) -> Grid {
847 assert_initialized_main_thread!();
848 self.builder.build()
849 }
850}
851
852/// Trait containing all [`struct@Grid`] methods.
853///
854/// # Implementors
855///
856/// [`Grid`][struct@crate::Grid]
857pub trait GridExt: IsA<Grid> + 'static {
858 /// Adds a widget to the grid.
859 ///
860 /// The position of @child is determined by @column and @row.
861 /// The number of “cells” that @child will occupy is determined
862 /// by @width and @height.
863 /// ## `child`
864 /// the widget to add
865 /// ## `column`
866 /// the column number to attach the left side of @child to
867 /// ## `row`
868 /// the row number to attach the top side of @child to
869 /// ## `width`
870 /// the number of columns that @child will span
871 /// ## `height`
872 /// the number of rows that @child will span
873 #[doc(alias = "gtk_grid_attach")]
874 fn attach(&self, child: &impl IsA<Widget>, column: i32, row: i32, width: i32, height: i32) {
875 unsafe {
876 ffi::gtk_grid_attach(
877 self.as_ref().to_glib_none().0,
878 child.as_ref().to_glib_none().0,
879 column,
880 row,
881 width,
882 height,
883 );
884 }
885 }
886
887 /// Adds a widget to the grid.
888 ///
889 /// The widget is placed next to @sibling, on the side determined by
890 /// @side. When @sibling is [`None`], the widget is placed in row (for
891 /// left or right placement) or column 0 (for top or bottom placement),
892 /// at the end indicated by @side.
893 ///
894 /// Attaching widgets labeled `[1]`, `[2]`, `[3]` with `@sibling == [`None`]` and
895 /// `@side == [`PositionType::Left`][crate::PositionType::Left]` yields a layout of `[3][2][1]`.
896 /// ## `child`
897 /// the widget to add
898 /// ## `sibling`
899 /// the child of @self that @child will be placed
900 /// next to, or [`None`] to place @child at the beginning or end
901 /// ## `side`
902 /// the side of @sibling that @child is positioned next to
903 /// ## `width`
904 /// the number of columns that @child will span
905 /// ## `height`
906 /// the number of rows that @child will span
907 #[doc(alias = "gtk_grid_attach_next_to")]
908 fn attach_next_to(
909 &self,
910 child: &impl IsA<Widget>,
911 sibling: Option<&impl IsA<Widget>>,
912 side: PositionType,
913 width: i32,
914 height: i32,
915 ) {
916 unsafe {
917 ffi::gtk_grid_attach_next_to(
918 self.as_ref().to_glib_none().0,
919 child.as_ref().to_glib_none().0,
920 sibling.map(|p| p.as_ref()).to_glib_none().0,
921 side.into_glib(),
922 width,
923 height,
924 );
925 }
926 }
927
928 /// Returns which row defines the global baseline of @self.
929 ///
930 /// # Returns
931 ///
932 /// the row index defining the global baseline
933 #[doc(alias = "gtk_grid_get_baseline_row")]
934 #[doc(alias = "get_baseline_row")]
935 #[doc(alias = "baseline-row")]
936 fn baseline_row(&self) -> i32 {
937 unsafe { ffi::gtk_grid_get_baseline_row(self.as_ref().to_glib_none().0) }
938 }
939
940 /// Gets the child of @self whose area covers the grid
941 /// cell at @column, @row.
942 /// ## `column`
943 /// the left edge of the cell
944 /// ## `row`
945 /// the top edge of the cell
946 ///
947 /// # Returns
948 ///
949 /// the child at the given position
950 #[doc(alias = "gtk_grid_get_child_at")]
951 #[doc(alias = "get_child_at")]
952 fn child_at(&self, column: i32, row: i32) -> Option<Widget> {
953 unsafe {
954 from_glib_none(ffi::gtk_grid_get_child_at(
955 self.as_ref().to_glib_none().0,
956 column,
957 row,
958 ))
959 }
960 }
961
962 /// Returns whether all columns of @self have the same width.
963 ///
964 /// # Returns
965 ///
966 /// whether all columns of @self have the same width.
967 #[doc(alias = "gtk_grid_get_column_homogeneous")]
968 #[doc(alias = "get_column_homogeneous")]
969 #[doc(alias = "column-homogeneous")]
970 fn is_column_homogeneous(&self) -> bool {
971 unsafe {
972 from_glib(ffi::gtk_grid_get_column_homogeneous(
973 self.as_ref().to_glib_none().0,
974 ))
975 }
976 }
977
978 /// Returns the amount of space between the columns of @self.
979 ///
980 /// # Returns
981 ///
982 /// the column spacing of @self
983 #[doc(alias = "gtk_grid_get_column_spacing")]
984 #[doc(alias = "get_column_spacing")]
985 #[doc(alias = "column-spacing")]
986 fn column_spacing(&self) -> u32 {
987 unsafe { ffi::gtk_grid_get_column_spacing(self.as_ref().to_glib_none().0) }
988 }
989
990 /// Returns the baseline position of @row.
991 ///
992 /// See [`set_row_baseline_position()`][Self::set_row_baseline_position()].
993 /// ## `row`
994 /// a row index
995 ///
996 /// # Returns
997 ///
998 /// the baseline position of @row
999 #[doc(alias = "gtk_grid_get_row_baseline_position")]
1000 #[doc(alias = "get_row_baseline_position")]
1001 fn row_baseline_position(&self, row: i32) -> BaselinePosition {
1002 unsafe {
1003 from_glib(ffi::gtk_grid_get_row_baseline_position(
1004 self.as_ref().to_glib_none().0,
1005 row,
1006 ))
1007 }
1008 }
1009
1010 /// Returns whether all rows of @self have the same height.
1011 ///
1012 /// # Returns
1013 ///
1014 /// whether all rows of @self have the same height.
1015 #[doc(alias = "gtk_grid_get_row_homogeneous")]
1016 #[doc(alias = "get_row_homogeneous")]
1017 #[doc(alias = "row-homogeneous")]
1018 fn is_row_homogeneous(&self) -> bool {
1019 unsafe {
1020 from_glib(ffi::gtk_grid_get_row_homogeneous(
1021 self.as_ref().to_glib_none().0,
1022 ))
1023 }
1024 }
1025
1026 /// Returns the amount of space between the rows of @self.
1027 ///
1028 /// # Returns
1029 ///
1030 /// the row spacing of @self
1031 #[doc(alias = "gtk_grid_get_row_spacing")]
1032 #[doc(alias = "get_row_spacing")]
1033 #[doc(alias = "row-spacing")]
1034 fn row_spacing(&self) -> u32 {
1035 unsafe { ffi::gtk_grid_get_row_spacing(self.as_ref().to_glib_none().0) }
1036 }
1037
1038 /// Inserts a column at the specified position.
1039 ///
1040 /// Children which are attached at or to the right of this position
1041 /// are moved one column to the right. Children which span across this
1042 /// position are grown to span the new column.
1043 /// ## `position`
1044 /// the position to insert the column at
1045 #[doc(alias = "gtk_grid_insert_column")]
1046 fn insert_column(&self, position: i32) {
1047 unsafe {
1048 ffi::gtk_grid_insert_column(self.as_ref().to_glib_none().0, position);
1049 }
1050 }
1051
1052 /// Inserts a row or column at the specified position.
1053 ///
1054 /// The new row or column is placed next to @sibling, on the side
1055 /// determined by @side. If @side is [`PositionType::Top`][crate::PositionType::Top] or [`PositionType::Bottom`][crate::PositionType::Bottom],
1056 /// a row is inserted. If @side is [`PositionType::Left`][crate::PositionType::Left] of [`PositionType::Right`][crate::PositionType::Right],
1057 /// a column is inserted.
1058 /// ## `sibling`
1059 /// the child of @self that the new row or column will be
1060 /// placed next to
1061 /// ## `side`
1062 /// the side of @sibling that @child is positioned next to
1063 #[doc(alias = "gtk_grid_insert_next_to")]
1064 fn insert_next_to(&self, sibling: &impl IsA<Widget>, side: PositionType) {
1065 unsafe {
1066 ffi::gtk_grid_insert_next_to(
1067 self.as_ref().to_glib_none().0,
1068 sibling.as_ref().to_glib_none().0,
1069 side.into_glib(),
1070 );
1071 }
1072 }
1073
1074 /// Inserts a row at the specified position.
1075 ///
1076 /// Children which are attached at or below this position
1077 /// are moved one row down. Children which span across this
1078 /// position are grown to span the new row.
1079 /// ## `position`
1080 /// the position to insert the row at
1081 #[doc(alias = "gtk_grid_insert_row")]
1082 fn insert_row(&self, position: i32) {
1083 unsafe {
1084 ffi::gtk_grid_insert_row(self.as_ref().to_glib_none().0, position);
1085 }
1086 }
1087
1088 /// Queries the attach points and spans of @child inside the given [`Grid`][crate::Grid].
1089 /// ## `child`
1090 /// a [`Widget`][crate::Widget] child of @self
1091 ///
1092 /// # Returns
1093 ///
1094 ///
1095 /// ## `column`
1096 /// the column used to attach the left side of @child
1097 ///
1098 /// ## `row`
1099 /// the row used to attach the top side of @child
1100 ///
1101 /// ## `width`
1102 /// the number of columns @child spans
1103 ///
1104 /// ## `height`
1105 /// the number of rows @child spans
1106 #[doc(alias = "gtk_grid_query_child")]
1107 fn query_child(&self, child: &impl IsA<Widget>) -> (i32, i32, i32, i32) {
1108 unsafe {
1109 let mut column = std::mem::MaybeUninit::uninit();
1110 let mut row = std::mem::MaybeUninit::uninit();
1111 let mut width = std::mem::MaybeUninit::uninit();
1112 let mut height = std::mem::MaybeUninit::uninit();
1113 ffi::gtk_grid_query_child(
1114 self.as_ref().to_glib_none().0,
1115 child.as_ref().to_glib_none().0,
1116 column.as_mut_ptr(),
1117 row.as_mut_ptr(),
1118 width.as_mut_ptr(),
1119 height.as_mut_ptr(),
1120 );
1121 (
1122 column.assume_init(),
1123 row.assume_init(),
1124 width.assume_init(),
1125 height.assume_init(),
1126 )
1127 }
1128 }
1129
1130 /// Removes a child from @self.
1131 ///
1132 /// The child must have been added with
1133 /// [`attach()`][Self::attach()] or [`attach_next_to()`][Self::attach_next_to()].
1134 /// ## `child`
1135 /// the child widget to remove
1136 #[doc(alias = "gtk_grid_remove")]
1137 fn remove(&self, child: &impl IsA<Widget>) {
1138 unsafe {
1139 ffi::gtk_grid_remove(
1140 self.as_ref().to_glib_none().0,
1141 child.as_ref().to_glib_none().0,
1142 );
1143 }
1144 }
1145
1146 /// Removes a column from the grid.
1147 ///
1148 /// Children that are placed in this column are removed,
1149 /// spanning children that overlap this column have their
1150 /// width reduced by one, and children after the column
1151 /// are moved to the left.
1152 /// ## `position`
1153 /// the position of the column to remove
1154 #[doc(alias = "gtk_grid_remove_column")]
1155 fn remove_column(&self, position: i32) {
1156 unsafe {
1157 ffi::gtk_grid_remove_column(self.as_ref().to_glib_none().0, position);
1158 }
1159 }
1160
1161 /// Removes a row from the grid.
1162 ///
1163 /// Children that are placed in this row are removed,
1164 /// spanning children that overlap this row have their
1165 /// height reduced by one, and children below the row
1166 /// are moved up.
1167 /// ## `position`
1168 /// the position of the row to remove
1169 #[doc(alias = "gtk_grid_remove_row")]
1170 fn remove_row(&self, position: i32) {
1171 unsafe {
1172 ffi::gtk_grid_remove_row(self.as_ref().to_glib_none().0, position);
1173 }
1174 }
1175
1176 /// Sets which row defines the global baseline for the entire grid.
1177 ///
1178 /// Each row in the grid can have its own local baseline, but only
1179 /// one of those is global, meaning it will be the baseline in the
1180 /// parent of the @self.
1181 /// ## `row`
1182 /// the row index
1183 #[doc(alias = "gtk_grid_set_baseline_row")]
1184 #[doc(alias = "baseline-row")]
1185 fn set_baseline_row(&self, row: i32) {
1186 unsafe {
1187 ffi::gtk_grid_set_baseline_row(self.as_ref().to_glib_none().0, row);
1188 }
1189 }
1190
1191 /// Sets whether all columns of @self will have the same width.
1192 /// ## `homogeneous`
1193 /// [`true`] to make columns homogeneous
1194 #[doc(alias = "gtk_grid_set_column_homogeneous")]
1195 #[doc(alias = "column-homogeneous")]
1196 fn set_column_homogeneous(&self, homogeneous: bool) {
1197 unsafe {
1198 ffi::gtk_grid_set_column_homogeneous(
1199 self.as_ref().to_glib_none().0,
1200 homogeneous.into_glib(),
1201 );
1202 }
1203 }
1204
1205 /// Sets the amount of space between columns of @self.
1206 /// ## `spacing`
1207 /// the amount of space to insert between columns
1208 #[doc(alias = "gtk_grid_set_column_spacing")]
1209 #[doc(alias = "column-spacing")]
1210 fn set_column_spacing(&self, spacing: u32) {
1211 unsafe {
1212 ffi::gtk_grid_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
1213 }
1214 }
1215
1216 /// Sets how the baseline should be positioned on @row of the
1217 /// grid, in case that row is assigned more space than is requested.
1218 ///
1219 /// The default baseline position is [`BaselinePosition::Center`][crate::BaselinePosition::Center].
1220 /// ## `row`
1221 /// a row index
1222 /// ## `pos`
1223 /// a [`BaselinePosition`][crate::BaselinePosition]
1224 #[doc(alias = "gtk_grid_set_row_baseline_position")]
1225 fn set_row_baseline_position(&self, row: i32, pos: BaselinePosition) {
1226 unsafe {
1227 ffi::gtk_grid_set_row_baseline_position(
1228 self.as_ref().to_glib_none().0,
1229 row,
1230 pos.into_glib(),
1231 );
1232 }
1233 }
1234
1235 /// Sets whether all rows of @self will have the same height.
1236 /// ## `homogeneous`
1237 /// [`true`] to make rows homogeneous
1238 #[doc(alias = "gtk_grid_set_row_homogeneous")]
1239 #[doc(alias = "row-homogeneous")]
1240 fn set_row_homogeneous(&self, homogeneous: bool) {
1241 unsafe {
1242 ffi::gtk_grid_set_row_homogeneous(
1243 self.as_ref().to_glib_none().0,
1244 homogeneous.into_glib(),
1245 );
1246 }
1247 }
1248
1249 /// Sets the amount of space between rows of @self.
1250 /// ## `spacing`
1251 /// the amount of space to insert between rows
1252 #[doc(alias = "gtk_grid_set_row_spacing")]
1253 #[doc(alias = "row-spacing")]
1254 fn set_row_spacing(&self, spacing: u32) {
1255 unsafe {
1256 ffi::gtk_grid_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
1257 }
1258 }
1259
1260 #[doc(alias = "baseline-row")]
1261 fn connect_baseline_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1262 unsafe extern "C" fn notify_baseline_row_trampoline<P: IsA<Grid>, F: Fn(&P) + 'static>(
1263 this: *mut ffi::GtkGrid,
1264 _param_spec: glib::ffi::gpointer,
1265 f: glib::ffi::gpointer,
1266 ) {
1267 let f: &F = &*(f as *const F);
1268 f(Grid::from_glib_borrow(this).unsafe_cast_ref())
1269 }
1270 unsafe {
1271 let f: Box_<F> = Box_::new(f);
1272 connect_raw(
1273 self.as_ptr() as *mut _,
1274 c"notify::baseline-row".as_ptr() as *const _,
1275 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1276 notify_baseline_row_trampoline::<Self, F> as *const (),
1277 )),
1278 Box_::into_raw(f),
1279 )
1280 }
1281 }
1282
1283 #[doc(alias = "column-homogeneous")]
1284 fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1285 unsafe extern "C" fn notify_column_homogeneous_trampoline<
1286 P: IsA<Grid>,
1287 F: Fn(&P) + 'static,
1288 >(
1289 this: *mut ffi::GtkGrid,
1290 _param_spec: glib::ffi::gpointer,
1291 f: glib::ffi::gpointer,
1292 ) {
1293 let f: &F = &*(f as *const F);
1294 f(Grid::from_glib_borrow(this).unsafe_cast_ref())
1295 }
1296 unsafe {
1297 let f: Box_<F> = Box_::new(f);
1298 connect_raw(
1299 self.as_ptr() as *mut _,
1300 c"notify::column-homogeneous".as_ptr() as *const _,
1301 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1302 notify_column_homogeneous_trampoline::<Self, F> as *const (),
1303 )),
1304 Box_::into_raw(f),
1305 )
1306 }
1307 }
1308
1309 #[doc(alias = "column-spacing")]
1310 fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1311 unsafe extern "C" fn notify_column_spacing_trampoline<P: IsA<Grid>, F: Fn(&P) + 'static>(
1312 this: *mut ffi::GtkGrid,
1313 _param_spec: glib::ffi::gpointer,
1314 f: glib::ffi::gpointer,
1315 ) {
1316 let f: &F = &*(f as *const F);
1317 f(Grid::from_glib_borrow(this).unsafe_cast_ref())
1318 }
1319 unsafe {
1320 let f: Box_<F> = Box_::new(f);
1321 connect_raw(
1322 self.as_ptr() as *mut _,
1323 c"notify::column-spacing".as_ptr() as *const _,
1324 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1325 notify_column_spacing_trampoline::<Self, F> as *const (),
1326 )),
1327 Box_::into_raw(f),
1328 )
1329 }
1330 }
1331
1332 #[doc(alias = "row-homogeneous")]
1333 fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1334 unsafe extern "C" fn notify_row_homogeneous_trampoline<
1335 P: IsA<Grid>,
1336 F: Fn(&P) + 'static,
1337 >(
1338 this: *mut ffi::GtkGrid,
1339 _param_spec: glib::ffi::gpointer,
1340 f: glib::ffi::gpointer,
1341 ) {
1342 let f: &F = &*(f as *const F);
1343 f(Grid::from_glib_borrow(this).unsafe_cast_ref())
1344 }
1345 unsafe {
1346 let f: Box_<F> = Box_::new(f);
1347 connect_raw(
1348 self.as_ptr() as *mut _,
1349 c"notify::row-homogeneous".as_ptr() as *const _,
1350 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1351 notify_row_homogeneous_trampoline::<Self, F> as *const (),
1352 )),
1353 Box_::into_raw(f),
1354 )
1355 }
1356 }
1357
1358 #[doc(alias = "row-spacing")]
1359 fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1360 unsafe extern "C" fn notify_row_spacing_trampoline<P: IsA<Grid>, F: Fn(&P) + 'static>(
1361 this: *mut ffi::GtkGrid,
1362 _param_spec: glib::ffi::gpointer,
1363 f: glib::ffi::gpointer,
1364 ) {
1365 let f: &F = &*(f as *const F);
1366 f(Grid::from_glib_borrow(this).unsafe_cast_ref())
1367 }
1368 unsafe {
1369 let f: Box_<F> = Box_::new(f);
1370 connect_raw(
1371 self.as_ptr() as *mut _,
1372 c"notify::row-spacing".as_ptr() as *const _,
1373 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1374 notify_row_spacing_trampoline::<Self, F> as *const (),
1375 )),
1376 Box_::into_raw(f),
1377 )
1378 }
1379 }
1380}
1381
1382impl<O: IsA<Grid>> GridExt for O {}