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