1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager,
7 MediaStream, Overflow, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkMediaControls")]
18 pub struct MediaControls(Object<ffi::GtkMediaControls, ffi::GtkMediaControlsClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
19
20 match fn {
21 type_ => || ffi::gtk_media_controls_get_type(),
22 }
23}
24
25impl MediaControls {
26 #[doc(alias = "gtk_media_controls_new")]
27 pub fn new(stream: Option<&impl IsA<MediaStream>>) -> MediaControls {
28 assert_initialized_main_thread!();
29 unsafe {
30 Widget::from_glib_none(ffi::gtk_media_controls_new(
31 stream.map(|p| p.as_ref()).to_glib_none().0,
32 ))
33 .unsafe_cast()
34 }
35 }
36
37 pub fn builder() -> MediaControlsBuilder {
42 MediaControlsBuilder::new()
43 }
44
45 #[doc(alias = "gtk_media_controls_get_media_stream")]
46 #[doc(alias = "get_media_stream")]
47 #[doc(alias = "media-stream")]
48 pub fn media_stream(&self) -> Option<MediaStream> {
49 unsafe {
50 from_glib_none(ffi::gtk_media_controls_get_media_stream(
51 self.to_glib_none().0,
52 ))
53 }
54 }
55
56 #[doc(alias = "gtk_media_controls_set_media_stream")]
57 #[doc(alias = "media-stream")]
58 pub fn set_media_stream(&self, stream: Option<&impl IsA<MediaStream>>) {
59 unsafe {
60 ffi::gtk_media_controls_set_media_stream(
61 self.to_glib_none().0,
62 stream.map(|p| p.as_ref()).to_glib_none().0,
63 );
64 }
65 }
66
67 #[doc(alias = "media-stream")]
68 pub fn connect_media_stream_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
69 unsafe extern "C" fn notify_media_stream_trampoline<F: Fn(&MediaControls) + 'static>(
70 this: *mut ffi::GtkMediaControls,
71 _param_spec: glib::ffi::gpointer,
72 f: glib::ffi::gpointer,
73 ) {
74 let f: &F = &*(f as *const F);
75 f(&from_glib_borrow(this))
76 }
77 unsafe {
78 let f: Box_<F> = Box_::new(f);
79 connect_raw(
80 self.as_ptr() as *mut _,
81 c"notify::media-stream".as_ptr() as *const _,
82 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
83 notify_media_stream_trampoline::<F> as *const (),
84 )),
85 Box_::into_raw(f),
86 )
87 }
88 }
89}
90
91impl Default for MediaControls {
92 fn default() -> Self {
93 glib::object::Object::new::<Self>()
94 }
95}
96
97#[must_use = "The builder must be built to be used"]
102pub struct MediaControlsBuilder {
103 builder: glib::object::ObjectBuilder<'static, MediaControls>,
104}
105
106impl MediaControlsBuilder {
107 fn new() -> Self {
108 Self {
109 builder: glib::object::Object::builder(),
110 }
111 }
112
113 pub fn media_stream(self, media_stream: &impl IsA<MediaStream>) -> Self {
114 Self {
115 builder: self
116 .builder
117 .property("media-stream", media_stream.clone().upcast()),
118 }
119 }
120
121 pub fn can_focus(self, can_focus: bool) -> Self {
122 Self {
123 builder: self.builder.property("can-focus", can_focus),
124 }
125 }
126
127 pub fn can_target(self, can_target: bool) -> Self {
128 Self {
129 builder: self.builder.property("can-target", can_target),
130 }
131 }
132
133 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
134 Self {
135 builder: self.builder.property("css-classes", css_classes.into()),
136 }
137 }
138
139 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
140 Self {
141 builder: self.builder.property("css-name", css_name.into()),
142 }
143 }
144
145 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
146 Self {
147 builder: self.builder.property("cursor", cursor.clone()),
148 }
149 }
150
151 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
152 Self {
153 builder: self.builder.property("focus-on-click", focus_on_click),
154 }
155 }
156
157 pub fn focusable(self, focusable: bool) -> Self {
158 Self {
159 builder: self.builder.property("focusable", focusable),
160 }
161 }
162
163 pub fn halign(self, halign: Align) -> Self {
164 Self {
165 builder: self.builder.property("halign", halign),
166 }
167 }
168
169 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
170 Self {
171 builder: self.builder.property("has-tooltip", has_tooltip),
172 }
173 }
174
175 pub fn height_request(self, height_request: i32) -> Self {
176 Self {
177 builder: self.builder.property("height-request", height_request),
178 }
179 }
180
181 pub fn hexpand(self, hexpand: bool) -> Self {
182 Self {
183 builder: self.builder.property("hexpand", hexpand),
184 }
185 }
186
187 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
188 Self {
189 builder: self.builder.property("hexpand-set", hexpand_set),
190 }
191 }
192
193 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
194 Self {
195 builder: self
196 .builder
197 .property("layout-manager", layout_manager.clone().upcast()),
198 }
199 }
200
201 #[cfg(feature = "v4_18")]
202 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
203 pub fn limit_events(self, limit_events: bool) -> Self {
204 Self {
205 builder: self.builder.property("limit-events", limit_events),
206 }
207 }
208
209 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
210 Self {
211 builder: self.builder.property("margin-bottom", margin_bottom),
212 }
213 }
214
215 pub fn margin_end(self, margin_end: i32) -> Self {
216 Self {
217 builder: self.builder.property("margin-end", margin_end),
218 }
219 }
220
221 pub fn margin_start(self, margin_start: i32) -> Self {
222 Self {
223 builder: self.builder.property("margin-start", margin_start),
224 }
225 }
226
227 pub fn margin_top(self, margin_top: i32) -> Self {
228 Self {
229 builder: self.builder.property("margin-top", margin_top),
230 }
231 }
232
233 pub fn name(self, name: impl Into<glib::GString>) -> Self {
234 Self {
235 builder: self.builder.property("name", name.into()),
236 }
237 }
238
239 pub fn opacity(self, opacity: f64) -> Self {
240 Self {
241 builder: self.builder.property("opacity", opacity),
242 }
243 }
244
245 pub fn overflow(self, overflow: Overflow) -> Self {
246 Self {
247 builder: self.builder.property("overflow", overflow),
248 }
249 }
250
251 pub fn receives_default(self, receives_default: bool) -> Self {
252 Self {
253 builder: self.builder.property("receives-default", receives_default),
254 }
255 }
256
257 pub fn sensitive(self, sensitive: bool) -> Self {
258 Self {
259 builder: self.builder.property("sensitive", sensitive),
260 }
261 }
262
263 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
264 Self {
265 builder: self
266 .builder
267 .property("tooltip-markup", tooltip_markup.into()),
268 }
269 }
270
271 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
272 Self {
273 builder: self.builder.property("tooltip-text", tooltip_text.into()),
274 }
275 }
276
277 pub fn valign(self, valign: Align) -> Self {
278 Self {
279 builder: self.builder.property("valign", valign),
280 }
281 }
282
283 pub fn vexpand(self, vexpand: bool) -> Self {
284 Self {
285 builder: self.builder.property("vexpand", vexpand),
286 }
287 }
288
289 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
290 Self {
291 builder: self.builder.property("vexpand-set", vexpand_set),
292 }
293 }
294
295 pub fn visible(self, visible: bool) -> Self {
296 Self {
297 builder: self.builder.property("visible", visible),
298 }
299 }
300
301 pub fn width_request(self, width_request: i32) -> Self {
302 Self {
303 builder: self.builder.property("width-request", width_request),
304 }
305 }
306
307 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
308 Self {
309 builder: self.builder.property("accessible-role", accessible_role),
310 }
311 }
312
313 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
316 pub fn build(self) -> MediaControls {
317 assert_initialized_main_thread!();
318 self.builder.build()
319 }
320}