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