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