gtk4/auto/gl_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#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
8 Widget,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 /// Allows drawing with OpenGL.
20 ///
21 /// <picture>
22 /// <source srcset="glarea-dark.png" media="(prefers-color-scheme: dark)">
23 /// <img alt="An example GtkGLArea" src="glarea.png">
24 /// </picture>
25 ///
26 /// [`GLArea`][crate::GLArea] sets up its own [`gdk::GLContext`][crate::gdk::GLContext], and creates a custom
27 /// GL framebuffer that the widget will do GL rendering onto. It also ensures
28 /// that this framebuffer is the default GL rendering target when rendering.
29 /// The completed rendering is integrated into the larger GTK scene graph as
30 /// a texture.
31 ///
32 /// In order to draw, you have to connect to the [`render`][struct@crate::GLArea#render]
33 /// signal, or subclass [`GLArea`][crate::GLArea] and override the GtkGLAreaClass.render
34 /// virtual function.
35 ///
36 /// The [`GLArea`][crate::GLArea] widget ensures that the [`gdk::GLContext`][crate::gdk::GLContext] is associated with
37 /// the widget's drawing area, and it is kept updated when the size and
38 /// position of the drawing area changes.
39 ///
40 /// ## Drawing with GtkGLArea
41 ///
42 /// The simplest way to draw using OpenGL commands in a [`GLArea`][crate::GLArea] is to
43 /// create a widget instance and connect to the [`render`][struct@crate::GLArea#render] signal:
44 ///
45 /// The `render()` function will be called when the [`GLArea`][crate::GLArea] is ready
46 /// for you to draw its content:
47 ///
48 /// The initial contents of the framebuffer are transparent.
49 ///
50 /// **⚠️ The following code is in c ⚠️**
51 ///
52 /// ```c
53 /// static gboolean
54 /// render (GtkGLArea *area, GdkGLContext *context)
55 /// {
56 /// // inside this function it's safe to use GL; the given
57 /// // GdkGLContext has been made current to the drawable
58 /// // surface used by the `GtkGLArea` and the viewport has
59 /// // already been set to be the size of the allocation
60 ///
61 /// // we can start by clearing the buffer
62 /// glClearColor (0, 0, 0, 0);
63 /// glClear (GL_COLOR_BUFFER_BIT);
64 ///
65 /// // draw your object
66 /// // draw_an_object ();
67 ///
68 /// // we completed our drawing; the draw commands will be
69 /// // flushed at the end of the signal emission chain, and
70 /// // the buffers will be drawn on the window
71 /// return TRUE;
72 /// }
73 ///
74 /// void setup_glarea (void)
75 /// {
76 /// // create a GtkGLArea instance
77 /// GtkWidget *gl_area = gtk_gl_area_new ();
78 ///
79 /// // connect to the "render" signal
80 /// g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);
81 /// }
82 /// ```
83 ///
84 /// If you need to initialize OpenGL state, e.g. buffer objects or
85 /// shaders, you should use the [`realize`][struct@crate::Widget#realize] signal;
86 /// you can use the [`unrealize`][struct@crate::Widget#unrealize] signal to clean up.
87 /// Since the [`gdk::GLContext`][crate::gdk::GLContext] creation and initialization may fail, you
88 /// will need to check for errors, using [`GLAreaExt::error()`][crate::prelude::GLAreaExt::error()].
89 ///
90 /// An example of how to safely initialize the GL state is:
91 ///
92 /// **⚠️ The following code is in c ⚠️**
93 ///
94 /// ```c
95 /// static void
96 /// on_realize (GtkGLarea *area)
97 /// {
98 /// // We need to make the context current if we want to
99 /// // call GL API
100 /// gtk_gl_area_make_current (area);
101 ///
102 /// // If there were errors during the initialization or
103 /// // when trying to make the context current, this
104 /// // function will return a GError for you to catch
105 /// if (gtk_gl_area_get_error (area) != NULL)
106 /// return;
107 ///
108 /// // You can also use gtk_gl_area_set_error() in order
109 /// // to show eventual initialization errors on the
110 /// // GtkGLArea widget itself
111 /// GError *internal_error = NULL;
112 /// init_buffer_objects (&error);
113 /// if (error != NULL)
114 /// {
115 /// gtk_gl_area_set_error (area, error);
116 /// g_error_free (error);
117 /// return;
118 /// }
119 ///
120 /// init_shaders (&error);
121 /// if (error != NULL)
122 /// {
123 /// gtk_gl_area_set_error (area, error);
124 /// g_error_free (error);
125 /// return;
126 /// }
127 /// }
128 /// ```
129 ///
130 /// If you need to change the options for creating the [`gdk::GLContext`][crate::gdk::GLContext]
131 /// you should use the [`create-context`][struct@crate::GLArea#create-context] signal.
132 ///
133 /// ## Properties
134 ///
135 ///
136 /// #### `allowed-apis`
137 /// The allowed APIs.
138 ///
139 /// Readable | Writeable
140 ///
141 ///
142 /// #### `api`
143 /// The API currently in use.
144 ///
145 /// Readable
146 ///
147 ///
148 /// #### `auto-render`
149 /// If set to [`true`] the ::render signal will be emitted every time
150 /// the widget draws.
151 ///
152 /// This is the default and is useful if drawing the widget is faster.
153 ///
154 /// If set to [`false`] the data from previous rendering is kept around and will
155 /// be used for drawing the widget the next time, unless the window is resized.
156 /// In order to force a rendering [`GLAreaExt::queue_render()`][crate::prelude::GLAreaExt::queue_render()] must be called.
157 /// This mode is useful when the scene changes seldom, but takes a long time
158 /// to redraw.
159 ///
160 /// Readable | Writeable
161 ///
162 ///
163 /// #### `context`
164 /// The [`gdk::GLContext`][crate::gdk::GLContext] used by the [`GLArea`][crate::GLArea] widget.
165 ///
166 /// The [`GLArea`][crate::GLArea] widget is responsible for creating the [`gdk::GLContext`][crate::gdk::GLContext]
167 /// instance. If you need to render with other kinds of buffers (stencil,
168 /// depth, etc), use render buffers.
169 ///
170 /// Readable
171 ///
172 ///
173 /// #### `has-depth-buffer`
174 /// If set to [`true`] the widget will allocate and enable a depth buffer for the
175 /// target framebuffer.
176 ///
177 /// Setting this property will enable GL's depth testing as a side effect. If
178 /// you don't need depth testing, you should call `glDisable(GL_DEPTH_TEST)`
179 /// in your `GtkGLArea::render` handler.
180 ///
181 /// Readable | Writeable
182 ///
183 ///
184 /// #### `has-stencil-buffer`
185 /// If set to [`true`] the widget will allocate and enable a stencil buffer for the
186 /// target framebuffer.
187 ///
188 /// Readable | Writeable
189 ///
190 ///
191 /// #### `use-es`
192 /// If set to [`true`] the widget will try to create a [`gdk::GLContext`][crate::gdk::GLContext] using
193 /// OpenGL ES instead of OpenGL.
194 ///
195 /// Readable | Writeable
196 /// <details><summary><h4>Widget</h4></summary>
197 ///
198 ///
199 /// #### `can-focus`
200 /// Whether the widget or any of its descendents can accept
201 /// the input focus.
202 ///
203 /// This property is meant to be set by widget implementations,
204 /// typically in their instance init function.
205 ///
206 /// Readable | Writeable
207 ///
208 ///
209 /// #### `can-target`
210 /// Whether the widget can receive pointer events.
211 ///
212 /// Readable | Writeable
213 ///
214 ///
215 /// #### `css-classes`
216 /// A list of css classes applied to this widget.
217 ///
218 /// Readable | Writeable
219 ///
220 ///
221 /// #### `css-name`
222 /// The name of this widget in the CSS tree.
223 ///
224 /// This property is meant to be set by widget implementations,
225 /// typically in their instance init function.
226 ///
227 /// Readable | Writeable | Construct Only
228 ///
229 ///
230 /// #### `cursor`
231 /// The cursor used by @widget.
232 ///
233 /// Readable | Writeable
234 ///
235 ///
236 /// #### `focus-on-click`
237 /// Whether the widget should grab focus when it is clicked with the mouse.
238 ///
239 /// This property is only relevant for widgets that can take focus.
240 ///
241 /// Readable | Writeable
242 ///
243 ///
244 /// #### `focusable`
245 /// Whether this widget itself will accept the input focus.
246 ///
247 /// Readable | Writeable
248 ///
249 ///
250 /// #### `halign`
251 /// How to distribute horizontal space if widget gets extra space.
252 ///
253 /// Readable | Writeable
254 ///
255 ///
256 /// #### `has-default`
257 /// Whether the widget is the default widget.
258 ///
259 /// Readable
260 ///
261 ///
262 /// #### `has-focus`
263 /// Whether the widget has the input focus.
264 ///
265 /// Readable
266 ///
267 ///
268 /// #### `has-tooltip`
269 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
270 /// signal on @widget.
271 ///
272 /// A true value indicates that @widget can have a tooltip, in this case
273 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
274 /// determine whether it will provide a tooltip or not.
275 ///
276 /// Readable | Writeable
277 ///
278 ///
279 /// #### `height-request`
280 /// Overrides for height request of the widget.
281 ///
282 /// If this is -1, the natural request will be used.
283 ///
284 /// Readable | Writeable
285 ///
286 ///
287 /// #### `hexpand`
288 /// Whether to expand horizontally.
289 ///
290 /// Readable | Writeable
291 ///
292 ///
293 /// #### `hexpand-set`
294 /// Whether to use the `hexpand` property.
295 ///
296 /// Readable | Writeable
297 ///
298 ///
299 /// #### `layout-manager`
300 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
301 /// the preferred size of the widget, and allocate its children.
302 ///
303 /// This property is meant to be set by widget implementations,
304 /// typically in their instance init function.
305 ///
306 /// Readable | Writeable
307 ///
308 ///
309 /// #### `limit-events`
310 /// Makes this widget act like a modal dialog, with respect to
311 /// event delivery.
312 ///
313 /// Global event controllers will not handle events with targets
314 /// inside the widget, unless they are set up to ignore propagation
315 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
316 ///
317 /// Readable | Writeable
318 ///
319 ///
320 /// #### `margin-bottom`
321 /// Margin on bottom side of widget.
322 ///
323 /// This property adds margin outside of the widget's normal size
324 /// request, the margin will be added in addition to the size from
325 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
326 ///
327 /// Readable | Writeable
328 ///
329 ///
330 /// #### `margin-end`
331 /// Margin on end of widget, horizontally.
332 ///
333 /// This property supports left-to-right and right-to-left text
334 /// directions.
335 ///
336 /// This property adds margin outside of the widget's normal size
337 /// request, the margin will be added in addition to the size from
338 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
339 ///
340 /// Readable | Writeable
341 ///
342 ///
343 /// #### `margin-start`
344 /// Margin on start of widget, horizontally.
345 ///
346 /// This property supports left-to-right and right-to-left text
347 /// directions.
348 ///
349 /// This property adds margin outside of the widget's normal size
350 /// request, the margin will be added in addition to the size from
351 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
352 ///
353 /// Readable | Writeable
354 ///
355 ///
356 /// #### `margin-top`
357 /// Margin on top side of widget.
358 ///
359 /// This property adds margin outside of the widget's normal size
360 /// request, the margin will be added in addition to the size from
361 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
362 ///
363 /// Readable | Writeable
364 ///
365 ///
366 /// #### `name`
367 /// The name of the widget.
368 ///
369 /// Readable | Writeable
370 ///
371 ///
372 /// #### `opacity`
373 /// The requested opacity of the widget.
374 ///
375 /// Readable | Writeable
376 ///
377 ///
378 /// #### `overflow`
379 /// How content outside the widget's content area is treated.
380 ///
381 /// This property is meant to be set by widget implementations,
382 /// typically in their instance init function.
383 ///
384 /// Readable | Writeable
385 ///
386 ///
387 /// #### `parent`
388 /// The parent widget of this widget.
389 ///
390 /// Readable
391 ///
392 ///
393 /// #### `receives-default`
394 /// Whether the widget will receive the default action when it is focused.
395 ///
396 /// Readable | Writeable
397 ///
398 ///
399 /// #### `root`
400 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
401 ///
402 /// This will be `NULL` if the widget is not contained in a root widget.
403 ///
404 /// Readable
405 ///
406 ///
407 /// #### `scale-factor`
408 /// The scale factor of the widget.
409 ///
410 /// Readable
411 ///
412 ///
413 /// #### `sensitive`
414 /// Whether the widget responds to input.
415 ///
416 /// Readable | Writeable
417 ///
418 ///
419 /// #### `tooltip-markup`
420 /// Sets the text of tooltip to be the given string, which is marked up
421 /// with Pango markup.
422 ///
423 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
424 ///
425 /// This is a convenience property which will take care of getting the
426 /// tooltip shown if the given string is not `NULL`:
427 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
428 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
429 /// the default signal handler.
430 ///
431 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
432 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
433 ///
434 /// Readable | Writeable
435 ///
436 ///
437 /// #### `tooltip-text`
438 /// Sets the text of tooltip to be the given string.
439 ///
440 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
441 ///
442 /// This is a convenience property which will take care of getting the
443 /// tooltip shown if the given string is not `NULL`:
444 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
445 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
446 /// the default signal handler.
447 ///
448 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
449 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
450 ///
451 /// Readable | Writeable
452 ///
453 ///
454 /// #### `valign`
455 /// How to distribute vertical space if widget gets extra space.
456 ///
457 /// Readable | Writeable
458 ///
459 ///
460 /// #### `vexpand`
461 /// Whether to expand vertically.
462 ///
463 /// Readable | Writeable
464 ///
465 ///
466 /// #### `vexpand-set`
467 /// Whether to use the `vexpand` property.
468 ///
469 /// Readable | Writeable
470 ///
471 ///
472 /// #### `visible`
473 /// Whether the widget is visible.
474 ///
475 /// Readable | Writeable
476 ///
477 ///
478 /// #### `width-request`
479 /// Overrides for width request of the widget.
480 ///
481 /// If this is -1, the natural request will be used.
482 ///
483 /// Readable | Writeable
484 /// </details>
485 /// <details><summary><h4>Accessible</h4></summary>
486 ///
487 ///
488 /// #### `accessible-role`
489 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
490 ///
491 /// The accessible role cannot be changed once set.
492 ///
493 /// Readable | Writeable
494 /// </details>
495 ///
496 /// ## Signals
497 ///
498 ///
499 /// #### `create-context`
500 /// Emitted when the widget is being realized.
501 ///
502 /// This allows you to override how the GL context is created.
503 /// This is useful when you want to reuse an existing GL context,
504 /// or if you want to try creating different kinds of GL options.
505 ///
506 /// If context creation fails then the signal handler can use
507 /// [`GLAreaExt::set_error()`][crate::prelude::GLAreaExt::set_error()] to register a more detailed error
508 /// of how the construction failed.
509 ///
510 ///
511 ///
512 ///
513 /// #### `render`
514 /// Emitted every time the contents of the [`GLArea`][crate::GLArea] should be redrawn.
515 ///
516 /// The @context is bound to the @area prior to emitting this function,
517 /// and the buffers are painted to the window once the emission terminates.
518 ///
519 ///
520 ///
521 ///
522 /// #### `resize`
523 /// Emitted once when the widget is realized, and then each time the widget
524 /// is changed while realized.
525 ///
526 /// This is useful in order to keep GL state up to date with the widget size,
527 /// like for instance camera properties which may depend on the width/height
528 /// ratio.
529 ///
530 /// The GL context for the area is guaranteed to be current when this signal
531 /// is emitted.
532 ///
533 /// The default handler sets up the GL viewport.
534 ///
535 ///
536 /// <details><summary><h4>Widget</h4></summary>
537 ///
538 ///
539 /// #### `destroy`
540 /// Signals that all holders of a reference to the widget should release
541 /// the reference that they hold.
542 ///
543 /// May result in finalization of the widget if all references are released.
544 ///
545 /// This signal is not suitable for saving widget state.
546 ///
547 ///
548 ///
549 ///
550 /// #### `direction-changed`
551 /// Emitted when the text direction of a widget changes.
552 ///
553 ///
554 ///
555 ///
556 /// #### `hide`
557 /// Emitted when @widget is hidden.
558 ///
559 ///
560 ///
561 ///
562 /// #### `keynav-failed`
563 /// Emitted if keyboard navigation fails.
564 ///
565 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
566 ///
567 ///
568 ///
569 ///
570 /// #### `map`
571 /// Emitted when @widget is going to be mapped.
572 ///
573 /// A widget is mapped when the widget is visible (which is controlled with
574 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
575 /// are also visible.
576 ///
577 /// The `::map` signal can be used to determine whether a widget will be drawn,
578 /// for instance it can resume an animation that was stopped during the
579 /// emission of [`unmap`][struct@crate::Widget#unmap].
580 ///
581 ///
582 ///
583 ///
584 /// #### `mnemonic-activate`
585 /// Emitted when a widget is activated via a mnemonic.
586 ///
587 /// The default handler for this signal activates @widget if @group_cycling
588 /// is false, or just makes @widget grab focus if @group_cycling is true.
589 ///
590 ///
591 ///
592 ///
593 /// #### `move-focus`
594 /// Emitted when the focus is moved.
595 ///
596 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
597 ///
598 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
599 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
600 ///
601 /// Action
602 ///
603 ///
604 /// #### `query-tooltip`
605 /// Emitted when the widget’s tooltip is about to be shown.
606 ///
607 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
608 /// is true and the hover timeout has expired with the cursor hovering
609 /// above @widget; or emitted when @widget got focus in keyboard mode.
610 ///
611 /// Using the given coordinates, the signal handler should determine
612 /// whether a tooltip should be shown for @widget. If this is the case
613 /// true should be returned, false otherwise. Note that if @keyboard_mode
614 /// is true, the values of @x and @y are undefined and should not be used.
615 ///
616 /// The signal handler is free to manipulate @tooltip with the therefore
617 /// destined function calls.
618 ///
619 ///
620 ///
621 ///
622 /// #### `realize`
623 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
624 ///
625 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
626 /// or the widget has been mapped (that is, it is going to be drawn).
627 ///
628 ///
629 ///
630 ///
631 /// #### `show`
632 /// Emitted when @widget is shown.
633 ///
634 ///
635 ///
636 ///
637 /// #### `state-flags-changed`
638 /// Emitted when the widget state changes.
639 ///
640 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
641 ///
642 ///
643 ///
644 ///
645 /// #### `unmap`
646 /// Emitted when @widget is going to be unmapped.
647 ///
648 /// A widget is unmapped when either it or any of its parents up to the
649 /// toplevel widget have been set as hidden.
650 ///
651 /// As `::unmap` indicates that a widget will not be shown any longer,
652 /// it can be used to, for example, stop an animation on the widget.
653 ///
654 ///
655 ///
656 ///
657 /// #### `unrealize`
658 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
659 ///
660 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
661 /// or the widget has been unmapped (that is, it is going to be hidden).
662 ///
663 ///
664 /// </details>
665 ///
666 /// # Implements
667 ///
668 /// [`GLAreaExt`][trait@crate::prelude::GLAreaExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
669 #[doc(alias = "GtkGLArea")]
670 pub struct GLArea(Object<ffi::GtkGLArea, ffi::GtkGLAreaClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
671
672 match fn {
673 type_ => || ffi::gtk_gl_area_get_type(),
674 }
675}
676
677impl GLArea {
678 pub const NONE: Option<&'static GLArea> = None;
679
680 /// Creates a new [`GLArea`][crate::GLArea] widget.
681 ///
682 /// # Returns
683 ///
684 /// a new [`GLArea`][crate::GLArea]
685 #[doc(alias = "gtk_gl_area_new")]
686 pub fn new() -> GLArea {
687 assert_initialized_main_thread!();
688 unsafe { Widget::from_glib_none(ffi::gtk_gl_area_new()).unsafe_cast() }
689 }
690
691 // rustdoc-stripper-ignore-next
692 /// Creates a new builder-pattern struct instance to construct [`GLArea`] objects.
693 ///
694 /// This method returns an instance of [`GLAreaBuilder`](crate::builders::GLAreaBuilder) which can be used to create [`GLArea`] objects.
695 pub fn builder() -> GLAreaBuilder {
696 GLAreaBuilder::new()
697 }
698}
699
700impl Default for GLArea {
701 fn default() -> Self {
702 Self::new()
703 }
704}
705
706// rustdoc-stripper-ignore-next
707/// A [builder-pattern] type to construct [`GLArea`] objects.
708///
709/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
710#[must_use = "The builder must be built to be used"]
711pub struct GLAreaBuilder {
712 builder: glib::object::ObjectBuilder<'static, GLArea>,
713}
714
715impl GLAreaBuilder {
716 fn new() -> Self {
717 Self {
718 builder: glib::object::Object::builder(),
719 }
720 }
721
722 /// The allowed APIs.
723 #[cfg(feature = "v4_12")]
724 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
725 pub fn allowed_apis(self, allowed_apis: gdk::GLAPI) -> Self {
726 Self {
727 builder: self.builder.property("allowed-apis", allowed_apis),
728 }
729 }
730
731 /// If set to [`true`] the ::render signal will be emitted every time
732 /// the widget draws.
733 ///
734 /// This is the default and is useful if drawing the widget is faster.
735 ///
736 /// If set to [`false`] the data from previous rendering is kept around and will
737 /// be used for drawing the widget the next time, unless the window is resized.
738 /// In order to force a rendering [`GLAreaExt::queue_render()`][crate::prelude::GLAreaExt::queue_render()] must be called.
739 /// This mode is useful when the scene changes seldom, but takes a long time
740 /// to redraw.
741 pub fn auto_render(self, auto_render: bool) -> Self {
742 Self {
743 builder: self.builder.property("auto-render", auto_render),
744 }
745 }
746
747 /// If set to [`true`] the widget will allocate and enable a depth buffer for the
748 /// target framebuffer.
749 ///
750 /// Setting this property will enable GL's depth testing as a side effect. If
751 /// you don't need depth testing, you should call `glDisable(GL_DEPTH_TEST)`
752 /// in your `GtkGLArea::render` handler.
753 pub fn has_depth_buffer(self, has_depth_buffer: bool) -> Self {
754 Self {
755 builder: self.builder.property("has-depth-buffer", has_depth_buffer),
756 }
757 }
758
759 /// If set to [`true`] the widget will allocate and enable a stencil buffer for the
760 /// target framebuffer.
761 pub fn has_stencil_buffer(self, has_stencil_buffer: bool) -> Self {
762 Self {
763 builder: self
764 .builder
765 .property("has-stencil-buffer", has_stencil_buffer),
766 }
767 }
768
769 /// If set to [`true`] the widget will try to create a [`gdk::GLContext`][crate::gdk::GLContext] using
770 /// OpenGL ES instead of OpenGL.
771 /// Use [`allowed-apis`][struct@crate::GLArea#allowed-apis]
772 #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
773 pub fn use_es(self, use_es: bool) -> Self {
774 Self {
775 builder: self.builder.property("use-es", use_es),
776 }
777 }
778
779 /// Whether the widget or any of its descendents can accept
780 /// the input focus.
781 ///
782 /// This property is meant to be set by widget implementations,
783 /// typically in their instance init function.
784 pub fn can_focus(self, can_focus: bool) -> Self {
785 Self {
786 builder: self.builder.property("can-focus", can_focus),
787 }
788 }
789
790 /// Whether the widget can receive pointer events.
791 pub fn can_target(self, can_target: bool) -> Self {
792 Self {
793 builder: self.builder.property("can-target", can_target),
794 }
795 }
796
797 /// A list of css classes applied to this widget.
798 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
799 Self {
800 builder: self.builder.property("css-classes", css_classes.into()),
801 }
802 }
803
804 /// The name of this widget in the CSS tree.
805 ///
806 /// This property is meant to be set by widget implementations,
807 /// typically in their instance init function.
808 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
809 Self {
810 builder: self.builder.property("css-name", css_name.into()),
811 }
812 }
813
814 /// The cursor used by @widget.
815 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
816 Self {
817 builder: self.builder.property("cursor", cursor.clone()),
818 }
819 }
820
821 /// Whether the widget should grab focus when it is clicked with the mouse.
822 ///
823 /// This property is only relevant for widgets that can take focus.
824 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
825 Self {
826 builder: self.builder.property("focus-on-click", focus_on_click),
827 }
828 }
829
830 /// Whether this widget itself will accept the input focus.
831 pub fn focusable(self, focusable: bool) -> Self {
832 Self {
833 builder: self.builder.property("focusable", focusable),
834 }
835 }
836
837 /// How to distribute horizontal space if widget gets extra space.
838 pub fn halign(self, halign: Align) -> Self {
839 Self {
840 builder: self.builder.property("halign", halign),
841 }
842 }
843
844 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
845 /// signal on @widget.
846 ///
847 /// A true value indicates that @widget can have a tooltip, in this case
848 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
849 /// determine whether it will provide a tooltip or not.
850 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
851 Self {
852 builder: self.builder.property("has-tooltip", has_tooltip),
853 }
854 }
855
856 /// Overrides for height request of the widget.
857 ///
858 /// If this is -1, the natural request will be used.
859 pub fn height_request(self, height_request: i32) -> Self {
860 Self {
861 builder: self.builder.property("height-request", height_request),
862 }
863 }
864
865 /// Whether to expand horizontally.
866 pub fn hexpand(self, hexpand: bool) -> Self {
867 Self {
868 builder: self.builder.property("hexpand", hexpand),
869 }
870 }
871
872 /// Whether to use the `hexpand` property.
873 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
874 Self {
875 builder: self.builder.property("hexpand-set", hexpand_set),
876 }
877 }
878
879 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
880 /// the preferred size of the widget, and allocate its children.
881 ///
882 /// This property is meant to be set by widget implementations,
883 /// typically in their instance init function.
884 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
885 Self {
886 builder: self
887 .builder
888 .property("layout-manager", layout_manager.clone().upcast()),
889 }
890 }
891
892 /// Makes this widget act like a modal dialog, with respect to
893 /// event delivery.
894 ///
895 /// Global event controllers will not handle events with targets
896 /// inside the widget, unless they are set up to ignore propagation
897 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
898 #[cfg(feature = "v4_18")]
899 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
900 pub fn limit_events(self, limit_events: bool) -> Self {
901 Self {
902 builder: self.builder.property("limit-events", limit_events),
903 }
904 }
905
906 /// Margin on bottom side of widget.
907 ///
908 /// This property adds margin outside of the widget's normal size
909 /// request, the margin will be added in addition to the size from
910 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
911 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
912 Self {
913 builder: self.builder.property("margin-bottom", margin_bottom),
914 }
915 }
916
917 /// Margin on end of widget, horizontally.
918 ///
919 /// This property supports left-to-right and right-to-left text
920 /// directions.
921 ///
922 /// This property adds margin outside of the widget's normal size
923 /// request, the margin will be added in addition to the size from
924 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
925 pub fn margin_end(self, margin_end: i32) -> Self {
926 Self {
927 builder: self.builder.property("margin-end", margin_end),
928 }
929 }
930
931 /// Margin on start of widget, horizontally.
932 ///
933 /// This property supports left-to-right and right-to-left text
934 /// directions.
935 ///
936 /// This property adds margin outside of the widget's normal size
937 /// request, the margin will be added in addition to the size from
938 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
939 pub fn margin_start(self, margin_start: i32) -> Self {
940 Self {
941 builder: self.builder.property("margin-start", margin_start),
942 }
943 }
944
945 /// Margin on top side of widget.
946 ///
947 /// This property adds margin outside of the widget's normal size
948 /// request, the margin will be added in addition to the size from
949 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
950 pub fn margin_top(self, margin_top: i32) -> Self {
951 Self {
952 builder: self.builder.property("margin-top", margin_top),
953 }
954 }
955
956 /// The name of the widget.
957 pub fn name(self, name: impl Into<glib::GString>) -> Self {
958 Self {
959 builder: self.builder.property("name", name.into()),
960 }
961 }
962
963 /// The requested opacity of the widget.
964 pub fn opacity(self, opacity: f64) -> Self {
965 Self {
966 builder: self.builder.property("opacity", opacity),
967 }
968 }
969
970 /// How content outside the widget's content area is treated.
971 ///
972 /// This property is meant to be set by widget implementations,
973 /// typically in their instance init function.
974 pub fn overflow(self, overflow: Overflow) -> Self {
975 Self {
976 builder: self.builder.property("overflow", overflow),
977 }
978 }
979
980 /// Whether the widget will receive the default action when it is focused.
981 pub fn receives_default(self, receives_default: bool) -> Self {
982 Self {
983 builder: self.builder.property("receives-default", receives_default),
984 }
985 }
986
987 /// Whether the widget responds to input.
988 pub fn sensitive(self, sensitive: bool) -> Self {
989 Self {
990 builder: self.builder.property("sensitive", sensitive),
991 }
992 }
993
994 /// Sets the text of tooltip to be the given string, which is marked up
995 /// with Pango markup.
996 ///
997 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
998 ///
999 /// This is a convenience property which will take care of getting the
1000 /// tooltip shown if the given string is not `NULL`:
1001 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1002 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1003 /// the default signal handler.
1004 ///
1005 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1006 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1007 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1008 Self {
1009 builder: self
1010 .builder
1011 .property("tooltip-markup", tooltip_markup.into()),
1012 }
1013 }
1014
1015 /// Sets the text of tooltip to be the given string.
1016 ///
1017 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1018 ///
1019 /// This is a convenience property which will take care of getting the
1020 /// tooltip shown if the given string is not `NULL`:
1021 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1022 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1023 /// the default signal handler.
1024 ///
1025 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1026 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1027 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1028 Self {
1029 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1030 }
1031 }
1032
1033 /// How to distribute vertical space if widget gets extra space.
1034 pub fn valign(self, valign: Align) -> Self {
1035 Self {
1036 builder: self.builder.property("valign", valign),
1037 }
1038 }
1039
1040 /// Whether to expand vertically.
1041 pub fn vexpand(self, vexpand: bool) -> Self {
1042 Self {
1043 builder: self.builder.property("vexpand", vexpand),
1044 }
1045 }
1046
1047 /// Whether to use the `vexpand` property.
1048 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1049 Self {
1050 builder: self.builder.property("vexpand-set", vexpand_set),
1051 }
1052 }
1053
1054 /// Whether the widget is visible.
1055 pub fn visible(self, visible: bool) -> Self {
1056 Self {
1057 builder: self.builder.property("visible", visible),
1058 }
1059 }
1060
1061 /// Overrides for width request of the widget.
1062 ///
1063 /// If this is -1, the natural request will be used.
1064 pub fn width_request(self, width_request: i32) -> Self {
1065 Self {
1066 builder: self.builder.property("width-request", width_request),
1067 }
1068 }
1069
1070 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1071 ///
1072 /// The accessible role cannot be changed once set.
1073 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1074 Self {
1075 builder: self.builder.property("accessible-role", accessible_role),
1076 }
1077 }
1078
1079 // rustdoc-stripper-ignore-next
1080 /// Build the [`GLArea`].
1081 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1082 pub fn build(self) -> GLArea {
1083 assert_initialized_main_thread!();
1084 self.builder.build()
1085 }
1086}
1087
1088/// Trait containing all [`struct@GLArea`] methods.
1089///
1090/// # Implementors
1091///
1092/// [`GLArea`][struct@crate::GLArea]
1093pub trait GLAreaExt: IsA<GLArea> + 'static {
1094 /// Binds buffers to the framebuffer.
1095 ///
1096 /// Ensures that the @self framebuffer object is made the current draw
1097 /// and read target, and that all the required buffers for the @self
1098 /// are created and bound to the framebuffer.
1099 ///
1100 /// This function is automatically called before emitting the
1101 /// [`render`][struct@crate::GLArea#render] signal, and doesn't normally need to be
1102 /// called by application code.
1103 #[doc(alias = "gtk_gl_area_attach_buffers")]
1104 fn attach_buffers(&self) {
1105 unsafe {
1106 ffi::gtk_gl_area_attach_buffers(self.as_ref().to_glib_none().0);
1107 }
1108 }
1109
1110 /// Gets the allowed APIs.
1111 ///
1112 /// See [`set_allowed_apis()`][Self::set_allowed_apis()].
1113 ///
1114 /// # Returns
1115 ///
1116 /// the allowed APIs
1117 #[cfg(feature = "v4_12")]
1118 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1119 #[doc(alias = "gtk_gl_area_get_allowed_apis")]
1120 #[doc(alias = "get_allowed_apis")]
1121 #[doc(alias = "allowed-apis")]
1122 fn allowed_apis(&self) -> gdk::GLAPI {
1123 unsafe {
1124 from_glib(ffi::gtk_gl_area_get_allowed_apis(
1125 self.as_ref().to_glib_none().0,
1126 ))
1127 }
1128 }
1129
1130 /// Gets the API that is currently in use.
1131 ///
1132 /// If the GL area has not been realized yet, 0 is returned.
1133 ///
1134 /// # Returns
1135 ///
1136 /// the currently used API
1137 #[cfg(feature = "v4_12")]
1138 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1139 #[doc(alias = "gtk_gl_area_get_api")]
1140 #[doc(alias = "get_api")]
1141 fn api(&self) -> gdk::GLAPI {
1142 unsafe { from_glib(ffi::gtk_gl_area_get_api(self.as_ref().to_glib_none().0)) }
1143 }
1144
1145 /// Returns whether the area is in auto render mode or not.
1146 ///
1147 /// # Returns
1148 ///
1149 /// [`true`] if the @self is auto rendering, [`false`] otherwise
1150 #[doc(alias = "gtk_gl_area_get_auto_render")]
1151 #[doc(alias = "get_auto_render")]
1152 #[doc(alias = "auto-render")]
1153 fn is_auto_render(&self) -> bool {
1154 unsafe {
1155 from_glib(ffi::gtk_gl_area_get_auto_render(
1156 self.as_ref().to_glib_none().0,
1157 ))
1158 }
1159 }
1160
1161 /// Retrieves the [`gdk::GLContext`][crate::gdk::GLContext] used by @self.
1162 ///
1163 /// # Returns
1164 ///
1165 /// the [`gdk::GLContext`][crate::gdk::GLContext]
1166 #[doc(alias = "gtk_gl_area_get_context")]
1167 #[doc(alias = "get_context")]
1168 fn context(&self) -> Option<gdk::GLContext> {
1169 unsafe { from_glib_none(ffi::gtk_gl_area_get_context(self.as_ref().to_glib_none().0)) }
1170 }
1171
1172 /// Gets the current error set on the @self.
1173 ///
1174 /// # Returns
1175 ///
1176 /// the `GError`
1177 #[doc(alias = "gtk_gl_area_get_error")]
1178 #[doc(alias = "get_error")]
1179 fn error(&self) -> Option<glib::Error> {
1180 unsafe { from_glib_none(ffi::gtk_gl_area_get_error(self.as_ref().to_glib_none().0)) }
1181 }
1182
1183 /// Returns whether the area has a depth buffer.
1184 ///
1185 /// # Returns
1186 ///
1187 /// [`true`] if the @self has a depth buffer, [`false`] otherwise
1188 #[doc(alias = "gtk_gl_area_get_has_depth_buffer")]
1189 #[doc(alias = "get_has_depth_buffer")]
1190 #[doc(alias = "has-depth-buffer")]
1191 fn has_depth_buffer(&self) -> bool {
1192 unsafe {
1193 from_glib(ffi::gtk_gl_area_get_has_depth_buffer(
1194 self.as_ref().to_glib_none().0,
1195 ))
1196 }
1197 }
1198
1199 /// Returns whether the area has a stencil buffer.
1200 ///
1201 /// # Returns
1202 ///
1203 /// [`true`] if the @self has a stencil buffer, [`false`] otherwise
1204 #[doc(alias = "gtk_gl_area_get_has_stencil_buffer")]
1205 #[doc(alias = "get_has_stencil_buffer")]
1206 #[doc(alias = "has-stencil-buffer")]
1207 fn has_stencil_buffer(&self) -> bool {
1208 unsafe {
1209 from_glib(ffi::gtk_gl_area_get_has_stencil_buffer(
1210 self.as_ref().to_glib_none().0,
1211 ))
1212 }
1213 }
1214
1215 /// Retrieves the required version of OpenGL.
1216 ///
1217 /// See [`set_required_version()`][Self::set_required_version()].
1218 ///
1219 /// # Returns
1220 ///
1221 ///
1222 /// ## `major`
1223 /// return location for the required major version
1224 ///
1225 /// ## `minor`
1226 /// return location for the required minor version
1227 #[doc(alias = "gtk_gl_area_get_required_version")]
1228 #[doc(alias = "get_required_version")]
1229 fn required_version(&self) -> (i32, i32) {
1230 unsafe {
1231 let mut major = std::mem::MaybeUninit::uninit();
1232 let mut minor = std::mem::MaybeUninit::uninit();
1233 ffi::gtk_gl_area_get_required_version(
1234 self.as_ref().to_glib_none().0,
1235 major.as_mut_ptr(),
1236 minor.as_mut_ptr(),
1237 );
1238 (major.assume_init(), minor.assume_init())
1239 }
1240 }
1241
1242 /// Returns whether the [`GLArea`][crate::GLArea] should use OpenGL ES.
1243 ///
1244 /// See [`set_use_es()`][Self::set_use_es()].
1245 ///
1246 /// # Deprecated since 4.12
1247 ///
1248 /// Use [`api()`][Self::api()]
1249 ///
1250 /// # Returns
1251 ///
1252 /// [`true`] if the [`GLArea`][crate::GLArea] should create an OpenGL ES context
1253 /// and [`false`] otherwise
1254 #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
1255 #[allow(deprecated)]
1256 #[doc(alias = "gtk_gl_area_get_use_es")]
1257 #[doc(alias = "get_use_es")]
1258 #[doc(alias = "use-es")]
1259 fn uses_es(&self) -> bool {
1260 unsafe { from_glib(ffi::gtk_gl_area_get_use_es(self.as_ref().to_glib_none().0)) }
1261 }
1262
1263 /// Ensures that the [`gdk::GLContext`][crate::gdk::GLContext] used by @self is associated with
1264 /// the [`GLArea`][crate::GLArea].
1265 ///
1266 /// This function is automatically called before emitting the
1267 /// [`render`][struct@crate::GLArea#render] signal, and doesn't normally need
1268 /// to be called by application code.
1269 #[doc(alias = "gtk_gl_area_make_current")]
1270 fn make_current(&self) {
1271 unsafe {
1272 ffi::gtk_gl_area_make_current(self.as_ref().to_glib_none().0);
1273 }
1274 }
1275
1276 /// Marks the currently rendered data (if any) as invalid, and queues
1277 /// a redraw of the widget.
1278 ///
1279 /// This ensures that the [`render`][struct@crate::GLArea#render] signal
1280 /// is emitted during the draw.
1281 ///
1282 /// This is only needed when [`set_auto_render()`][Self::set_auto_render()] has
1283 /// been called with a [`false`] value. The default behaviour is to
1284 /// emit [`render`][struct@crate::GLArea#render] on each draw.
1285 #[doc(alias = "gtk_gl_area_queue_render")]
1286 fn queue_render(&self) {
1287 unsafe {
1288 ffi::gtk_gl_area_queue_render(self.as_ref().to_glib_none().0);
1289 }
1290 }
1291
1292 /// Sets the allowed APIs to create a context with.
1293 ///
1294 /// You should check [`api`][struct@crate::GLArea#api] before drawing
1295 /// with either API.
1296 ///
1297 /// By default, all APIs are allowed.
1298 /// ## `apis`
1299 /// the allowed APIs
1300 #[cfg(feature = "v4_12")]
1301 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1302 #[doc(alias = "gtk_gl_area_set_allowed_apis")]
1303 #[doc(alias = "allowed-apis")]
1304 fn set_allowed_apis(&self, apis: gdk::GLAPI) {
1305 unsafe {
1306 ffi::gtk_gl_area_set_allowed_apis(self.as_ref().to_glib_none().0, apis.into_glib());
1307 }
1308 }
1309
1310 /// Sets whether the [`GLArea`][crate::GLArea] is in auto render mode.
1311 ///
1312 /// If @auto_render is [`true`] the [`render`][struct@crate::GLArea#render] signal will
1313 /// be emitted every time the widget draws. This is the default and is
1314 /// useful if drawing the widget is faster.
1315 ///
1316 /// If @auto_render is [`false`] the data from previous rendering is kept
1317 /// around and will be used for drawing the widget the next time,
1318 /// unless the window is resized. In order to force a rendering
1319 /// [`queue_render()`][Self::queue_render()] must be called. This mode is
1320 /// useful when the scene changes seldom, but takes a long time to redraw.
1321 /// ## `auto_render`
1322 /// a boolean
1323 #[doc(alias = "gtk_gl_area_set_auto_render")]
1324 #[doc(alias = "auto-render")]
1325 fn set_auto_render(&self, auto_render: bool) {
1326 unsafe {
1327 ffi::gtk_gl_area_set_auto_render(
1328 self.as_ref().to_glib_none().0,
1329 auto_render.into_glib(),
1330 );
1331 }
1332 }
1333
1334 /// Sets an error on the area which will be shown instead of the
1335 /// GL rendering.
1336 ///
1337 /// This is useful in the [`create-context`][struct@crate::GLArea#create-context]
1338 /// signal if GL context creation fails.
1339 /// ## `error`
1340 /// a new `GError`, or [`None`] to unset the error
1341 #[doc(alias = "gtk_gl_area_set_error")]
1342 fn set_error(&self, error: Option<&glib::Error>) {
1343 unsafe {
1344 ffi::gtk_gl_area_set_error(self.as_ref().to_glib_none().0, error.to_glib_none().0);
1345 }
1346 }
1347
1348 /// Sets whether the [`GLArea`][crate::GLArea] should use a depth buffer.
1349 ///
1350 /// If @has_depth_buffer is [`true`] the widget will allocate and
1351 /// enable a depth buffer for the target framebuffer. Otherwise
1352 /// there will be none.
1353 /// ## `has_depth_buffer`
1354 /// [`true`] to add a depth buffer
1355 #[doc(alias = "gtk_gl_area_set_has_depth_buffer")]
1356 #[doc(alias = "has-depth-buffer")]
1357 fn set_has_depth_buffer(&self, has_depth_buffer: bool) {
1358 unsafe {
1359 ffi::gtk_gl_area_set_has_depth_buffer(
1360 self.as_ref().to_glib_none().0,
1361 has_depth_buffer.into_glib(),
1362 );
1363 }
1364 }
1365
1366 /// Sets whether the [`GLArea`][crate::GLArea] should use a stencil buffer.
1367 ///
1368 /// If @has_stencil_buffer is [`true`] the widget will allocate and
1369 /// enable a stencil buffer for the target framebuffer. Otherwise
1370 /// there will be none.
1371 /// ## `has_stencil_buffer`
1372 /// [`true`] to add a stencil buffer
1373 #[doc(alias = "gtk_gl_area_set_has_stencil_buffer")]
1374 #[doc(alias = "has-stencil-buffer")]
1375 fn set_has_stencil_buffer(&self, has_stencil_buffer: bool) {
1376 unsafe {
1377 ffi::gtk_gl_area_set_has_stencil_buffer(
1378 self.as_ref().to_glib_none().0,
1379 has_stencil_buffer.into_glib(),
1380 );
1381 }
1382 }
1383
1384 /// Sets the required version of OpenGL to be used when creating
1385 /// the context for the widget.
1386 ///
1387 /// This function must be called before the area has been realized.
1388 /// ## `major`
1389 /// the major version
1390 /// ## `minor`
1391 /// the minor version
1392 #[doc(alias = "gtk_gl_area_set_required_version")]
1393 fn set_required_version(&self, major: i32, minor: i32) {
1394 unsafe {
1395 ffi::gtk_gl_area_set_required_version(self.as_ref().to_glib_none().0, major, minor);
1396 }
1397 }
1398
1399 /// Sets whether the @self should create an OpenGL or an OpenGL ES context.
1400 ///
1401 /// You should check the capabilities of the [`gdk::GLContext`][crate::gdk::GLContext] before drawing
1402 /// with either API.
1403 ///
1404 /// # Deprecated since 4.12
1405 ///
1406 /// Use [`set_allowed_apis()`][Self::set_allowed_apis()]
1407 /// ## `use_es`
1408 /// whether to use OpenGL or OpenGL ES
1409 #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
1410 #[allow(deprecated)]
1411 #[doc(alias = "gtk_gl_area_set_use_es")]
1412 #[doc(alias = "use-es")]
1413 fn set_use_es(&self, use_es: bool) {
1414 unsafe {
1415 ffi::gtk_gl_area_set_use_es(self.as_ref().to_glib_none().0, use_es.into_glib());
1416 }
1417 }
1418
1419 /// Emitted when the widget is being realized.
1420 ///
1421 /// This allows you to override how the GL context is created.
1422 /// This is useful when you want to reuse an existing GL context,
1423 /// or if you want to try creating different kinds of GL options.
1424 ///
1425 /// If context creation fails then the signal handler can use
1426 /// [`set_error()`][Self::set_error()] to register a more detailed error
1427 /// of how the construction failed.
1428 ///
1429 /// # Returns
1430 ///
1431 /// a newly created [`gdk::GLContext`][crate::gdk::GLContext];
1432 /// the [`GLArea`][crate::GLArea] widget will take ownership of the returned value.
1433 #[doc(alias = "create-context")]
1434 fn connect_create_context<F: Fn(&Self) -> Option<gdk::GLContext> + 'static>(
1435 &self,
1436 f: F,
1437 ) -> SignalHandlerId {
1438 unsafe extern "C" fn create_context_trampoline<
1439 P: IsA<GLArea>,
1440 F: Fn(&P) -> Option<gdk::GLContext> + 'static,
1441 >(
1442 this: *mut ffi::GtkGLArea,
1443 f: glib::ffi::gpointer,
1444 ) -> *mut gdk::ffi::GdkGLContext {
1445 let f: &F = &*(f as *const F);
1446 f(GLArea::from_glib_borrow(this).unsafe_cast_ref()).to_glib_full()
1447 }
1448 unsafe {
1449 let f: Box_<F> = Box_::new(f);
1450 connect_raw(
1451 self.as_ptr() as *mut _,
1452 c"create-context".as_ptr() as *const _,
1453 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1454 create_context_trampoline::<Self, F> as *const (),
1455 )),
1456 Box_::into_raw(f),
1457 )
1458 }
1459 }
1460
1461 /// Emitted every time the contents of the [`GLArea`][crate::GLArea] should be redrawn.
1462 ///
1463 /// The @context is bound to the @area prior to emitting this function,
1464 /// and the buffers are painted to the window once the emission terminates.
1465 /// ## `context`
1466 /// the [`gdk::GLContext`][crate::gdk::GLContext] used by @area
1467 ///
1468 /// # Returns
1469 ///
1470 /// [`true`] to stop other handlers from being invoked for the event.
1471 /// [`false`] to propagate the event further.
1472 #[doc(alias = "render")]
1473 fn connect_render<F: Fn(&Self, &gdk::GLContext) -> glib::Propagation + 'static>(
1474 &self,
1475 f: F,
1476 ) -> SignalHandlerId {
1477 unsafe extern "C" fn render_trampoline<
1478 P: IsA<GLArea>,
1479 F: Fn(&P, &gdk::GLContext) -> glib::Propagation + 'static,
1480 >(
1481 this: *mut ffi::GtkGLArea,
1482 context: *mut gdk::ffi::GdkGLContext,
1483 f: glib::ffi::gpointer,
1484 ) -> glib::ffi::gboolean {
1485 let f: &F = &*(f as *const F);
1486 f(
1487 GLArea::from_glib_borrow(this).unsafe_cast_ref(),
1488 &from_glib_borrow(context),
1489 )
1490 .into_glib()
1491 }
1492 unsafe {
1493 let f: Box_<F> = Box_::new(f);
1494 connect_raw(
1495 self.as_ptr() as *mut _,
1496 c"render".as_ptr() as *const _,
1497 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1498 render_trampoline::<Self, F> as *const (),
1499 )),
1500 Box_::into_raw(f),
1501 )
1502 }
1503 }
1504
1505 /// Emitted once when the widget is realized, and then each time the widget
1506 /// is changed while realized.
1507 ///
1508 /// This is useful in order to keep GL state up to date with the widget size,
1509 /// like for instance camera properties which may depend on the width/height
1510 /// ratio.
1511 ///
1512 /// The GL context for the area is guaranteed to be current when this signal
1513 /// is emitted.
1514 ///
1515 /// The default handler sets up the GL viewport.
1516 /// ## `width`
1517 /// the width of the viewport
1518 /// ## `height`
1519 /// the height of the viewport
1520 #[doc(alias = "resize")]
1521 fn connect_resize<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
1522 unsafe extern "C" fn resize_trampoline<P: IsA<GLArea>, F: Fn(&P, i32, i32) + 'static>(
1523 this: *mut ffi::GtkGLArea,
1524 width: std::ffi::c_int,
1525 height: std::ffi::c_int,
1526 f: glib::ffi::gpointer,
1527 ) {
1528 let f: &F = &*(f as *const F);
1529 f(
1530 GLArea::from_glib_borrow(this).unsafe_cast_ref(),
1531 width,
1532 height,
1533 )
1534 }
1535 unsafe {
1536 let f: Box_<F> = Box_::new(f);
1537 connect_raw(
1538 self.as_ptr() as *mut _,
1539 c"resize".as_ptr() as *const _,
1540 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1541 resize_trampoline::<Self, F> as *const (),
1542 )),
1543 Box_::into_raw(f),
1544 )
1545 }
1546 }
1547
1548 #[cfg(feature = "v4_12")]
1549 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1550 #[doc(alias = "allowed-apis")]
1551 fn connect_allowed_apis_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1552 unsafe extern "C" fn notify_allowed_apis_trampoline<P: IsA<GLArea>, F: Fn(&P) + 'static>(
1553 this: *mut ffi::GtkGLArea,
1554 _param_spec: glib::ffi::gpointer,
1555 f: glib::ffi::gpointer,
1556 ) {
1557 let f: &F = &*(f as *const F);
1558 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1559 }
1560 unsafe {
1561 let f: Box_<F> = Box_::new(f);
1562 connect_raw(
1563 self.as_ptr() as *mut _,
1564 c"notify::allowed-apis".as_ptr() as *const _,
1565 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1566 notify_allowed_apis_trampoline::<Self, F> as *const (),
1567 )),
1568 Box_::into_raw(f),
1569 )
1570 }
1571 }
1572
1573 #[cfg(feature = "v4_12")]
1574 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1575 #[doc(alias = "api")]
1576 fn connect_api_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1577 unsafe extern "C" fn notify_api_trampoline<P: IsA<GLArea>, F: Fn(&P) + 'static>(
1578 this: *mut ffi::GtkGLArea,
1579 _param_spec: glib::ffi::gpointer,
1580 f: glib::ffi::gpointer,
1581 ) {
1582 let f: &F = &*(f as *const F);
1583 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1584 }
1585 unsafe {
1586 let f: Box_<F> = Box_::new(f);
1587 connect_raw(
1588 self.as_ptr() as *mut _,
1589 c"notify::api".as_ptr() as *const _,
1590 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1591 notify_api_trampoline::<Self, F> as *const (),
1592 )),
1593 Box_::into_raw(f),
1594 )
1595 }
1596 }
1597
1598 #[doc(alias = "auto-render")]
1599 fn connect_auto_render_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1600 unsafe extern "C" fn notify_auto_render_trampoline<P: IsA<GLArea>, F: Fn(&P) + 'static>(
1601 this: *mut ffi::GtkGLArea,
1602 _param_spec: glib::ffi::gpointer,
1603 f: glib::ffi::gpointer,
1604 ) {
1605 let f: &F = &*(f as *const F);
1606 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1607 }
1608 unsafe {
1609 let f: Box_<F> = Box_::new(f);
1610 connect_raw(
1611 self.as_ptr() as *mut _,
1612 c"notify::auto-render".as_ptr() as *const _,
1613 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1614 notify_auto_render_trampoline::<Self, F> as *const (),
1615 )),
1616 Box_::into_raw(f),
1617 )
1618 }
1619 }
1620
1621 #[doc(alias = "context")]
1622 fn connect_context_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1623 unsafe extern "C" fn notify_context_trampoline<P: IsA<GLArea>, F: Fn(&P) + 'static>(
1624 this: *mut ffi::GtkGLArea,
1625 _param_spec: glib::ffi::gpointer,
1626 f: glib::ffi::gpointer,
1627 ) {
1628 let f: &F = &*(f as *const F);
1629 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1630 }
1631 unsafe {
1632 let f: Box_<F> = Box_::new(f);
1633 connect_raw(
1634 self.as_ptr() as *mut _,
1635 c"notify::context".as_ptr() as *const _,
1636 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1637 notify_context_trampoline::<Self, F> as *const (),
1638 )),
1639 Box_::into_raw(f),
1640 )
1641 }
1642 }
1643
1644 #[doc(alias = "has-depth-buffer")]
1645 fn connect_has_depth_buffer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1646 unsafe extern "C" fn notify_has_depth_buffer_trampoline<
1647 P: IsA<GLArea>,
1648 F: Fn(&P) + 'static,
1649 >(
1650 this: *mut ffi::GtkGLArea,
1651 _param_spec: glib::ffi::gpointer,
1652 f: glib::ffi::gpointer,
1653 ) {
1654 let f: &F = &*(f as *const F);
1655 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1656 }
1657 unsafe {
1658 let f: Box_<F> = Box_::new(f);
1659 connect_raw(
1660 self.as_ptr() as *mut _,
1661 c"notify::has-depth-buffer".as_ptr() as *const _,
1662 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1663 notify_has_depth_buffer_trampoline::<Self, F> as *const (),
1664 )),
1665 Box_::into_raw(f),
1666 )
1667 }
1668 }
1669
1670 #[doc(alias = "has-stencil-buffer")]
1671 fn connect_has_stencil_buffer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1672 unsafe extern "C" fn notify_has_stencil_buffer_trampoline<
1673 P: IsA<GLArea>,
1674 F: Fn(&P) + 'static,
1675 >(
1676 this: *mut ffi::GtkGLArea,
1677 _param_spec: glib::ffi::gpointer,
1678 f: glib::ffi::gpointer,
1679 ) {
1680 let f: &F = &*(f as *const F);
1681 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1682 }
1683 unsafe {
1684 let f: Box_<F> = Box_::new(f);
1685 connect_raw(
1686 self.as_ptr() as *mut _,
1687 c"notify::has-stencil-buffer".as_ptr() as *const _,
1688 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1689 notify_has_stencil_buffer_trampoline::<Self, F> as *const (),
1690 )),
1691 Box_::into_raw(f),
1692 )
1693 }
1694 }
1695
1696 #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
1697 #[doc(alias = "use-es")]
1698 fn connect_use_es_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1699 unsafe extern "C" fn notify_use_es_trampoline<P: IsA<GLArea>, F: Fn(&P) + 'static>(
1700 this: *mut ffi::GtkGLArea,
1701 _param_spec: glib::ffi::gpointer,
1702 f: glib::ffi::gpointer,
1703 ) {
1704 let f: &F = &*(f as *const F);
1705 f(GLArea::from_glib_borrow(this).unsafe_cast_ref())
1706 }
1707 unsafe {
1708 let f: Box_<F> = Box_::new(f);
1709 connect_raw(
1710 self.as_ptr() as *mut _,
1711 c"notify::use-es".as_ptr() as *const _,
1712 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1713 notify_use_es_trampoline::<Self, F> as *const (),
1714 )),
1715 Box_::into_raw(f),
1716 )
1717 }
1718 }
1719}
1720
1721impl<O: IsA<GLArea>> GLAreaExt for O {}