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