gtk/auto/layout.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 Adjustment, Align, Buildable, Container, ResizeMode, Scrollable, ScrollablePolicy, Widget,
7};
8use glib::{
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::{boxed::Box as Box_, fmt, mem, mem::transmute};
14
15glib::wrapper! {
16 /// [`Layout`][crate::Layout] is similar to [`DrawingArea`][crate::DrawingArea] in that it’s a “blank slate” and
17 /// doesn’t do anything except paint a blank background by default. It’s
18 /// different in that it supports scrolling natively due to implementing
19 /// [`Scrollable`][crate::Scrollable], and can contain child widgets since it’s a [`Container`][crate::Container].
20 ///
21 /// If you just want to draw, a [`DrawingArea`][crate::DrawingArea] is a better choice since it has
22 /// lower overhead. If you just need to position child widgets at specific
23 /// points, then [`Fixed`][crate::Fixed] provides that functionality on its own.
24 ///
25 /// When handling expose events on a [`Layout`][crate::Layout], you must draw to the [`gdk::Window`][crate::gdk::Window]
26 /// returned by [`LayoutExt::bin_window()`][crate::prelude::LayoutExt::bin_window()], rather than to the one returned by
27 /// [`WidgetExt::window()`][crate::prelude::WidgetExt::window()] as you would for a [`DrawingArea`][crate::DrawingArea].
28 ///
29 /// ## Properties
30 ///
31 ///
32 /// #### `height`
33 /// Readable | Writeable
34 ///
35 ///
36 /// #### `width`
37 /// Readable | Writeable
38 /// <details><summary><h4>Container</h4></summary>
39 ///
40 ///
41 /// #### `border-width`
42 /// Readable | Writeable
43 ///
44 ///
45 /// #### `child`
46 /// Writeable
47 ///
48 ///
49 /// #### `resize-mode`
50 /// Readable | Writeable
51 /// </details>
52 /// <details><summary><h4>Widget</h4></summary>
53 ///
54 ///
55 /// #### `app-paintable`
56 /// Readable | Writeable
57 ///
58 ///
59 /// #### `can-default`
60 /// Readable | Writeable
61 ///
62 ///
63 /// #### `can-focus`
64 /// Readable | Writeable
65 ///
66 ///
67 /// #### `composite-child`
68 /// Readable
69 ///
70 ///
71 /// #### `double-buffered`
72 /// Whether the widget is double buffered.
73 ///
74 /// Readable | Writeable
75 ///
76 ///
77 /// #### `events`
78 /// Readable | Writeable
79 ///
80 ///
81 /// #### `expand`
82 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
83 ///
84 /// Readable | Writeable
85 ///
86 ///
87 /// #### `focus-on-click`
88 /// Whether the widget should grab focus when it is clicked with the mouse.
89 ///
90 /// This property is only relevant for widgets that can take focus.
91 ///
92 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
93 /// GtkComboBox) implemented this property individually.
94 ///
95 /// Readable | Writeable
96 ///
97 ///
98 /// #### `halign`
99 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
100 ///
101 /// Readable | Writeable
102 ///
103 ///
104 /// #### `has-default`
105 /// Readable | Writeable
106 ///
107 ///
108 /// #### `has-focus`
109 /// Readable | Writeable
110 ///
111 ///
112 /// #### `has-tooltip`
113 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
114 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
115 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
116 /// whether it will provide a tooltip or not.
117 ///
118 /// Note that setting this property to [`true`] for the first time will change
119 /// the event masks of the GdkWindows of this widget to include leave-notify
120 /// and motion-notify events. This cannot and will not be undone when the
121 /// property is set to [`false`] again.
122 ///
123 /// Readable | Writeable
124 ///
125 ///
126 /// #### `height-request`
127 /// Readable | Writeable
128 ///
129 ///
130 /// #### `hexpand`
131 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
132 ///
133 /// Readable | Writeable
134 ///
135 ///
136 /// #### `hexpand-set`
137 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
138 ///
139 /// Readable | Writeable
140 ///
141 ///
142 /// #### `is-focus`
143 /// Readable | Writeable
144 ///
145 ///
146 /// #### `margin`
147 /// Sets all four sides' margin at once. If read, returns max
148 /// margin on any side.
149 ///
150 /// Readable | Writeable
151 ///
152 ///
153 /// #### `margin-bottom`
154 /// Margin on bottom side of widget.
155 ///
156 /// This property adds margin outside of the widget's normal size
157 /// request, the margin will be added in addition to the size from
158 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
159 ///
160 /// Readable | Writeable
161 ///
162 ///
163 /// #### `margin-end`
164 /// Margin on end of widget, horizontally. This property supports
165 /// left-to-right and right-to-left text directions.
166 ///
167 /// This property adds margin outside of the widget's normal size
168 /// request, the margin will be added in addition to the size from
169 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
170 ///
171 /// Readable | Writeable
172 ///
173 ///
174 /// #### `margin-left`
175 /// Margin on left side of widget.
176 ///
177 /// This property adds margin outside of the widget's normal size
178 /// request, the margin will be added in addition to the size from
179 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
180 ///
181 /// Readable | Writeable
182 ///
183 ///
184 /// #### `margin-right`
185 /// Margin on right side of widget.
186 ///
187 /// This property adds margin outside of the widget's normal size
188 /// request, the margin will be added in addition to the size from
189 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
190 ///
191 /// Readable | Writeable
192 ///
193 ///
194 /// #### `margin-start`
195 /// Margin on start of widget, horizontally. This property supports
196 /// left-to-right and right-to-left text directions.
197 ///
198 /// This property adds margin outside of the widget's normal size
199 /// request, the margin will be added in addition to the size from
200 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
201 ///
202 /// Readable | Writeable
203 ///
204 ///
205 /// #### `margin-top`
206 /// Margin on top side of widget.
207 ///
208 /// This property adds margin outside of the widget's normal size
209 /// request, the margin will be added in addition to the size from
210 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
211 ///
212 /// Readable | Writeable
213 ///
214 ///
215 /// #### `name`
216 /// Readable | Writeable
217 ///
218 ///
219 /// #### `no-show-all`
220 /// Readable | Writeable
221 ///
222 ///
223 /// #### `opacity`
224 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
225 /// more details about window opacity.
226 ///
227 /// Before 3.8 this was only available in GtkWindow
228 ///
229 /// Readable | Writeable
230 ///
231 ///
232 /// #### `parent`
233 /// Readable | Writeable
234 ///
235 ///
236 /// #### `receives-default`
237 /// Readable | Writeable
238 ///
239 ///
240 /// #### `scale-factor`
241 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
242 /// more details about widget scaling.
243 ///
244 /// Readable
245 ///
246 ///
247 /// #### `sensitive`
248 /// Readable | Writeable
249 ///
250 ///
251 /// #### `style`
252 /// The style of the widget, which contains information about how it will look (colors, etc).
253 ///
254 /// Readable | Writeable
255 ///
256 ///
257 /// #### `tooltip-markup`
258 /// Sets the text of tooltip to be the given string, which is marked up
259 /// with the [Pango text markup language][PangoMarkupFormat].
260 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
261 ///
262 /// This is a convenience property which will take care of getting the
263 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
264 /// will automatically be set to [`true`] and there will be taken care of
265 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
266 ///
267 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
268 /// are set, the last one wins.
269 ///
270 /// Readable | Writeable
271 ///
272 ///
273 /// #### `tooltip-text`
274 /// Sets the text of tooltip to be the given string.
275 ///
276 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
277 ///
278 /// This is a convenience property which will take care of getting the
279 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
280 /// will automatically be set to [`true`] and there will be taken care of
281 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
282 ///
283 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
284 /// are set, the last one wins.
285 ///
286 /// Readable | Writeable
287 ///
288 ///
289 /// #### `valign`
290 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
291 ///
292 /// Readable | Writeable
293 ///
294 ///
295 /// #### `vexpand`
296 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
297 ///
298 /// Readable | Writeable
299 ///
300 ///
301 /// #### `vexpand-set`
302 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
303 ///
304 /// Readable | Writeable
305 ///
306 ///
307 /// #### `visible`
308 /// Readable | Writeable
309 ///
310 ///
311 /// #### `width-request`
312 /// Readable | Writeable
313 ///
314 ///
315 /// #### `window`
316 /// The widget's window if it is realized, [`None`] otherwise.
317 ///
318 /// Readable
319 /// </details>
320 /// <details><summary><h4>Scrollable</h4></summary>
321 ///
322 ///
323 /// #### `hadjustment`
324 /// Horizontal [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is
325 /// shared between the scrollable widget and its parent.
326 ///
327 /// Readable | Writeable | Construct
328 ///
329 ///
330 /// #### `hscroll-policy`
331 /// Determines whether horizontal scrolling should start once the scrollable
332 /// widget is allocated less than its minimum width or less than its natural width.
333 ///
334 /// Readable | Writeable
335 ///
336 ///
337 /// #### `vadjustment`
338 /// Verical [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is shared
339 /// between the scrollable widget and its parent.
340 ///
341 /// Readable | Writeable | Construct
342 ///
343 ///
344 /// #### `vscroll-policy`
345 /// Determines whether vertical scrolling should start once the scrollable
346 /// widget is allocated less than its minimum height or less than its natural height.
347 ///
348 /// Readable | Writeable
349 /// </details>
350 ///
351 /// # Implements
352 ///
353 /// [`LayoutExt`][trait@crate::prelude::LayoutExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ScrollableExt`][trait@crate::prelude::ScrollableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
354 #[doc(alias = "GtkLayout")]
355 pub struct Layout(Object<ffi::GtkLayout, ffi::GtkLayoutClass>) @extends Container, Widget, @implements Buildable, Scrollable;
356
357 match fn {
358 type_ => || ffi::gtk_layout_get_type(),
359 }
360}
361
362impl Layout {
363 pub const NONE: Option<&'static Layout> = None;
364
365 /// Creates a new [`Layout`][crate::Layout]. Unless you have a specific adjustment
366 /// you’d like the layout to use for scrolling, pass [`None`] for
367 /// `hadjustment` and `vadjustment`.
368 /// ## `hadjustment`
369 /// horizontal scroll adjustment, or [`None`]
370 /// ## `vadjustment`
371 /// vertical scroll adjustment, or [`None`]
372 ///
373 /// # Returns
374 ///
375 /// a new [`Layout`][crate::Layout]
376 #[doc(alias = "gtk_layout_new")]
377 pub fn new(
378 hadjustment: Option<&impl IsA<Adjustment>>,
379 vadjustment: Option<&impl IsA<Adjustment>>,
380 ) -> Layout {
381 assert_initialized_main_thread!();
382 unsafe {
383 Widget::from_glib_none(ffi::gtk_layout_new(
384 hadjustment.map(|p| p.as_ref()).to_glib_none().0,
385 vadjustment.map(|p| p.as_ref()).to_glib_none().0,
386 ))
387 .unsafe_cast()
388 }
389 }
390
391 // rustdoc-stripper-ignore-next
392 /// Creates a new builder-pattern struct instance to construct [`Layout`] objects.
393 ///
394 /// This method returns an instance of [`LayoutBuilder`](crate::builders::LayoutBuilder) which can be used to create [`Layout`] objects.
395 pub fn builder() -> LayoutBuilder {
396 LayoutBuilder::new()
397 }
398}
399
400impl Default for Layout {
401 fn default() -> Self {
402 glib::object::Object::new::<Self>()
403 }
404}
405
406// rustdoc-stripper-ignore-next
407/// A [builder-pattern] type to construct [`Layout`] objects.
408///
409/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
410#[must_use = "The builder must be built to be used"]
411pub struct LayoutBuilder {
412 builder: glib::object::ObjectBuilder<'static, Layout>,
413}
414
415impl LayoutBuilder {
416 fn new() -> Self {
417 Self {
418 builder: glib::object::Object::builder(),
419 }
420 }
421
422 pub fn height(self, height: u32) -> Self {
423 Self {
424 builder: self.builder.property("height", height),
425 }
426 }
427
428 pub fn width(self, width: u32) -> Self {
429 Self {
430 builder: self.builder.property("width", width),
431 }
432 }
433
434 pub fn border_width(self, border_width: u32) -> Self {
435 Self {
436 builder: self.builder.property("border-width", border_width),
437 }
438 }
439
440 pub fn child(self, child: &impl IsA<Widget>) -> Self {
441 Self {
442 builder: self.builder.property("child", child.clone().upcast()),
443 }
444 }
445
446 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
447 Self {
448 builder: self.builder.property("resize-mode", resize_mode),
449 }
450 }
451
452 pub fn app_paintable(self, app_paintable: bool) -> Self {
453 Self {
454 builder: self.builder.property("app-paintable", app_paintable),
455 }
456 }
457
458 pub fn can_default(self, can_default: bool) -> Self {
459 Self {
460 builder: self.builder.property("can-default", can_default),
461 }
462 }
463
464 pub fn can_focus(self, can_focus: bool) -> Self {
465 Self {
466 builder: self.builder.property("can-focus", can_focus),
467 }
468 }
469
470 pub fn events(self, events: gdk::EventMask) -> Self {
471 Self {
472 builder: self.builder.property("events", events),
473 }
474 }
475
476 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
477 pub fn expand(self, expand: bool) -> Self {
478 Self {
479 builder: self.builder.property("expand", expand),
480 }
481 }
482
483 /// Whether the widget should grab focus when it is clicked with the mouse.
484 ///
485 /// This property is only relevant for widgets that can take focus.
486 ///
487 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
488 /// GtkComboBox) implemented this property individually.
489 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
490 Self {
491 builder: self.builder.property("focus-on-click", focus_on_click),
492 }
493 }
494
495 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
496 pub fn halign(self, halign: Align) -> Self {
497 Self {
498 builder: self.builder.property("halign", halign),
499 }
500 }
501
502 pub fn has_default(self, has_default: bool) -> Self {
503 Self {
504 builder: self.builder.property("has-default", has_default),
505 }
506 }
507
508 pub fn has_focus(self, has_focus: bool) -> Self {
509 Self {
510 builder: self.builder.property("has-focus", has_focus),
511 }
512 }
513
514 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
515 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
516 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
517 /// whether it will provide a tooltip or not.
518 ///
519 /// Note that setting this property to [`true`] for the first time will change
520 /// the event masks of the GdkWindows of this widget to include leave-notify
521 /// and motion-notify events. This cannot and will not be undone when the
522 /// property is set to [`false`] again.
523 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
524 Self {
525 builder: self.builder.property("has-tooltip", has_tooltip),
526 }
527 }
528
529 pub fn height_request(self, height_request: i32) -> Self {
530 Self {
531 builder: self.builder.property("height-request", height_request),
532 }
533 }
534
535 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
536 pub fn hexpand(self, hexpand: bool) -> Self {
537 Self {
538 builder: self.builder.property("hexpand", hexpand),
539 }
540 }
541
542 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
543 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
544 Self {
545 builder: self.builder.property("hexpand-set", hexpand_set),
546 }
547 }
548
549 pub fn is_focus(self, is_focus: bool) -> Self {
550 Self {
551 builder: self.builder.property("is-focus", is_focus),
552 }
553 }
554
555 /// Sets all four sides' margin at once. If read, returns max
556 /// margin on any side.
557 pub fn margin(self, margin: i32) -> Self {
558 Self {
559 builder: self.builder.property("margin", margin),
560 }
561 }
562
563 /// Margin on bottom side of widget.
564 ///
565 /// This property adds margin outside of the widget's normal size
566 /// request, the margin will be added in addition to the size from
567 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
568 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
569 Self {
570 builder: self.builder.property("margin-bottom", margin_bottom),
571 }
572 }
573
574 /// Margin on end of widget, horizontally. This property supports
575 /// left-to-right and right-to-left text directions.
576 ///
577 /// This property adds margin outside of the widget's normal size
578 /// request, the margin will be added in addition to the size from
579 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
580 pub fn margin_end(self, margin_end: i32) -> Self {
581 Self {
582 builder: self.builder.property("margin-end", margin_end),
583 }
584 }
585
586 /// Margin on start of widget, horizontally. This property supports
587 /// left-to-right and right-to-left text directions.
588 ///
589 /// This property adds margin outside of the widget's normal size
590 /// request, the margin will be added in addition to the size from
591 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
592 pub fn margin_start(self, margin_start: i32) -> Self {
593 Self {
594 builder: self.builder.property("margin-start", margin_start),
595 }
596 }
597
598 /// Margin on top side of widget.
599 ///
600 /// This property adds margin outside of the widget's normal size
601 /// request, the margin will be added in addition to the size from
602 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
603 pub fn margin_top(self, margin_top: i32) -> Self {
604 Self {
605 builder: self.builder.property("margin-top", margin_top),
606 }
607 }
608
609 pub fn name(self, name: impl Into<glib::GString>) -> Self {
610 Self {
611 builder: self.builder.property("name", name.into()),
612 }
613 }
614
615 pub fn no_show_all(self, no_show_all: bool) -> Self {
616 Self {
617 builder: self.builder.property("no-show-all", no_show_all),
618 }
619 }
620
621 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
622 /// more details about window opacity.
623 ///
624 /// Before 3.8 this was only available in GtkWindow
625 pub fn opacity(self, opacity: f64) -> Self {
626 Self {
627 builder: self.builder.property("opacity", opacity),
628 }
629 }
630
631 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
632 Self {
633 builder: self.builder.property("parent", parent.clone().upcast()),
634 }
635 }
636
637 pub fn receives_default(self, receives_default: bool) -> Self {
638 Self {
639 builder: self.builder.property("receives-default", receives_default),
640 }
641 }
642
643 pub fn sensitive(self, sensitive: bool) -> Self {
644 Self {
645 builder: self.builder.property("sensitive", sensitive),
646 }
647 }
648
649 /// Sets the text of tooltip to be the given string, which is marked up
650 /// with the [Pango text markup language][PangoMarkupFormat].
651 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
652 ///
653 /// This is a convenience property which will take care of getting the
654 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
655 /// will automatically be set to [`true`] and there will be taken care of
656 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
657 ///
658 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
659 /// are set, the last one wins.
660 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
661 Self {
662 builder: self
663 .builder
664 .property("tooltip-markup", tooltip_markup.into()),
665 }
666 }
667
668 /// Sets the text of tooltip to be the given string.
669 ///
670 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
671 ///
672 /// This is a convenience property which will take care of getting the
673 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
674 /// will automatically be set to [`true`] and there will be taken care of
675 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
676 ///
677 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
678 /// are set, the last one wins.
679 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
680 Self {
681 builder: self.builder.property("tooltip-text", tooltip_text.into()),
682 }
683 }
684
685 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
686 pub fn valign(self, valign: Align) -> Self {
687 Self {
688 builder: self.builder.property("valign", valign),
689 }
690 }
691
692 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
693 pub fn vexpand(self, vexpand: bool) -> Self {
694 Self {
695 builder: self.builder.property("vexpand", vexpand),
696 }
697 }
698
699 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
700 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
701 Self {
702 builder: self.builder.property("vexpand-set", vexpand_set),
703 }
704 }
705
706 pub fn visible(self, visible: bool) -> Self {
707 Self {
708 builder: self.builder.property("visible", visible),
709 }
710 }
711
712 pub fn width_request(self, width_request: i32) -> Self {
713 Self {
714 builder: self.builder.property("width-request", width_request),
715 }
716 }
717
718 /// Horizontal [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is
719 /// shared between the scrollable widget and its parent.
720 pub fn hadjustment(self, hadjustment: &impl IsA<Adjustment>) -> Self {
721 Self {
722 builder: self
723 .builder
724 .property("hadjustment", hadjustment.clone().upcast()),
725 }
726 }
727
728 /// Determines whether horizontal scrolling should start once the scrollable
729 /// widget is allocated less than its minimum width or less than its natural width.
730 pub fn hscroll_policy(self, hscroll_policy: ScrollablePolicy) -> Self {
731 Self {
732 builder: self.builder.property("hscroll-policy", hscroll_policy),
733 }
734 }
735
736 /// Verical [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is shared
737 /// between the scrollable widget and its parent.
738 pub fn vadjustment(self, vadjustment: &impl IsA<Adjustment>) -> Self {
739 Self {
740 builder: self
741 .builder
742 .property("vadjustment", vadjustment.clone().upcast()),
743 }
744 }
745
746 /// Determines whether vertical scrolling should start once the scrollable
747 /// widget is allocated less than its minimum height or less than its natural height.
748 pub fn vscroll_policy(self, vscroll_policy: ScrollablePolicy) -> Self {
749 Self {
750 builder: self.builder.property("vscroll-policy", vscroll_policy),
751 }
752 }
753
754 // rustdoc-stripper-ignore-next
755 /// Build the [`Layout`].
756 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
757 pub fn build(self) -> Layout {
758 self.builder.build()
759 }
760}
761
762mod sealed {
763 pub trait Sealed {}
764 impl<T: super::IsA<super::Layout>> Sealed for T {}
765}
766
767/// Trait containing all [`struct@Layout`] methods.
768///
769/// # Implementors
770///
771/// [`Layout`][struct@crate::Layout]
772pub trait LayoutExt: IsA<Layout> + sealed::Sealed + 'static {
773 /// Retrieve the bin window of the layout used for drawing operations.
774 ///
775 /// # Returns
776 ///
777 /// a [`gdk::Window`][crate::gdk::Window]
778 #[doc(alias = "gtk_layout_get_bin_window")]
779 #[doc(alias = "get_bin_window")]
780 fn bin_window(&self) -> Option<gdk::Window> {
781 unsafe {
782 from_glib_none(ffi::gtk_layout_get_bin_window(
783 self.as_ref().to_glib_none().0,
784 ))
785 }
786 }
787
788 /// Gets the size that has been set on the layout, and that determines
789 /// the total extents of the layout’s scrollbar area. See
790 /// gtk_layout_set_size ().
791 ///
792 /// # Returns
793 ///
794 ///
795 /// ## `width`
796 /// location to store the width set on
797 /// `self`, or [`None`]
798 ///
799 /// ## `height`
800 /// location to store the height set on
801 /// `self`, or [`None`]
802 #[doc(alias = "gtk_layout_get_size")]
803 #[doc(alias = "get_size")]
804 fn size(&self) -> (u32, u32) {
805 unsafe {
806 let mut width = mem::MaybeUninit::uninit();
807 let mut height = mem::MaybeUninit::uninit();
808 ffi::gtk_layout_get_size(
809 self.as_ref().to_glib_none().0,
810 width.as_mut_ptr(),
811 height.as_mut_ptr(),
812 );
813 (width.assume_init(), height.assume_init())
814 }
815 }
816
817 #[doc(alias = "gtk_layout_move")]
818 #[doc(alias = "move")]
819 fn move_(&self, child_widget: &impl IsA<Widget>, x: i32, y: i32) {
820 unsafe {
821 ffi::gtk_layout_move(
822 self.as_ref().to_glib_none().0,
823 child_widget.as_ref().to_glib_none().0,
824 x,
825 y,
826 );
827 }
828 }
829
830 /// Adds `child_widget` to `self`, at position (`x`,`y`).
831 /// `self` becomes the new parent container of `child_widget`.
832 /// ## `child_widget`
833 /// child widget
834 /// ## `x`
835 /// X position of child widget
836 /// ## `y`
837 /// Y position of child widget
838 #[doc(alias = "gtk_layout_put")]
839 fn put(&self, child_widget: &impl IsA<Widget>, x: i32, y: i32) {
840 unsafe {
841 ffi::gtk_layout_put(
842 self.as_ref().to_glib_none().0,
843 child_widget.as_ref().to_glib_none().0,
844 x,
845 y,
846 );
847 }
848 }
849
850 /// Sets the size of the scrollable area of the layout.
851 /// ## `width`
852 /// width of entire scrollable area
853 /// ## `height`
854 /// height of entire scrollable area
855 #[doc(alias = "gtk_layout_set_size")]
856 fn set_size(&self, width: u32, height: u32) {
857 unsafe {
858 ffi::gtk_layout_set_size(self.as_ref().to_glib_none().0, width, height);
859 }
860 }
861
862 fn height(&self) -> u32 {
863 ObjectExt::property(self.as_ref(), "height")
864 }
865
866 fn set_height(&self, height: u32) {
867 ObjectExt::set_property(self.as_ref(), "height", height)
868 }
869
870 fn width(&self) -> u32 {
871 ObjectExt::property(self.as_ref(), "width")
872 }
873
874 fn set_width(&self, width: u32) {
875 ObjectExt::set_property(self.as_ref(), "width", width)
876 }
877
878 fn child_x<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
879 crate::prelude::ContainerExtManual::child_property(
880 self.as_ref(),
881 &item.clone().upcast(),
882 "x",
883 )
884 }
885
886 fn set_child_x<T: IsA<crate::Widget>>(&self, item: &T, x: i32) {
887 crate::prelude::ContainerExtManual::child_set_property(
888 self.as_ref(),
889 &item.clone().upcast(),
890 "x",
891 &x,
892 )
893 }
894
895 fn child_y<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
896 crate::prelude::ContainerExtManual::child_property(
897 self.as_ref(),
898 &item.clone().upcast(),
899 "y",
900 )
901 }
902
903 fn set_child_y<T: IsA<crate::Widget>>(&self, item: &T, y: i32) {
904 crate::prelude::ContainerExtManual::child_set_property(
905 self.as_ref(),
906 &item.clone().upcast(),
907 "y",
908 &y,
909 )
910 }
911
912 #[doc(alias = "height")]
913 fn connect_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
914 unsafe extern "C" fn notify_height_trampoline<P: IsA<Layout>, F: Fn(&P) + 'static>(
915 this: *mut ffi::GtkLayout,
916 _param_spec: glib::ffi::gpointer,
917 f: glib::ffi::gpointer,
918 ) {
919 let f: &F = &*(f as *const F);
920 f(Layout::from_glib_borrow(this).unsafe_cast_ref())
921 }
922 unsafe {
923 let f: Box_<F> = Box_::new(f);
924 connect_raw(
925 self.as_ptr() as *mut _,
926 b"notify::height\0".as_ptr() as *const _,
927 Some(transmute::<_, unsafe extern "C" fn()>(
928 notify_height_trampoline::<Self, F> as *const (),
929 )),
930 Box_::into_raw(f),
931 )
932 }
933 }
934
935 #[doc(alias = "width")]
936 fn connect_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
937 unsafe extern "C" fn notify_width_trampoline<P: IsA<Layout>, F: Fn(&P) + 'static>(
938 this: *mut ffi::GtkLayout,
939 _param_spec: glib::ffi::gpointer,
940 f: glib::ffi::gpointer,
941 ) {
942 let f: &F = &*(f as *const F);
943 f(Layout::from_glib_borrow(this).unsafe_cast_ref())
944 }
945 unsafe {
946 let f: Box_<F> = Box_::new(f);
947 connect_raw(
948 self.as_ptr() as *mut _,
949 b"notify::width\0".as_ptr() as *const _,
950 Some(transmute::<_, unsafe extern "C" fn()>(
951 notify_width_trampoline::<Self, F> as *const (),
952 )),
953 Box_::into_raw(f),
954 )
955 }
956 }
957}
958
959impl<O: IsA<Layout>> LayoutExt for O {}
960
961impl fmt::Display for Layout {
962 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
963 f.write_str("Layout")
964 }
965}