gtk4/auto/
drawing_area.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, Buildable, ConstraintTarget, LayoutManager, Overflow,
7    Widget,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// [`DrawingArea`][crate::DrawingArea] is a widget that allows drawing with cairo.
19    ///
20    /// ![An example GtkDrawingArea](drawingarea.png)
21    ///
22    /// It’s essentially a blank widget; you can draw on it. After
23    /// creating a drawing area, the application may want to connect to:
24    ///
25    /// - The [`realize`][struct@crate::Widget#realize] signal to take any necessary actions
26    ///   when the widget is instantiated on a particular display.
27    ///   (Create GDK resources in response to this signal.)
28    ///
29    /// - The [`resize`][struct@crate::DrawingArea#resize] signal to take any necessary
30    ///   actions when the widget changes size.
31    ///
32    /// - Call [`DrawingAreaExtManual::set_draw_func()`][crate::prelude::DrawingAreaExtManual::set_draw_func()] to handle redrawing the
33    ///   contents of the widget.
34    ///
35    /// The following code portion demonstrates using a drawing
36    /// area to display a circle in the normal widget foreground
37    /// color.
38    ///
39    /// ## Simple GtkDrawingArea usage
40    ///
41    /// **⚠️ The following code is in c ⚠️**
42    ///
43    /// ```c
44    /// static void
45    /// draw_function (GtkDrawingArea *area,
46    ///                cairo_t        *cr,
47    ///                int             width,
48    ///                int             height,
49    ///                gpointer        data)
50    /// {
51    ///   GdkRGBA color;
52    ///
53    ///   cairo_arc (cr,
54    ///              width / 2.0, height / 2.0,
55    ///              MIN (width, height) / 2.0,
56    ///              0, 2 * G_PI);
57    ///
58    ///   gtk_widget_get_color (GTK_WIDGET (area),
59    ///                         &color);
60    ///   gdk_cairo_set_source_rgba (cr, &color);
61    ///
62    ///   cairo_fill (cr);
63    /// }
64    ///
65    /// int
66    /// main (int argc, char **argv)
67    /// {
68    ///   gtk_init ();
69    ///
70    ///   GtkWidget *area = gtk_drawing_area_new ();
71    ///   gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (area), 100);
72    ///   gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (area), 100);
73    ///   gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (area),
74    ///                                   draw_function,
75    ///                                   NULL, NULL);
76    ///   return 0;
77    /// }
78    /// ```
79    ///
80    /// The draw function is normally called when a drawing area first comes
81    /// onscreen, or when it’s covered by another window and then uncovered.
82    /// You can also force a redraw by adding to the “damage region” of the
83    /// drawing area’s window using [`WidgetExt::queue_draw()`][crate::prelude::WidgetExt::queue_draw()].
84    /// This will cause the drawing area to call the draw function again.
85    ///
86    /// The available routines for drawing are documented in the
87    /// [Cairo documentation](https://www.cairographics.org/manual/); GDK
88    /// offers additional API to integrate with Cairo, like `cairo_set_source_rgba()`
89    /// or `cairo_set_source_pixbuf()`.
90    ///
91    /// To receive mouse events on a drawing area, you will need to use
92    /// event controllers. To receive keyboard events, you will need to set
93    /// the “can-focus” property on the drawing area, and you should probably
94    /// draw some user-visible indication that the drawing area is focused.
95    ///
96    /// If you need more complex control over your widget, you should consider
97    /// creating your own [`Widget`][crate::Widget] subclass.
98    ///
99    /// ## Properties
100    ///
101    ///
102    /// #### `content-height`
103    ///  The content height.
104    ///
105    /// Readable | Writeable
106    ///
107    ///
108    /// #### `content-width`
109    ///  The content width.
110    ///
111    /// Readable | Writeable
112    /// <details><summary><h4>Widget</h4></summary>
113    ///
114    ///
115    /// #### `can-focus`
116    ///  Whether the widget or any of its descendents can accept
117    /// the input focus.
118    ///
119    /// This property is meant to be set by widget implementations,
120    /// typically in their instance init function.
121    ///
122    /// Readable | Writeable
123    ///
124    ///
125    /// #### `can-target`
126    ///  Whether the widget can receive pointer events.
127    ///
128    /// Readable | Writeable
129    ///
130    ///
131    /// #### `css-classes`
132    ///  A list of css classes applied to this widget.
133    ///
134    /// Readable | Writeable
135    ///
136    ///
137    /// #### `css-name`
138    ///  The name of this widget in the CSS tree.
139    ///
140    /// This property is meant to be set by widget implementations,
141    /// typically in their instance init function.
142    ///
143    /// Readable | Writeable | Construct Only
144    ///
145    ///
146    /// #### `cursor`
147    ///  The cursor used by @widget.
148    ///
149    /// Readable | Writeable
150    ///
151    ///
152    /// #### `focus-on-click`
153    ///  Whether the widget should grab focus when it is clicked with the mouse.
154    ///
155    /// This property is only relevant for widgets that can take focus.
156    ///
157    /// Readable | Writeable
158    ///
159    ///
160    /// #### `focusable`
161    ///  Whether this widget itself will accept the input focus.
162    ///
163    /// Readable | Writeable
164    ///
165    ///
166    /// #### `halign`
167    ///  How to distribute horizontal space if widget gets extra space.
168    ///
169    /// Readable | Writeable
170    ///
171    ///
172    /// #### `has-default`
173    ///  Whether the widget is the default widget.
174    ///
175    /// Readable
176    ///
177    ///
178    /// #### `has-focus`
179    ///  Whether the widget has the input focus.
180    ///
181    /// Readable
182    ///
183    ///
184    /// #### `has-tooltip`
185    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
186    /// signal on @widget.
187    ///
188    /// A true value indicates that @widget can have a tooltip, in this case
189    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
190    /// determine whether it will provide a tooltip or not.
191    ///
192    /// Readable | Writeable
193    ///
194    ///
195    /// #### `height-request`
196    ///  Overrides for height request of the widget.
197    ///
198    /// If this is -1, the natural request will be used.
199    ///
200    /// Readable | Writeable
201    ///
202    ///
203    /// #### `hexpand`
204    ///  Whether to expand horizontally.
205    ///
206    /// Readable | Writeable
207    ///
208    ///
209    /// #### `hexpand-set`
210    ///  Whether to use the `hexpand` property.
211    ///
212    /// Readable | Writeable
213    ///
214    ///
215    /// #### `layout-manager`
216    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
217    /// the preferred size of the widget, and allocate its children.
218    ///
219    /// This property is meant to be set by widget implementations,
220    /// typically in their instance init function.
221    ///
222    /// Readable | Writeable
223    ///
224    ///
225    /// #### `limit-events`
226    ///  Makes this widget act like a modal dialog, with respect to
227    /// event delivery.
228    ///
229    /// Global event controllers will not handle events with targets
230    /// inside the widget, unless they are set up to ignore propagation
231    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
232    ///
233    /// Readable | Writeable
234    ///
235    ///
236    /// #### `margin-bottom`
237    ///  Margin on bottom side of widget.
238    ///
239    /// This property adds margin outside of the widget's normal size
240    /// request, the margin will be added in addition to the size from
241    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
242    ///
243    /// Readable | Writeable
244    ///
245    ///
246    /// #### `margin-end`
247    ///  Margin on end of widget, horizontally.
248    ///
249    /// This property supports left-to-right and right-to-left text
250    /// directions.
251    ///
252    /// This property adds margin outside of the widget's normal size
253    /// request, the margin will be added in addition to the size from
254    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
255    ///
256    /// Readable | Writeable
257    ///
258    ///
259    /// #### `margin-start`
260    ///  Margin on start of widget, horizontally.
261    ///
262    /// This property supports left-to-right and right-to-left text
263    /// directions.
264    ///
265    /// This property adds margin outside of the widget's normal size
266    /// request, the margin will be added in addition to the size from
267    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
268    ///
269    /// Readable | Writeable
270    ///
271    ///
272    /// #### `margin-top`
273    ///  Margin on top side of widget.
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    /// #### `name`
283    ///  The name of the widget.
284    ///
285    /// Readable | Writeable
286    ///
287    ///
288    /// #### `opacity`
289    ///  The requested opacity of the widget.
290    ///
291    /// Readable | Writeable
292    ///
293    ///
294    /// #### `overflow`
295    ///  How content outside the widget's content area is treated.
296    ///
297    /// This property is meant to be set by widget implementations,
298    /// typically in their instance init function.
299    ///
300    /// Readable | Writeable
301    ///
302    ///
303    /// #### `parent`
304    ///  The parent widget of this widget.
305    ///
306    /// Readable
307    ///
308    ///
309    /// #### `receives-default`
310    ///  Whether the widget will receive the default action when it is focused.
311    ///
312    /// Readable | Writeable
313    ///
314    ///
315    /// #### `root`
316    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
317    ///
318    /// This will be `NULL` if the widget is not contained in a root widget.
319    ///
320    /// Readable
321    ///
322    ///
323    /// #### `scale-factor`
324    ///  The scale factor of the widget.
325    ///
326    /// Readable
327    ///
328    ///
329    /// #### `sensitive`
330    ///  Whether the widget responds to input.
331    ///
332    /// Readable | Writeable
333    ///
334    ///
335    /// #### `tooltip-markup`
336    ///  Sets the text of tooltip to be the given string, which is marked up
337    /// with Pango markup.
338    ///
339    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
340    ///
341    /// This is a convenience property which will take care of getting the
342    /// tooltip shown if the given string is not `NULL`:
343    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
344    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
345    /// the default signal handler.
346    ///
347    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
348    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
349    ///
350    /// Readable | Writeable
351    ///
352    ///
353    /// #### `tooltip-text`
354    ///  Sets the text of tooltip to be the given string.
355    ///
356    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
357    ///
358    /// This is a convenience property which will take care of getting the
359    /// tooltip shown if the given string is not `NULL`:
360    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
361    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
362    /// the default signal handler.
363    ///
364    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
365    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
366    ///
367    /// Readable | Writeable
368    ///
369    ///
370    /// #### `valign`
371    ///  How to distribute vertical space if widget gets extra space.
372    ///
373    /// Readable | Writeable
374    ///
375    ///
376    /// #### `vexpand`
377    ///  Whether to expand vertically.
378    ///
379    /// Readable | Writeable
380    ///
381    ///
382    /// #### `vexpand-set`
383    ///  Whether to use the `vexpand` property.
384    ///
385    /// Readable | Writeable
386    ///
387    ///
388    /// #### `visible`
389    ///  Whether the widget is visible.
390    ///
391    /// Readable | Writeable
392    ///
393    ///
394    /// #### `width-request`
395    ///  Overrides for width request of the widget.
396    ///
397    /// If this is -1, the natural request will be used.
398    ///
399    /// Readable | Writeable
400    /// </details>
401    /// <details><summary><h4>Accessible</h4></summary>
402    ///
403    ///
404    /// #### `accessible-role`
405    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
406    ///
407    /// The accessible role cannot be changed once set.
408    ///
409    /// Readable | Writeable
410    /// </details>
411    ///
412    /// ## Signals
413    ///
414    ///
415    /// #### `resize`
416    ///  Emitted once when the widget is realized, and then each time the widget
417    /// is changed while realized.
418    ///
419    /// This is useful in order to keep state up to date with the widget size,
420    /// like for instance a backing surface.
421    ///
422    ///
423    /// <details><summary><h4>Widget</h4></summary>
424    ///
425    ///
426    /// #### `destroy`
427    ///  Signals that all holders of a reference to the widget should release
428    /// the reference that they hold.
429    ///
430    /// May result in finalization of the widget if all references are released.
431    ///
432    /// This signal is not suitable for saving widget state.
433    ///
434    ///
435    ///
436    ///
437    /// #### `direction-changed`
438    ///  Emitted when the text direction of a widget changes.
439    ///
440    ///
441    ///
442    ///
443    /// #### `hide`
444    ///  Emitted when @widget is hidden.
445    ///
446    ///
447    ///
448    ///
449    /// #### `keynav-failed`
450    ///  Emitted if keyboard navigation fails.
451    ///
452    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
453    ///
454    ///
455    ///
456    ///
457    /// #### `map`
458    ///  Emitted when @widget is going to be mapped.
459    ///
460    /// A widget is mapped when the widget is visible (which is controlled with
461    /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
462    /// are also visible.
463    ///
464    /// The `::map` signal can be used to determine whether a widget will be drawn,
465    /// for instance it can resume an animation that was stopped during the
466    /// emission of [`unmap`][struct@crate::Widget#unmap].
467    ///
468    ///
469    ///
470    ///
471    /// #### `mnemonic-activate`
472    ///  Emitted when a widget is activated via a mnemonic.
473    ///
474    /// The default handler for this signal activates @widget if @group_cycling
475    /// is false, or just makes @widget grab focus if @group_cycling is true.
476    ///
477    ///
478    ///
479    ///
480    /// #### `move-focus`
481    ///  Emitted when the focus is moved.
482    ///
483    /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
484    ///
485    /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
486    /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
487    ///
488    /// Action
489    ///
490    ///
491    /// #### `query-tooltip`
492    ///  Emitted when the widget’s tooltip is about to be shown.
493    ///
494    /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
495    /// is true and the hover timeout has expired with the cursor hovering
496    /// above @widget; or emitted when @widget got focus in keyboard mode.
497    ///
498    /// Using the given coordinates, the signal handler should determine
499    /// whether a tooltip should be shown for @widget. If this is the case
500    /// true should be returned, false otherwise. Note that if @keyboard_mode
501    /// is true, the values of @x and @y are undefined and should not be used.
502    ///
503    /// The signal handler is free to manipulate @tooltip with the therefore
504    /// destined function calls.
505    ///
506    ///
507    ///
508    ///
509    /// #### `realize`
510    ///  Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
511    ///
512    /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
513    /// or the widget has been mapped (that is, it is going to be drawn).
514    ///
515    ///
516    ///
517    ///
518    /// #### `show`
519    ///  Emitted when @widget is shown.
520    ///
521    ///
522    ///
523    ///
524    /// #### `state-flags-changed`
525    ///  Emitted when the widget state changes.
526    ///
527    /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
528    ///
529    ///
530    ///
531    ///
532    /// #### `unmap`
533    ///  Emitted when @widget is going to be unmapped.
534    ///
535    /// A widget is unmapped when either it or any of its parents up to the
536    /// toplevel widget have been set as hidden.
537    ///
538    /// As `::unmap` indicates that a widget will not be shown any longer,
539    /// it can be used to, for example, stop an animation on the widget.
540    ///
541    ///
542    ///
543    ///
544    /// #### `unrealize`
545    ///  Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
546    ///
547    /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
548    /// or the widget has been unmapped (that is, it is going to be hidden).
549    ///
550    ///
551    /// </details>
552    ///
553    /// # Implements
554    ///
555    /// [`DrawingAreaExt`][trait@crate::prelude::DrawingAreaExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`DrawingAreaExtManual`][trait@crate::prelude::DrawingAreaExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
556    #[doc(alias = "GtkDrawingArea")]
557    pub struct DrawingArea(Object<ffi::GtkDrawingArea, ffi::GtkDrawingAreaClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
558
559    match fn {
560        type_ => || ffi::gtk_drawing_area_get_type(),
561    }
562}
563
564impl DrawingArea {
565    pub const NONE: Option<&'static DrawingArea> = None;
566
567    /// Creates a new drawing area.
568    ///
569    /// # Returns
570    ///
571    /// a new [`DrawingArea`][crate::DrawingArea]
572    #[doc(alias = "gtk_drawing_area_new")]
573    pub fn new() -> DrawingArea {
574        assert_initialized_main_thread!();
575        unsafe { Widget::from_glib_none(ffi::gtk_drawing_area_new()).unsafe_cast() }
576    }
577
578    // rustdoc-stripper-ignore-next
579    /// Creates a new builder-pattern struct instance to construct [`DrawingArea`] objects.
580    ///
581    /// This method returns an instance of [`DrawingAreaBuilder`](crate::builders::DrawingAreaBuilder) which can be used to create [`DrawingArea`] objects.
582    pub fn builder() -> DrawingAreaBuilder {
583        DrawingAreaBuilder::new()
584    }
585}
586
587impl Default for DrawingArea {
588    fn default() -> Self {
589        Self::new()
590    }
591}
592
593// rustdoc-stripper-ignore-next
594/// A [builder-pattern] type to construct [`DrawingArea`] objects.
595///
596/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
597#[must_use = "The builder must be built to be used"]
598pub struct DrawingAreaBuilder {
599    builder: glib::object::ObjectBuilder<'static, DrawingArea>,
600}
601
602impl DrawingAreaBuilder {
603    fn new() -> Self {
604        Self {
605            builder: glib::object::Object::builder(),
606        }
607    }
608
609    /// The content height.
610    pub fn content_height(self, content_height: i32) -> Self {
611        Self {
612            builder: self.builder.property("content-height", content_height),
613        }
614    }
615
616    /// The content width.
617    pub fn content_width(self, content_width: i32) -> Self {
618        Self {
619            builder: self.builder.property("content-width", content_width),
620        }
621    }
622
623    /// Whether the widget or any of its descendents can accept
624    /// the input focus.
625    ///
626    /// This property is meant to be set by widget implementations,
627    /// typically in their instance init function.
628    pub fn can_focus(self, can_focus: bool) -> Self {
629        Self {
630            builder: self.builder.property("can-focus", can_focus),
631        }
632    }
633
634    /// Whether the widget can receive pointer events.
635    pub fn can_target(self, can_target: bool) -> Self {
636        Self {
637            builder: self.builder.property("can-target", can_target),
638        }
639    }
640
641    /// A list of css classes applied to this widget.
642    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
643        Self {
644            builder: self.builder.property("css-classes", css_classes.into()),
645        }
646    }
647
648    /// The name of this widget in the CSS tree.
649    ///
650    /// This property is meant to be set by widget implementations,
651    /// typically in their instance init function.
652    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
653        Self {
654            builder: self.builder.property("css-name", css_name.into()),
655        }
656    }
657
658    /// The cursor used by @widget.
659    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
660        Self {
661            builder: self.builder.property("cursor", cursor.clone()),
662        }
663    }
664
665    /// Whether the widget should grab focus when it is clicked with the mouse.
666    ///
667    /// This property is only relevant for widgets that can take focus.
668    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
669        Self {
670            builder: self.builder.property("focus-on-click", focus_on_click),
671        }
672    }
673
674    /// Whether this widget itself will accept the input focus.
675    pub fn focusable(self, focusable: bool) -> Self {
676        Self {
677            builder: self.builder.property("focusable", focusable),
678        }
679    }
680
681    /// How to distribute horizontal space if widget gets extra space.
682    pub fn halign(self, halign: Align) -> Self {
683        Self {
684            builder: self.builder.property("halign", halign),
685        }
686    }
687
688    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
689    /// signal on @widget.
690    ///
691    /// A true value indicates that @widget can have a tooltip, in this case
692    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
693    /// determine whether it will provide a tooltip or not.
694    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
695        Self {
696            builder: self.builder.property("has-tooltip", has_tooltip),
697        }
698    }
699
700    /// Overrides for height request of the widget.
701    ///
702    /// If this is -1, the natural request will be used.
703    pub fn height_request(self, height_request: i32) -> Self {
704        Self {
705            builder: self.builder.property("height-request", height_request),
706        }
707    }
708
709    /// Whether to expand horizontally.
710    pub fn hexpand(self, hexpand: bool) -> Self {
711        Self {
712            builder: self.builder.property("hexpand", hexpand),
713        }
714    }
715
716    /// Whether to use the `hexpand` property.
717    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
718        Self {
719            builder: self.builder.property("hexpand-set", hexpand_set),
720        }
721    }
722
723    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
724    /// the preferred size of the widget, and allocate its children.
725    ///
726    /// This property is meant to be set by widget implementations,
727    /// typically in their instance init function.
728    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
729        Self {
730            builder: self
731                .builder
732                .property("layout-manager", layout_manager.clone().upcast()),
733        }
734    }
735
736    /// Makes this widget act like a modal dialog, with respect to
737    /// event delivery.
738    ///
739    /// Global event controllers will not handle events with targets
740    /// inside the widget, unless they are set up to ignore propagation
741    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
742    #[cfg(feature = "v4_18")]
743    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
744    pub fn limit_events(self, limit_events: bool) -> Self {
745        Self {
746            builder: self.builder.property("limit-events", limit_events),
747        }
748    }
749
750    /// Margin on bottom side of widget.
751    ///
752    /// This property adds margin outside of the widget's normal size
753    /// request, the margin will be added in addition to the size from
754    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
755    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
756        Self {
757            builder: self.builder.property("margin-bottom", margin_bottom),
758        }
759    }
760
761    /// Margin on end of widget, horizontally.
762    ///
763    /// This property supports left-to-right and right-to-left text
764    /// directions.
765    ///
766    /// This property adds margin outside of the widget's normal size
767    /// request, the margin will be added in addition to the size from
768    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
769    pub fn margin_end(self, margin_end: i32) -> Self {
770        Self {
771            builder: self.builder.property("margin-end", margin_end),
772        }
773    }
774
775    /// Margin on start of widget, horizontally.
776    ///
777    /// This property supports left-to-right and right-to-left text
778    /// directions.
779    ///
780    /// This property adds margin outside of the widget's normal size
781    /// request, the margin will be added in addition to the size from
782    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
783    pub fn margin_start(self, margin_start: i32) -> Self {
784        Self {
785            builder: self.builder.property("margin-start", margin_start),
786        }
787    }
788
789    /// Margin on top side of widget.
790    ///
791    /// This property adds margin outside of the widget's normal size
792    /// request, the margin will be added in addition to the size from
793    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
794    pub fn margin_top(self, margin_top: i32) -> Self {
795        Self {
796            builder: self.builder.property("margin-top", margin_top),
797        }
798    }
799
800    /// The name of the widget.
801    pub fn name(self, name: impl Into<glib::GString>) -> Self {
802        Self {
803            builder: self.builder.property("name", name.into()),
804        }
805    }
806
807    /// The requested opacity of the widget.
808    pub fn opacity(self, opacity: f64) -> Self {
809        Self {
810            builder: self.builder.property("opacity", opacity),
811        }
812    }
813
814    /// How content outside the widget's content area is treated.
815    ///
816    /// This property is meant to be set by widget implementations,
817    /// typically in their instance init function.
818    pub fn overflow(self, overflow: Overflow) -> Self {
819        Self {
820            builder: self.builder.property("overflow", overflow),
821        }
822    }
823
824    /// Whether the widget will receive the default action when it is focused.
825    pub fn receives_default(self, receives_default: bool) -> Self {
826        Self {
827            builder: self.builder.property("receives-default", receives_default),
828        }
829    }
830
831    /// Whether the widget responds to input.
832    pub fn sensitive(self, sensitive: bool) -> Self {
833        Self {
834            builder: self.builder.property("sensitive", sensitive),
835        }
836    }
837
838    /// Sets the text of tooltip to be the given string, which is marked up
839    /// with Pango markup.
840    ///
841    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
842    ///
843    /// This is a convenience property which will take care of getting the
844    /// tooltip shown if the given string is not `NULL`:
845    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
846    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
847    /// the default signal handler.
848    ///
849    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
850    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
851    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
852        Self {
853            builder: self
854                .builder
855                .property("tooltip-markup", tooltip_markup.into()),
856        }
857    }
858
859    /// Sets the text of tooltip to be the given string.
860    ///
861    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
862    ///
863    /// This is a convenience property which will take care of getting the
864    /// tooltip shown if the given string is not `NULL`:
865    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
866    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
867    /// the default signal handler.
868    ///
869    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
870    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
871    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
872        Self {
873            builder: self.builder.property("tooltip-text", tooltip_text.into()),
874        }
875    }
876
877    /// How to distribute vertical space if widget gets extra space.
878    pub fn valign(self, valign: Align) -> Self {
879        Self {
880            builder: self.builder.property("valign", valign),
881        }
882    }
883
884    /// Whether to expand vertically.
885    pub fn vexpand(self, vexpand: bool) -> Self {
886        Self {
887            builder: self.builder.property("vexpand", vexpand),
888        }
889    }
890
891    /// Whether to use the `vexpand` property.
892    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
893        Self {
894            builder: self.builder.property("vexpand-set", vexpand_set),
895        }
896    }
897
898    /// Whether the widget is visible.
899    pub fn visible(self, visible: bool) -> Self {
900        Self {
901            builder: self.builder.property("visible", visible),
902        }
903    }
904
905    /// Overrides for width request of the widget.
906    ///
907    /// If this is -1, the natural request will be used.
908    pub fn width_request(self, width_request: i32) -> Self {
909        Self {
910            builder: self.builder.property("width-request", width_request),
911        }
912    }
913
914    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
915    ///
916    /// The accessible role cannot be changed once set.
917    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
918        Self {
919            builder: self.builder.property("accessible-role", accessible_role),
920        }
921    }
922
923    // rustdoc-stripper-ignore-next
924    /// Build the [`DrawingArea`].
925    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
926    pub fn build(self) -> DrawingArea {
927        assert_initialized_main_thread!();
928        self.builder.build()
929    }
930}
931
932mod sealed {
933    pub trait Sealed {}
934    impl<T: super::IsA<super::DrawingArea>> Sealed for T {}
935}
936
937/// Trait containing all [`struct@DrawingArea`] methods.
938///
939/// # Implementors
940///
941/// [`DrawingArea`][struct@crate::DrawingArea]
942pub trait DrawingAreaExt: IsA<DrawingArea> + sealed::Sealed + 'static {
943    /// Retrieves the content height of the [`DrawingArea`][crate::DrawingArea].
944    ///
945    /// # Returns
946    ///
947    /// The height requested for content of the drawing area
948    #[doc(alias = "gtk_drawing_area_get_content_height")]
949    #[doc(alias = "get_content_height")]
950    #[doc(alias = "content-height")]
951    fn content_height(&self) -> i32 {
952        unsafe { ffi::gtk_drawing_area_get_content_height(self.as_ref().to_glib_none().0) }
953    }
954
955    /// Retrieves the content width of the [`DrawingArea`][crate::DrawingArea].
956    ///
957    /// # Returns
958    ///
959    /// The width requested for content of the drawing area
960    #[doc(alias = "gtk_drawing_area_get_content_width")]
961    #[doc(alias = "get_content_width")]
962    #[doc(alias = "content-width")]
963    fn content_width(&self) -> i32 {
964        unsafe { ffi::gtk_drawing_area_get_content_width(self.as_ref().to_glib_none().0) }
965    }
966
967    /// Sets the desired height of the contents of the drawing area.
968    ///
969    /// Note that because widgets may be allocated larger sizes than they
970    /// requested, it is possible that the actual height passed to your draw
971    /// function is larger than the height set here. You can use
972    /// [`WidgetExt::set_valign()`][crate::prelude::WidgetExt::set_valign()] to avoid that.
973    ///
974    /// If the height is set to 0 (the default), the drawing area may disappear.
975    /// ## `height`
976    /// the height of contents
977    #[doc(alias = "gtk_drawing_area_set_content_height")]
978    #[doc(alias = "content-height")]
979    fn set_content_height(&self, height: i32) {
980        unsafe {
981            ffi::gtk_drawing_area_set_content_height(self.as_ref().to_glib_none().0, height);
982        }
983    }
984
985    /// Sets the desired width of the contents of the drawing area.
986    ///
987    /// Note that because widgets may be allocated larger sizes than they
988    /// requested, it is possible that the actual width passed to your draw
989    /// function is larger than the width set here. You can use
990    /// [`WidgetExt::set_halign()`][crate::prelude::WidgetExt::set_halign()] to avoid that.
991    ///
992    /// If the width is set to 0 (the default), the drawing area may disappear.
993    /// ## `width`
994    /// the width of contents
995    #[doc(alias = "gtk_drawing_area_set_content_width")]
996    #[doc(alias = "content-width")]
997    fn set_content_width(&self, width: i32) {
998        unsafe {
999            ffi::gtk_drawing_area_set_content_width(self.as_ref().to_glib_none().0, width);
1000        }
1001    }
1002
1003    /// Emitted once when the widget is realized, and then each time the widget
1004    /// is changed while realized.
1005    ///
1006    /// This is useful in order to keep state up to date with the widget size,
1007    /// like for instance a backing surface.
1008    /// ## `width`
1009    /// the width of the viewport
1010    /// ## `height`
1011    /// the height of the viewport
1012    #[doc(alias = "resize")]
1013    fn connect_resize<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
1014        unsafe extern "C" fn resize_trampoline<
1015            P: IsA<DrawingArea>,
1016            F: Fn(&P, i32, i32) + 'static,
1017        >(
1018            this: *mut ffi::GtkDrawingArea,
1019            width: std::ffi::c_int,
1020            height: std::ffi::c_int,
1021            f: glib::ffi::gpointer,
1022        ) {
1023            let f: &F = &*(f as *const F);
1024            f(
1025                DrawingArea::from_glib_borrow(this).unsafe_cast_ref(),
1026                width,
1027                height,
1028            )
1029        }
1030        unsafe {
1031            let f: Box_<F> = Box_::new(f);
1032            connect_raw(
1033                self.as_ptr() as *mut _,
1034                b"resize\0".as_ptr() as *const _,
1035                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1036                    resize_trampoline::<Self, F> as *const (),
1037                )),
1038                Box_::into_raw(f),
1039            )
1040        }
1041    }
1042
1043    #[doc(alias = "content-height")]
1044    fn connect_content_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1045        unsafe extern "C" fn notify_content_height_trampoline<
1046            P: IsA<DrawingArea>,
1047            F: Fn(&P) + 'static,
1048        >(
1049            this: *mut ffi::GtkDrawingArea,
1050            _param_spec: glib::ffi::gpointer,
1051            f: glib::ffi::gpointer,
1052        ) {
1053            let f: &F = &*(f as *const F);
1054            f(DrawingArea::from_glib_borrow(this).unsafe_cast_ref())
1055        }
1056        unsafe {
1057            let f: Box_<F> = Box_::new(f);
1058            connect_raw(
1059                self.as_ptr() as *mut _,
1060                b"notify::content-height\0".as_ptr() as *const _,
1061                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1062                    notify_content_height_trampoline::<Self, F> as *const (),
1063                )),
1064                Box_::into_raw(f),
1065            )
1066        }
1067    }
1068
1069    #[doc(alias = "content-width")]
1070    fn connect_content_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1071        unsafe extern "C" fn notify_content_width_trampoline<
1072            P: IsA<DrawingArea>,
1073            F: Fn(&P) + 'static,
1074        >(
1075            this: *mut ffi::GtkDrawingArea,
1076            _param_spec: glib::ffi::gpointer,
1077            f: glib::ffi::gpointer,
1078        ) {
1079            let f: &F = &*(f as *const F);
1080            f(DrawingArea::from_glib_borrow(this).unsafe_cast_ref())
1081        }
1082        unsafe {
1083            let f: Box_<F> = Box_::new(f);
1084            connect_raw(
1085                self.as_ptr() as *mut _,
1086                b"notify::content-width\0".as_ptr() as *const _,
1087                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1088                    notify_content_width_trampoline::<Self, F> as *const (),
1089                )),
1090                Box_::into_raw(f),
1091            )
1092        }
1093    }
1094}
1095
1096impl<O: IsA<DrawingArea>> DrawingAreaExt for O {}