gtk4/auto/video.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_14")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
7use crate::GraphicsOffloadEnabled;
8use crate::{
9 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager,
10 MediaStream, Overflow, Widget,
11};
12use glib::{
13 prelude::*,
14 signal::{connect_raw, SignalHandlerId},
15 translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20 /// Shows a [`MediaStream`][crate::MediaStream] with media controls.
21 ///
22 /// <picture>
23 /// <source srcset="video-dark.png" media="(prefers-color-scheme: dark)">
24 /// <img alt="An example GtkVideo" src="video.png">
25 /// </picture>
26 ///
27 /// The controls are available separately as [`MediaControls`][crate::MediaControls].
28 /// If you just want to display a video without controls, you can treat it
29 /// like any other paintable and for example put it into a [`Picture`][crate::Picture].
30 ///
31 /// [`Video`][crate::Video] aims to cover use cases such as previews, embedded animations,
32 /// etc. It supports autoplay, looping, and simple media controls. It does
33 /// not have support for video overlays, multichannel audio, device
34 /// selection, or input. If you are writing a full-fledged video player,
35 /// you may want to use the [`gdk::Paintable`][crate::gdk::Paintable] API and a media framework
36 /// such as Gstreamer directly.
37 ///
38 /// ## Properties
39 ///
40 ///
41 /// #### `autoplay`
42 /// If the video should automatically begin playing.
43 ///
44 /// Readable | Writeable
45 ///
46 ///
47 /// #### `file`
48 /// The file played by this video if the video is playing a file.
49 ///
50 /// Readable | Writeable
51 ///
52 ///
53 /// #### `graphics-offload`
54 /// Whether to enable graphics offload.
55 ///
56 /// Readable | Writeable
57 ///
58 ///
59 /// #### `loop`
60 /// If new media files should be set to loop.
61 ///
62 /// Readable | Writeable
63 ///
64 ///
65 /// #### `media-stream`
66 /// The media-stream played
67 ///
68 /// Readable | Writeable
69 /// <details><summary><h4>Widget</h4></summary>
70 ///
71 ///
72 /// #### `can-focus`
73 /// Whether the widget or any of its descendents can accept
74 /// the input focus.
75 ///
76 /// This property is meant to be set by widget implementations,
77 /// typically in their instance init function.
78 ///
79 /// Readable | Writeable
80 ///
81 ///
82 /// #### `can-target`
83 /// Whether the widget can receive pointer events.
84 ///
85 /// Readable | Writeable
86 ///
87 ///
88 /// #### `css-classes`
89 /// A list of css classes applied to this widget.
90 ///
91 /// Readable | Writeable
92 ///
93 ///
94 /// #### `css-name`
95 /// The name of this widget in the CSS tree.
96 ///
97 /// This property is meant to be set by widget implementations,
98 /// typically in their instance init function.
99 ///
100 /// Readable | Writeable | Construct Only
101 ///
102 ///
103 /// #### `cursor`
104 /// The cursor used by @widget.
105 ///
106 /// Readable | Writeable
107 ///
108 ///
109 /// #### `focus-on-click`
110 /// Whether the widget should grab focus when it is clicked with the mouse.
111 ///
112 /// This property is only relevant for widgets that can take focus.
113 ///
114 /// Readable | Writeable
115 ///
116 ///
117 /// #### `focusable`
118 /// Whether this widget itself will accept the input focus.
119 ///
120 /// Readable | Writeable
121 ///
122 ///
123 /// #### `halign`
124 /// How to distribute horizontal space if widget gets extra space.
125 ///
126 /// Readable | Writeable
127 ///
128 ///
129 /// #### `has-default`
130 /// Whether the widget is the default widget.
131 ///
132 /// Readable
133 ///
134 ///
135 /// #### `has-focus`
136 /// Whether the widget has the input focus.
137 ///
138 /// Readable
139 ///
140 ///
141 /// #### `has-tooltip`
142 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
143 /// signal on @widget.
144 ///
145 /// A true value indicates that @widget can have a tooltip, in this case
146 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
147 /// determine whether it will provide a tooltip or not.
148 ///
149 /// Readable | Writeable
150 ///
151 ///
152 /// #### `height-request`
153 /// Overrides for height request of the widget.
154 ///
155 /// If this is -1, the natural request will be used.
156 ///
157 /// Readable | Writeable
158 ///
159 ///
160 /// #### `hexpand`
161 /// Whether to expand horizontally.
162 ///
163 /// Readable | Writeable
164 ///
165 ///
166 /// #### `hexpand-set`
167 /// Whether to use the `hexpand` property.
168 ///
169 /// Readable | Writeable
170 ///
171 ///
172 /// #### `layout-manager`
173 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
174 /// the preferred size of the widget, and allocate its children.
175 ///
176 /// This property is meant to be set by widget implementations,
177 /// typically in their instance init function.
178 ///
179 /// Readable | Writeable
180 ///
181 ///
182 /// #### `limit-events`
183 /// Makes this widget act like a modal dialog, with respect to
184 /// event delivery.
185 ///
186 /// Global event controllers will not handle events with targets
187 /// inside the widget, unless they are set up to ignore propagation
188 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
189 ///
190 /// Readable | Writeable
191 ///
192 ///
193 /// #### `margin-bottom`
194 /// Margin on bottom side of widget.
195 ///
196 /// This property adds margin outside of the widget's normal size
197 /// request, the margin will be added in addition to the size from
198 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
199 ///
200 /// Readable | Writeable
201 ///
202 ///
203 /// #### `margin-end`
204 /// Margin on end of widget, horizontally.
205 ///
206 /// This property supports left-to-right and right-to-left text
207 /// directions.
208 ///
209 /// This property adds margin outside of the widget's normal size
210 /// request, the margin will be added in addition to the size from
211 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
212 ///
213 /// Readable | Writeable
214 ///
215 ///
216 /// #### `margin-start`
217 /// Margin on start of widget, horizontally.
218 ///
219 /// This property supports left-to-right and right-to-left text
220 /// directions.
221 ///
222 /// This property adds margin outside of the widget's normal size
223 /// request, the margin will be added in addition to the size from
224 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
225 ///
226 /// Readable | Writeable
227 ///
228 ///
229 /// #### `margin-top`
230 /// Margin on top side of widget.
231 ///
232 /// This property adds margin outside of the widget's normal size
233 /// request, the margin will be added in addition to the size from
234 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
235 ///
236 /// Readable | Writeable
237 ///
238 ///
239 /// #### `name`
240 /// The name of the widget.
241 ///
242 /// Readable | Writeable
243 ///
244 ///
245 /// #### `opacity`
246 /// The requested opacity of the widget.
247 ///
248 /// Readable | Writeable
249 ///
250 ///
251 /// #### `overflow`
252 /// How content outside the widget's content area is treated.
253 ///
254 /// This property is meant to be set by widget implementations,
255 /// typically in their instance init function.
256 ///
257 /// Readable | Writeable
258 ///
259 ///
260 /// #### `parent`
261 /// The parent widget of this widget.
262 ///
263 /// Readable
264 ///
265 ///
266 /// #### `receives-default`
267 /// Whether the widget will receive the default action when it is focused.
268 ///
269 /// Readable | Writeable
270 ///
271 ///
272 /// #### `root`
273 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
274 ///
275 /// This will be `NULL` if the widget is not contained in a root widget.
276 ///
277 /// Readable
278 ///
279 ///
280 /// #### `scale-factor`
281 /// The scale factor of the widget.
282 ///
283 /// Readable
284 ///
285 ///
286 /// #### `sensitive`
287 /// Whether the widget responds to input.
288 ///
289 /// Readable | Writeable
290 ///
291 ///
292 /// #### `tooltip-markup`
293 /// Sets the text of tooltip to be the given string, which is marked up
294 /// with Pango markup.
295 ///
296 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
297 ///
298 /// This is a convenience property which will take care of getting the
299 /// tooltip shown if the given string is not `NULL`:
300 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
301 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
302 /// the default signal handler.
303 ///
304 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
305 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
306 ///
307 /// Readable | Writeable
308 ///
309 ///
310 /// #### `tooltip-text`
311 /// Sets the text of tooltip to be the given string.
312 ///
313 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
314 ///
315 /// This is a convenience property which will take care of getting the
316 /// tooltip shown if the given string is not `NULL`:
317 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
318 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
319 /// the default signal handler.
320 ///
321 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
322 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
323 ///
324 /// Readable | Writeable
325 ///
326 ///
327 /// #### `valign`
328 /// How to distribute vertical space if widget gets extra space.
329 ///
330 /// Readable | Writeable
331 ///
332 ///
333 /// #### `vexpand`
334 /// Whether to expand vertically.
335 ///
336 /// Readable | Writeable
337 ///
338 ///
339 /// #### `vexpand-set`
340 /// Whether to use the `vexpand` property.
341 ///
342 /// Readable | Writeable
343 ///
344 ///
345 /// #### `visible`
346 /// Whether the widget is visible.
347 ///
348 /// Readable | Writeable
349 ///
350 ///
351 /// #### `width-request`
352 /// Overrides for width request of the widget.
353 ///
354 /// If this is -1, the natural request will be used.
355 ///
356 /// Readable | Writeable
357 /// </details>
358 /// <details><summary><h4>Accessible</h4></summary>
359 ///
360 ///
361 /// #### `accessible-role`
362 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
363 ///
364 /// The accessible role cannot be changed once set.
365 ///
366 /// Readable | Writeable
367 /// </details>
368 ///
369 /// # Implements
370 ///
371 /// [`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]
372 #[doc(alias = "GtkVideo")]
373 pub struct Video(Object<ffi::GtkVideo, ffi::GtkVideoClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
374
375 match fn {
376 type_ => || ffi::gtk_video_get_type(),
377 }
378}
379
380impl Video {
381 /// Creates a new empty [`Video`][crate::Video].
382 ///
383 /// # Returns
384 ///
385 /// a new [`Video`][crate::Video]
386 #[doc(alias = "gtk_video_new")]
387 pub fn new() -> Video {
388 assert_initialized_main_thread!();
389 unsafe { Widget::from_glib_none(ffi::gtk_video_new()).unsafe_cast() }
390 }
391
392 /// Creates a [`Video`][crate::Video] to play back the given @file.
393 /// ## `file`
394 /// a `GFile`
395 ///
396 /// # Returns
397 ///
398 /// a new [`Video`][crate::Video]
399 #[doc(alias = "gtk_video_new_for_file")]
400 #[doc(alias = "new_for_file")]
401 pub fn for_file(file: Option<&impl IsA<gio::File>>) -> Video {
402 assert_initialized_main_thread!();
403 unsafe {
404 Widget::from_glib_none(ffi::gtk_video_new_for_file(
405 file.map(|p| p.as_ref()).to_glib_none().0,
406 ))
407 .unsafe_cast()
408 }
409 }
410
411 /// Creates a [`Video`][crate::Video] to play back the given @filename.
412 ///
413 /// This is a utility function that calls [`for_file()`][Self::for_file()],
414 /// See that function for details.
415 /// ## `filename`
416 /// filename to play back
417 ///
418 /// # Returns
419 ///
420 /// a new [`Video`][crate::Video]
421 #[doc(alias = "gtk_video_new_for_filename")]
422 #[doc(alias = "new_for_filename")]
423 pub fn for_filename(filename: Option<impl AsRef<std::path::Path>>) -> Video {
424 assert_initialized_main_thread!();
425 unsafe {
426 Widget::from_glib_none(ffi::gtk_video_new_for_filename(
427 filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
428 ))
429 .unsafe_cast()
430 }
431 }
432
433 /// Creates a [`Video`][crate::Video] to play back the given @stream.
434 /// ## `stream`
435 /// a [`MediaStream`][crate::MediaStream]
436 ///
437 /// # Returns
438 ///
439 /// a new [`Video`][crate::Video]
440 #[doc(alias = "gtk_video_new_for_media_stream")]
441 #[doc(alias = "new_for_media_stream")]
442 pub fn for_media_stream(stream: Option<&impl IsA<MediaStream>>) -> Video {
443 assert_initialized_main_thread!();
444 unsafe {
445 Widget::from_glib_none(ffi::gtk_video_new_for_media_stream(
446 stream.map(|p| p.as_ref()).to_glib_none().0,
447 ))
448 .unsafe_cast()
449 }
450 }
451
452 /// Creates a [`Video`][crate::Video] to play back the resource at the
453 /// given @resource_path.
454 ///
455 /// This is a utility function that calls [`for_file()`][Self::for_file()].
456 /// ## `resource_path`
457 /// resource path to play back
458 ///
459 /// # Returns
460 ///
461 /// a new [`Video`][crate::Video]
462 #[doc(alias = "gtk_video_new_for_resource")]
463 #[doc(alias = "new_for_resource")]
464 pub fn for_resource(resource_path: Option<&str>) -> Video {
465 assert_initialized_main_thread!();
466 unsafe {
467 Widget::from_glib_none(ffi::gtk_video_new_for_resource(
468 resource_path.to_glib_none().0,
469 ))
470 .unsafe_cast()
471 }
472 }
473
474 // rustdoc-stripper-ignore-next
475 /// Creates a new builder-pattern struct instance to construct [`Video`] objects.
476 ///
477 /// This method returns an instance of [`VideoBuilder`](crate::builders::VideoBuilder) which can be used to create [`Video`] objects.
478 pub fn builder() -> VideoBuilder {
479 VideoBuilder::new()
480 }
481
482 /// Returns [`true`] if videos have been set to loop.
483 ///
484 /// # Returns
485 ///
486 /// [`true`] if streams should autoplay
487 #[doc(alias = "gtk_video_get_autoplay")]
488 #[doc(alias = "get_autoplay")]
489 #[doc(alias = "autoplay")]
490 pub fn is_autoplay(&self) -> bool {
491 unsafe { from_glib(ffi::gtk_video_get_autoplay(self.to_glib_none().0)) }
492 }
493
494 /// Gets the file played by @self or [`None`] if not playing back
495 /// a file.
496 ///
497 /// # Returns
498 ///
499 /// The file played by @self
500 #[doc(alias = "gtk_video_get_file")]
501 #[doc(alias = "get_file")]
502 pub fn file(&self) -> Option<gio::File> {
503 unsafe { from_glib_none(ffi::gtk_video_get_file(self.to_glib_none().0)) }
504 }
505
506 /// Returns whether graphics offload is enabled.
507 ///
508 /// See [`GraphicsOffload`][crate::GraphicsOffload] for more information on graphics offload.
509 ///
510 /// # Returns
511 ///
512 /// the graphics offload status
513 #[cfg(feature = "v4_14")]
514 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
515 #[doc(alias = "gtk_video_get_graphics_offload")]
516 #[doc(alias = "get_graphics_offload")]
517 #[doc(alias = "graphics-offload")]
518 pub fn graphics_offload(&self) -> GraphicsOffloadEnabled {
519 unsafe { from_glib(ffi::gtk_video_get_graphics_offload(self.to_glib_none().0)) }
520 }
521
522 /// Returns [`true`] if videos have been set to loop.
523 ///
524 /// # Returns
525 ///
526 /// [`true`] if streams should loop
527 #[doc(alias = "gtk_video_get_loop")]
528 #[doc(alias = "get_loop")]
529 #[doc(alias = "loop")]
530 pub fn is_loop(&self) -> bool {
531 unsafe { from_glib(ffi::gtk_video_get_loop(self.to_glib_none().0)) }
532 }
533
534 /// Gets the media stream managed by @self or [`None`] if none.
535 ///
536 /// # Returns
537 ///
538 /// The media stream managed by @self
539 #[doc(alias = "gtk_video_get_media_stream")]
540 #[doc(alias = "get_media_stream")]
541 #[doc(alias = "media-stream")]
542 pub fn media_stream(&self) -> Option<MediaStream> {
543 unsafe { from_glib_none(ffi::gtk_video_get_media_stream(self.to_glib_none().0)) }
544 }
545
546 /// Sets whether @self automatically starts playback when it
547 /// becomes visible or when a new file gets loaded.
548 /// ## `autoplay`
549 /// whether media streams should autoplay
550 #[doc(alias = "gtk_video_set_autoplay")]
551 #[doc(alias = "autoplay")]
552 pub fn set_autoplay(&self, autoplay: bool) {
553 unsafe {
554 ffi::gtk_video_set_autoplay(self.to_glib_none().0, autoplay.into_glib());
555 }
556 }
557
558 /// Makes @self play the given @file.
559 /// ## `file`
560 /// the file to play
561 #[doc(alias = "gtk_video_set_file")]
562 #[doc(alias = "file")]
563 pub fn set_file(&self, file: Option<&impl IsA<gio::File>>) {
564 unsafe {
565 ffi::gtk_video_set_file(
566 self.to_glib_none().0,
567 file.map(|p| p.as_ref()).to_glib_none().0,
568 );
569 }
570 }
571
572 /// Makes @self play the given @filename.
573 ///
574 /// This is a utility function that calls gtk_video_set_file(),
575 /// ## `filename`
576 /// the filename to play
577 #[doc(alias = "gtk_video_set_filename")]
578 pub fn set_filename(&self, filename: Option<impl AsRef<std::path::Path>>) {
579 unsafe {
580 ffi::gtk_video_set_filename(
581 self.to_glib_none().0,
582 filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
583 );
584 }
585 }
586
587 /// Sets whether to enable graphics offload.
588 ///
589 /// See [`GraphicsOffload`][crate::GraphicsOffload] for more information on graphics offload.
590 /// ## `enabled`
591 /// the new graphics offload status
592 #[cfg(feature = "v4_14")]
593 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
594 #[doc(alias = "gtk_video_set_graphics_offload")]
595 #[doc(alias = "graphics-offload")]
596 pub fn set_graphics_offload(&self, enabled: GraphicsOffloadEnabled) {
597 unsafe {
598 ffi::gtk_video_set_graphics_offload(self.to_glib_none().0, enabled.into_glib());
599 }
600 }
601
602 /// Sets whether new files loaded by @self should be set to loop.
603 /// ## `loop_`
604 /// whether media streams should loop
605 #[doc(alias = "gtk_video_set_loop")]
606 #[doc(alias = "loop")]
607 pub fn set_loop(&self, loop_: bool) {
608 unsafe {
609 ffi::gtk_video_set_loop(self.to_glib_none().0, loop_.into_glib());
610 }
611 }
612
613 /// Sets the media stream to be played back.
614 ///
615 /// @self will take full control of managing the media stream. If you
616 /// want to manage a media stream yourself, consider using a
617 /// [`Picture`][crate::Picture] for display.
618 ///
619 /// If you want to display a file, consider using [`set_file()`][Self::set_file()]
620 /// instead.
621 /// ## `stream`
622 /// The media stream to play or [`None`] to unset
623 #[doc(alias = "gtk_video_set_media_stream")]
624 #[doc(alias = "media-stream")]
625 pub fn set_media_stream(&self, stream: Option<&impl IsA<MediaStream>>) {
626 unsafe {
627 ffi::gtk_video_set_media_stream(
628 self.to_glib_none().0,
629 stream.map(|p| p.as_ref()).to_glib_none().0,
630 );
631 }
632 }
633
634 /// Makes @self play the resource at the given @resource_path.
635 ///
636 /// This is a utility function that calls [`set_file()`][Self::set_file()].
637 /// ## `resource_path`
638 /// the resource to set
639 #[doc(alias = "gtk_video_set_resource")]
640 pub fn set_resource(&self, resource_path: Option<&str>) {
641 unsafe {
642 ffi::gtk_video_set_resource(self.to_glib_none().0, resource_path.to_glib_none().0);
643 }
644 }
645
646 #[doc(alias = "autoplay")]
647 pub fn connect_autoplay_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
648 unsafe extern "C" fn notify_autoplay_trampoline<F: Fn(&Video) + 'static>(
649 this: *mut ffi::GtkVideo,
650 _param_spec: glib::ffi::gpointer,
651 f: glib::ffi::gpointer,
652 ) {
653 let f: &F = &*(f as *const F);
654 f(&from_glib_borrow(this))
655 }
656 unsafe {
657 let f: Box_<F> = Box_::new(f);
658 connect_raw(
659 self.as_ptr() as *mut _,
660 c"notify::autoplay".as_ptr() as *const _,
661 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
662 notify_autoplay_trampoline::<F> as *const (),
663 )),
664 Box_::into_raw(f),
665 )
666 }
667 }
668
669 #[doc(alias = "file")]
670 pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
671 unsafe extern "C" fn notify_file_trampoline<F: Fn(&Video) + 'static>(
672 this: *mut ffi::GtkVideo,
673 _param_spec: glib::ffi::gpointer,
674 f: glib::ffi::gpointer,
675 ) {
676 let f: &F = &*(f as *const F);
677 f(&from_glib_borrow(this))
678 }
679 unsafe {
680 let f: Box_<F> = Box_::new(f);
681 connect_raw(
682 self.as_ptr() as *mut _,
683 c"notify::file".as_ptr() as *const _,
684 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
685 notify_file_trampoline::<F> as *const (),
686 )),
687 Box_::into_raw(f),
688 )
689 }
690 }
691
692 #[cfg(feature = "v4_14")]
693 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
694 #[doc(alias = "graphics-offload")]
695 pub fn connect_graphics_offload_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
696 unsafe extern "C" fn notify_graphics_offload_trampoline<F: Fn(&Video) + 'static>(
697 this: *mut ffi::GtkVideo,
698 _param_spec: glib::ffi::gpointer,
699 f: glib::ffi::gpointer,
700 ) {
701 let f: &F = &*(f as *const F);
702 f(&from_glib_borrow(this))
703 }
704 unsafe {
705 let f: Box_<F> = Box_::new(f);
706 connect_raw(
707 self.as_ptr() as *mut _,
708 c"notify::graphics-offload".as_ptr() as *const _,
709 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
710 notify_graphics_offload_trampoline::<F> as *const (),
711 )),
712 Box_::into_raw(f),
713 )
714 }
715 }
716
717 #[doc(alias = "loop")]
718 pub fn connect_loop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
719 unsafe extern "C" fn notify_loop_trampoline<F: Fn(&Video) + 'static>(
720 this: *mut ffi::GtkVideo,
721 _param_spec: glib::ffi::gpointer,
722 f: glib::ffi::gpointer,
723 ) {
724 let f: &F = &*(f as *const F);
725 f(&from_glib_borrow(this))
726 }
727 unsafe {
728 let f: Box_<F> = Box_::new(f);
729 connect_raw(
730 self.as_ptr() as *mut _,
731 c"notify::loop".as_ptr() as *const _,
732 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
733 notify_loop_trampoline::<F> as *const (),
734 )),
735 Box_::into_raw(f),
736 )
737 }
738 }
739
740 #[doc(alias = "media-stream")]
741 pub fn connect_media_stream_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
742 unsafe extern "C" fn notify_media_stream_trampoline<F: Fn(&Video) + 'static>(
743 this: *mut ffi::GtkVideo,
744 _param_spec: glib::ffi::gpointer,
745 f: glib::ffi::gpointer,
746 ) {
747 let f: &F = &*(f as *const F);
748 f(&from_glib_borrow(this))
749 }
750 unsafe {
751 let f: Box_<F> = Box_::new(f);
752 connect_raw(
753 self.as_ptr() as *mut _,
754 c"notify::media-stream".as_ptr() as *const _,
755 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
756 notify_media_stream_trampoline::<F> as *const (),
757 )),
758 Box_::into_raw(f),
759 )
760 }
761 }
762}
763
764impl Default for Video {
765 fn default() -> Self {
766 Self::new()
767 }
768}
769
770// rustdoc-stripper-ignore-next
771/// A [builder-pattern] type to construct [`Video`] objects.
772///
773/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
774#[must_use = "The builder must be built to be used"]
775pub struct VideoBuilder {
776 builder: glib::object::ObjectBuilder<'static, Video>,
777}
778
779impl VideoBuilder {
780 fn new() -> Self {
781 Self {
782 builder: glib::object::Object::builder(),
783 }
784 }
785
786 /// If the video should automatically begin playing.
787 pub fn autoplay(self, autoplay: bool) -> Self {
788 Self {
789 builder: self.builder.property("autoplay", autoplay),
790 }
791 }
792
793 /// The file played by this video if the video is playing a file.
794 pub fn file(self, file: &impl IsA<gio::File>) -> Self {
795 Self {
796 builder: self.builder.property("file", file.clone().upcast()),
797 }
798 }
799
800 /// Whether to enable graphics offload.
801 #[cfg(feature = "v4_14")]
802 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
803 pub fn graphics_offload(self, graphics_offload: GraphicsOffloadEnabled) -> Self {
804 Self {
805 builder: self.builder.property("graphics-offload", graphics_offload),
806 }
807 }
808
809 pub fn loop_(self, loop_: bool) -> Self {
810 Self {
811 builder: self.builder.property("loop", loop_),
812 }
813 }
814
815 /// The media-stream played
816 pub fn media_stream(self, media_stream: &impl IsA<MediaStream>) -> Self {
817 Self {
818 builder: self
819 .builder
820 .property("media-stream", media_stream.clone().upcast()),
821 }
822 }
823
824 /// Whether the widget or any of its descendents can accept
825 /// the input focus.
826 ///
827 /// This property is meant to be set by widget implementations,
828 /// typically in their instance init function.
829 pub fn can_focus(self, can_focus: bool) -> Self {
830 Self {
831 builder: self.builder.property("can-focus", can_focus),
832 }
833 }
834
835 /// Whether the widget can receive pointer events.
836 pub fn can_target(self, can_target: bool) -> Self {
837 Self {
838 builder: self.builder.property("can-target", can_target),
839 }
840 }
841
842 /// A list of css classes applied to this widget.
843 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
844 Self {
845 builder: self.builder.property("css-classes", css_classes.into()),
846 }
847 }
848
849 /// The name of this widget in the CSS tree.
850 ///
851 /// This property is meant to be set by widget implementations,
852 /// typically in their instance init function.
853 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
854 Self {
855 builder: self.builder.property("css-name", css_name.into()),
856 }
857 }
858
859 /// The cursor used by @widget.
860 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
861 Self {
862 builder: self.builder.property("cursor", cursor.clone()),
863 }
864 }
865
866 /// Whether the widget should grab focus when it is clicked with the mouse.
867 ///
868 /// This property is only relevant for widgets that can take focus.
869 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
870 Self {
871 builder: self.builder.property("focus-on-click", focus_on_click),
872 }
873 }
874
875 /// Whether this widget itself will accept the input focus.
876 pub fn focusable(self, focusable: bool) -> Self {
877 Self {
878 builder: self.builder.property("focusable", focusable),
879 }
880 }
881
882 /// How to distribute horizontal space if widget gets extra space.
883 pub fn halign(self, halign: Align) -> Self {
884 Self {
885 builder: self.builder.property("halign", halign),
886 }
887 }
888
889 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
890 /// signal on @widget.
891 ///
892 /// A true value indicates that @widget can have a tooltip, in this case
893 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
894 /// determine whether it will provide a tooltip or not.
895 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
896 Self {
897 builder: self.builder.property("has-tooltip", has_tooltip),
898 }
899 }
900
901 /// Overrides for height request of the widget.
902 ///
903 /// If this is -1, the natural request will be used.
904 pub fn height_request(self, height_request: i32) -> Self {
905 Self {
906 builder: self.builder.property("height-request", height_request),
907 }
908 }
909
910 /// Whether to expand horizontally.
911 pub fn hexpand(self, hexpand: bool) -> Self {
912 Self {
913 builder: self.builder.property("hexpand", hexpand),
914 }
915 }
916
917 /// Whether to use the `hexpand` property.
918 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
919 Self {
920 builder: self.builder.property("hexpand-set", hexpand_set),
921 }
922 }
923
924 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
925 /// the preferred size of the widget, and allocate its children.
926 ///
927 /// This property is meant to be set by widget implementations,
928 /// typically in their instance init function.
929 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
930 Self {
931 builder: self
932 .builder
933 .property("layout-manager", layout_manager.clone().upcast()),
934 }
935 }
936
937 /// Makes this widget act like a modal dialog, with respect to
938 /// event delivery.
939 ///
940 /// Global event controllers will not handle events with targets
941 /// inside the widget, unless they are set up to ignore propagation
942 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
943 #[cfg(feature = "v4_18")]
944 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
945 pub fn limit_events(self, limit_events: bool) -> Self {
946 Self {
947 builder: self.builder.property("limit-events", limit_events),
948 }
949 }
950
951 /// Margin on bottom side of widget.
952 ///
953 /// This property adds margin outside of the widget's normal size
954 /// request, the margin will be added in addition to the size from
955 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
956 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
957 Self {
958 builder: self.builder.property("margin-bottom", margin_bottom),
959 }
960 }
961
962 /// Margin on end of widget, horizontally.
963 ///
964 /// This property supports left-to-right and right-to-left text
965 /// directions.
966 ///
967 /// This property adds margin outside of the widget's normal size
968 /// request, the margin will be added in addition to the size from
969 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
970 pub fn margin_end(self, margin_end: i32) -> Self {
971 Self {
972 builder: self.builder.property("margin-end", margin_end),
973 }
974 }
975
976 /// Margin on start of widget, horizontally.
977 ///
978 /// This property supports left-to-right and right-to-left text
979 /// directions.
980 ///
981 /// This property adds margin outside of the widget's normal size
982 /// request, the margin will be added in addition to the size from
983 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
984 pub fn margin_start(self, margin_start: i32) -> Self {
985 Self {
986 builder: self.builder.property("margin-start", margin_start),
987 }
988 }
989
990 /// Margin on top side of widget.
991 ///
992 /// This property adds margin outside of the widget's normal size
993 /// request, the margin will be added in addition to the size from
994 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
995 pub fn margin_top(self, margin_top: i32) -> Self {
996 Self {
997 builder: self.builder.property("margin-top", margin_top),
998 }
999 }
1000
1001 /// The name of the widget.
1002 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1003 Self {
1004 builder: self.builder.property("name", name.into()),
1005 }
1006 }
1007
1008 /// The requested opacity of the widget.
1009 pub fn opacity(self, opacity: f64) -> Self {
1010 Self {
1011 builder: self.builder.property("opacity", opacity),
1012 }
1013 }
1014
1015 /// How content outside the widget's content area is treated.
1016 ///
1017 /// This property is meant to be set by widget implementations,
1018 /// typically in their instance init function.
1019 pub fn overflow(self, overflow: Overflow) -> Self {
1020 Self {
1021 builder: self.builder.property("overflow", overflow),
1022 }
1023 }
1024
1025 /// Whether the widget will receive the default action when it is focused.
1026 pub fn receives_default(self, receives_default: bool) -> Self {
1027 Self {
1028 builder: self.builder.property("receives-default", receives_default),
1029 }
1030 }
1031
1032 /// Whether the widget responds to input.
1033 pub fn sensitive(self, sensitive: bool) -> Self {
1034 Self {
1035 builder: self.builder.property("sensitive", sensitive),
1036 }
1037 }
1038
1039 /// Sets the text of tooltip to be the given string, which is marked up
1040 /// with Pango markup.
1041 ///
1042 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1043 ///
1044 /// This is a convenience property which will take care of getting the
1045 /// tooltip shown if the given string is not `NULL`:
1046 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1047 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1048 /// the default signal handler.
1049 ///
1050 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1051 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1052 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1053 Self {
1054 builder: self
1055 .builder
1056 .property("tooltip-markup", tooltip_markup.into()),
1057 }
1058 }
1059
1060 /// Sets the text of tooltip to be the given string.
1061 ///
1062 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1063 ///
1064 /// This is a convenience property which will take care of getting the
1065 /// tooltip shown if the given string is not `NULL`:
1066 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1067 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1068 /// the default signal handler.
1069 ///
1070 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1071 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1072 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1073 Self {
1074 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1075 }
1076 }
1077
1078 /// How to distribute vertical space if widget gets extra space.
1079 pub fn valign(self, valign: Align) -> Self {
1080 Self {
1081 builder: self.builder.property("valign", valign),
1082 }
1083 }
1084
1085 /// Whether to expand vertically.
1086 pub fn vexpand(self, vexpand: bool) -> Self {
1087 Self {
1088 builder: self.builder.property("vexpand", vexpand),
1089 }
1090 }
1091
1092 /// Whether to use the `vexpand` property.
1093 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1094 Self {
1095 builder: self.builder.property("vexpand-set", vexpand_set),
1096 }
1097 }
1098
1099 /// Whether the widget is visible.
1100 pub fn visible(self, visible: bool) -> Self {
1101 Self {
1102 builder: self.builder.property("visible", visible),
1103 }
1104 }
1105
1106 /// Overrides for width request of the widget.
1107 ///
1108 /// If this is -1, the natural request will be used.
1109 pub fn width_request(self, width_request: i32) -> Self {
1110 Self {
1111 builder: self.builder.property("width-request", width_request),
1112 }
1113 }
1114
1115 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1116 ///
1117 /// The accessible role cannot be changed once set.
1118 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1119 Self {
1120 builder: self.builder.property("accessible-role", accessible_role),
1121 }
1122 }
1123
1124 // rustdoc-stripper-ignore-next
1125 /// Build the [`Video`].
1126 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1127 pub fn build(self) -> Video {
1128 assert_initialized_main_thread!();
1129 self.builder.build()
1130 }
1131}