1#[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 #[doc(alias = "GtkVideo")]
21 pub struct Video(Object<ffi::GtkVideo, ffi::GtkVideoClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
22
23 match fn {
24 type_ => || ffi::gtk_video_get_type(),
25 }
26}
27
28impl Video {
29 #[doc(alias = "gtk_video_new")]
30 pub fn new() -> Video {
31 assert_initialized_main_thread!();
32 unsafe { Widget::from_glib_none(ffi::gtk_video_new()).unsafe_cast() }
33 }
34
35 #[doc(alias = "gtk_video_new_for_file")]
36 #[doc(alias = "new_for_file")]
37 pub fn for_file(file: Option<&impl IsA<gio::File>>) -> Video {
38 assert_initialized_main_thread!();
39 unsafe {
40 Widget::from_glib_none(ffi::gtk_video_new_for_file(
41 file.map(|p| p.as_ref()).to_glib_none().0,
42 ))
43 .unsafe_cast()
44 }
45 }
46
47 #[doc(alias = "gtk_video_new_for_filename")]
48 #[doc(alias = "new_for_filename")]
49 pub fn for_filename(filename: Option<impl AsRef<std::path::Path>>) -> Video {
50 assert_initialized_main_thread!();
51 unsafe {
52 Widget::from_glib_none(ffi::gtk_video_new_for_filename(
53 filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
54 ))
55 .unsafe_cast()
56 }
57 }
58
59 #[doc(alias = "gtk_video_new_for_media_stream")]
60 #[doc(alias = "new_for_media_stream")]
61 pub fn for_media_stream(stream: Option<&impl IsA<MediaStream>>) -> Video {
62 assert_initialized_main_thread!();
63 unsafe {
64 Widget::from_glib_none(ffi::gtk_video_new_for_media_stream(
65 stream.map(|p| p.as_ref()).to_glib_none().0,
66 ))
67 .unsafe_cast()
68 }
69 }
70
71 #[doc(alias = "gtk_video_new_for_resource")]
72 #[doc(alias = "new_for_resource")]
73 pub fn for_resource(resource_path: Option<&str>) -> Video {
74 assert_initialized_main_thread!();
75 unsafe {
76 Widget::from_glib_none(ffi::gtk_video_new_for_resource(
77 resource_path.to_glib_none().0,
78 ))
79 .unsafe_cast()
80 }
81 }
82
83 pub fn builder() -> VideoBuilder {
88 VideoBuilder::new()
89 }
90
91 #[doc(alias = "gtk_video_get_autoplay")]
92 #[doc(alias = "get_autoplay")]
93 #[doc(alias = "autoplay")]
94 pub fn is_autoplay(&self) -> bool {
95 unsafe { from_glib(ffi::gtk_video_get_autoplay(self.to_glib_none().0)) }
96 }
97
98 #[doc(alias = "gtk_video_get_file")]
99 #[doc(alias = "get_file")]
100 pub fn file(&self) -> Option<gio::File> {
101 unsafe { from_glib_none(ffi::gtk_video_get_file(self.to_glib_none().0)) }
102 }
103
104 #[cfg(feature = "v4_14")]
105 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
106 #[doc(alias = "gtk_video_get_graphics_offload")]
107 #[doc(alias = "get_graphics_offload")]
108 #[doc(alias = "graphics-offload")]
109 pub fn graphics_offload(&self) -> GraphicsOffloadEnabled {
110 unsafe { from_glib(ffi::gtk_video_get_graphics_offload(self.to_glib_none().0)) }
111 }
112
113 #[doc(alias = "gtk_video_get_loop")]
114 #[doc(alias = "get_loop")]
115 #[doc(alias = "loop")]
116 pub fn is_loop(&self) -> bool {
117 unsafe { from_glib(ffi::gtk_video_get_loop(self.to_glib_none().0)) }
118 }
119
120 #[doc(alias = "gtk_video_get_media_stream")]
121 #[doc(alias = "get_media_stream")]
122 #[doc(alias = "media-stream")]
123 pub fn media_stream(&self) -> Option<MediaStream> {
124 unsafe { from_glib_none(ffi::gtk_video_get_media_stream(self.to_glib_none().0)) }
125 }
126
127 #[doc(alias = "gtk_video_set_autoplay")]
128 #[doc(alias = "autoplay")]
129 pub fn set_autoplay(&self, autoplay: bool) {
130 unsafe {
131 ffi::gtk_video_set_autoplay(self.to_glib_none().0, autoplay.into_glib());
132 }
133 }
134
135 #[doc(alias = "gtk_video_set_file")]
136 #[doc(alias = "file")]
137 pub fn set_file(&self, file: Option<&impl IsA<gio::File>>) {
138 unsafe {
139 ffi::gtk_video_set_file(
140 self.to_glib_none().0,
141 file.map(|p| p.as_ref()).to_glib_none().0,
142 );
143 }
144 }
145
146 #[doc(alias = "gtk_video_set_filename")]
147 pub fn set_filename(&self, filename: Option<impl AsRef<std::path::Path>>) {
148 unsafe {
149 ffi::gtk_video_set_filename(
150 self.to_glib_none().0,
151 filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
152 );
153 }
154 }
155
156 #[cfg(feature = "v4_14")]
157 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
158 #[doc(alias = "gtk_video_set_graphics_offload")]
159 #[doc(alias = "graphics-offload")]
160 pub fn set_graphics_offload(&self, enabled: GraphicsOffloadEnabled) {
161 unsafe {
162 ffi::gtk_video_set_graphics_offload(self.to_glib_none().0, enabled.into_glib());
163 }
164 }
165
166 #[doc(alias = "gtk_video_set_loop")]
167 #[doc(alias = "loop")]
168 pub fn set_loop(&self, loop_: bool) {
169 unsafe {
170 ffi::gtk_video_set_loop(self.to_glib_none().0, loop_.into_glib());
171 }
172 }
173
174 #[doc(alias = "gtk_video_set_media_stream")]
175 #[doc(alias = "media-stream")]
176 pub fn set_media_stream(&self, stream: Option<&impl IsA<MediaStream>>) {
177 unsafe {
178 ffi::gtk_video_set_media_stream(
179 self.to_glib_none().0,
180 stream.map(|p| p.as_ref()).to_glib_none().0,
181 );
182 }
183 }
184
185 #[doc(alias = "gtk_video_set_resource")]
186 pub fn set_resource(&self, resource_path: Option<&str>) {
187 unsafe {
188 ffi::gtk_video_set_resource(self.to_glib_none().0, resource_path.to_glib_none().0);
189 }
190 }
191
192 #[doc(alias = "autoplay")]
193 pub fn connect_autoplay_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
194 unsafe extern "C" fn notify_autoplay_trampoline<F: Fn(&Video) + 'static>(
195 this: *mut ffi::GtkVideo,
196 _param_spec: glib::ffi::gpointer,
197 f: glib::ffi::gpointer,
198 ) {
199 let f: &F = &*(f as *const F);
200 f(&from_glib_borrow(this))
201 }
202 unsafe {
203 let f: Box_<F> = Box_::new(f);
204 connect_raw(
205 self.as_ptr() as *mut _,
206 c"notify::autoplay".as_ptr() as *const _,
207 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
208 notify_autoplay_trampoline::<F> as *const (),
209 )),
210 Box_::into_raw(f),
211 )
212 }
213 }
214
215 #[doc(alias = "file")]
216 pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217 unsafe extern "C" fn notify_file_trampoline<F: Fn(&Video) + 'static>(
218 this: *mut ffi::GtkVideo,
219 _param_spec: glib::ffi::gpointer,
220 f: glib::ffi::gpointer,
221 ) {
222 let f: &F = &*(f as *const F);
223 f(&from_glib_borrow(this))
224 }
225 unsafe {
226 let f: Box_<F> = Box_::new(f);
227 connect_raw(
228 self.as_ptr() as *mut _,
229 c"notify::file".as_ptr() as *const _,
230 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
231 notify_file_trampoline::<F> as *const (),
232 )),
233 Box_::into_raw(f),
234 )
235 }
236 }
237
238 #[cfg(feature = "v4_14")]
239 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
240 #[doc(alias = "graphics-offload")]
241 pub fn connect_graphics_offload_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
242 unsafe extern "C" fn notify_graphics_offload_trampoline<F: Fn(&Video) + 'static>(
243 this: *mut ffi::GtkVideo,
244 _param_spec: glib::ffi::gpointer,
245 f: glib::ffi::gpointer,
246 ) {
247 let f: &F = &*(f as *const F);
248 f(&from_glib_borrow(this))
249 }
250 unsafe {
251 let f: Box_<F> = Box_::new(f);
252 connect_raw(
253 self.as_ptr() as *mut _,
254 c"notify::graphics-offload".as_ptr() as *const _,
255 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
256 notify_graphics_offload_trampoline::<F> as *const (),
257 )),
258 Box_::into_raw(f),
259 )
260 }
261 }
262
263 #[doc(alias = "loop")]
264 pub fn connect_loop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
265 unsafe extern "C" fn notify_loop_trampoline<F: Fn(&Video) + 'static>(
266 this: *mut ffi::GtkVideo,
267 _param_spec: glib::ffi::gpointer,
268 f: glib::ffi::gpointer,
269 ) {
270 let f: &F = &*(f as *const F);
271 f(&from_glib_borrow(this))
272 }
273 unsafe {
274 let f: Box_<F> = Box_::new(f);
275 connect_raw(
276 self.as_ptr() as *mut _,
277 c"notify::loop".as_ptr() as *const _,
278 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
279 notify_loop_trampoline::<F> as *const (),
280 )),
281 Box_::into_raw(f),
282 )
283 }
284 }
285
286 #[doc(alias = "media-stream")]
287 pub fn connect_media_stream_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
288 unsafe extern "C" fn notify_media_stream_trampoline<F: Fn(&Video) + 'static>(
289 this: *mut ffi::GtkVideo,
290 _param_spec: glib::ffi::gpointer,
291 f: glib::ffi::gpointer,
292 ) {
293 let f: &F = &*(f as *const F);
294 f(&from_glib_borrow(this))
295 }
296 unsafe {
297 let f: Box_<F> = Box_::new(f);
298 connect_raw(
299 self.as_ptr() as *mut _,
300 c"notify::media-stream".as_ptr() as *const _,
301 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
302 notify_media_stream_trampoline::<F> as *const (),
303 )),
304 Box_::into_raw(f),
305 )
306 }
307 }
308}
309
310impl Default for Video {
311 fn default() -> Self {
312 Self::new()
313 }
314}
315
316#[must_use = "The builder must be built to be used"]
321pub struct VideoBuilder {
322 builder: glib::object::ObjectBuilder<'static, Video>,
323}
324
325impl VideoBuilder {
326 fn new() -> Self {
327 Self {
328 builder: glib::object::Object::builder(),
329 }
330 }
331
332 pub fn autoplay(self, autoplay: bool) -> Self {
333 Self {
334 builder: self.builder.property("autoplay", autoplay),
335 }
336 }
337
338 pub fn file(self, file: &impl IsA<gio::File>) -> Self {
339 Self {
340 builder: self.builder.property("file", file.clone().upcast()),
341 }
342 }
343
344 #[cfg(feature = "v4_14")]
345 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
346 pub fn graphics_offload(self, graphics_offload: GraphicsOffloadEnabled) -> Self {
347 Self {
348 builder: self.builder.property("graphics-offload", graphics_offload),
349 }
350 }
351
352 pub fn loop_(self, loop_: bool) -> Self {
353 Self {
354 builder: self.builder.property("loop", loop_),
355 }
356 }
357
358 pub fn media_stream(self, media_stream: &impl IsA<MediaStream>) -> Self {
359 Self {
360 builder: self
361 .builder
362 .property("media-stream", media_stream.clone().upcast()),
363 }
364 }
365
366 pub fn can_focus(self, can_focus: bool) -> Self {
367 Self {
368 builder: self.builder.property("can-focus", can_focus),
369 }
370 }
371
372 pub fn can_target(self, can_target: bool) -> Self {
373 Self {
374 builder: self.builder.property("can-target", can_target),
375 }
376 }
377
378 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
379 Self {
380 builder: self.builder.property("css-classes", css_classes.into()),
381 }
382 }
383
384 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
385 Self {
386 builder: self.builder.property("css-name", css_name.into()),
387 }
388 }
389
390 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
391 Self {
392 builder: self.builder.property("cursor", cursor.clone()),
393 }
394 }
395
396 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
397 Self {
398 builder: self.builder.property("focus-on-click", focus_on_click),
399 }
400 }
401
402 pub fn focusable(self, focusable: bool) -> Self {
403 Self {
404 builder: self.builder.property("focusable", focusable),
405 }
406 }
407
408 pub fn halign(self, halign: Align) -> Self {
409 Self {
410 builder: self.builder.property("halign", halign),
411 }
412 }
413
414 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
415 Self {
416 builder: self.builder.property("has-tooltip", has_tooltip),
417 }
418 }
419
420 pub fn height_request(self, height_request: i32) -> Self {
421 Self {
422 builder: self.builder.property("height-request", height_request),
423 }
424 }
425
426 pub fn hexpand(self, hexpand: bool) -> Self {
427 Self {
428 builder: self.builder.property("hexpand", hexpand),
429 }
430 }
431
432 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
433 Self {
434 builder: self.builder.property("hexpand-set", hexpand_set),
435 }
436 }
437
438 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
439 Self {
440 builder: self
441 .builder
442 .property("layout-manager", layout_manager.clone().upcast()),
443 }
444 }
445
446 #[cfg(feature = "v4_18")]
447 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
448 pub fn limit_events(self, limit_events: bool) -> Self {
449 Self {
450 builder: self.builder.property("limit-events", limit_events),
451 }
452 }
453
454 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
455 Self {
456 builder: self.builder.property("margin-bottom", margin_bottom),
457 }
458 }
459
460 pub fn margin_end(self, margin_end: i32) -> Self {
461 Self {
462 builder: self.builder.property("margin-end", margin_end),
463 }
464 }
465
466 pub fn margin_start(self, margin_start: i32) -> Self {
467 Self {
468 builder: self.builder.property("margin-start", margin_start),
469 }
470 }
471
472 pub fn margin_top(self, margin_top: i32) -> Self {
473 Self {
474 builder: self.builder.property("margin-top", margin_top),
475 }
476 }
477
478 pub fn name(self, name: impl Into<glib::GString>) -> Self {
479 Self {
480 builder: self.builder.property("name", name.into()),
481 }
482 }
483
484 pub fn opacity(self, opacity: f64) -> Self {
485 Self {
486 builder: self.builder.property("opacity", opacity),
487 }
488 }
489
490 pub fn overflow(self, overflow: Overflow) -> Self {
491 Self {
492 builder: self.builder.property("overflow", overflow),
493 }
494 }
495
496 pub fn receives_default(self, receives_default: bool) -> Self {
497 Self {
498 builder: self.builder.property("receives-default", receives_default),
499 }
500 }
501
502 pub fn sensitive(self, sensitive: bool) -> Self {
503 Self {
504 builder: self.builder.property("sensitive", sensitive),
505 }
506 }
507
508 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
509 Self {
510 builder: self
511 .builder
512 .property("tooltip-markup", tooltip_markup.into()),
513 }
514 }
515
516 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
517 Self {
518 builder: self.builder.property("tooltip-text", tooltip_text.into()),
519 }
520 }
521
522 pub fn valign(self, valign: Align) -> Self {
523 Self {
524 builder: self.builder.property("valign", valign),
525 }
526 }
527
528 pub fn vexpand(self, vexpand: bool) -> Self {
529 Self {
530 builder: self.builder.property("vexpand", vexpand),
531 }
532 }
533
534 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
535 Self {
536 builder: self.builder.property("vexpand-set", vexpand_set),
537 }
538 }
539
540 pub fn visible(self, visible: bool) -> Self {
541 Self {
542 builder: self.builder.property("visible", visible),
543 }
544 }
545
546 pub fn width_request(self, width_request: i32) -> Self {
547 Self {
548 builder: self.builder.property("width-request", width_request),
549 }
550 }
551
552 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
553 Self {
554 builder: self.builder.property("accessible-role", accessible_role),
555 }
556 }
557
558 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
561 pub fn build(self) -> Video {
562 assert_initialized_main_thread!();
563 self.builder.build()
564 }
565}