Skip to main content

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