1use crate::ffi;
7#[cfg(feature = "v1_7")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
9use crate::BannerButtonStyle;
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 #[doc(alias = "AdwBanner")]
20 pub struct Banner(Object<ffi::AdwBanner, ffi::AdwBannerClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable;
21
22 match fn {
23 type_ => || ffi::adw_banner_get_type(),
24 }
25}
26
27impl Banner {
28 #[doc(alias = "adw_banner_new")]
29 pub fn new(title: &str) -> Banner {
30 assert_initialized_main_thread!();
31 unsafe {
32 gtk::Widget::from_glib_none(ffi::adw_banner_new(title.to_glib_none().0)).unsafe_cast()
33 }
34 }
35
36 pub fn builder() -> BannerBuilder {
41 BannerBuilder::new()
42 }
43
44 #[doc(alias = "adw_banner_get_button_label")]
45 #[doc(alias = "get_button_label")]
46 #[doc(alias = "button-label")]
47 pub fn button_label(&self) -> Option<glib::GString> {
48 unsafe { from_glib_none(ffi::adw_banner_get_button_label(self.to_glib_none().0)) }
49 }
50
51 #[cfg(feature = "v1_7")]
52 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
53 #[doc(alias = "adw_banner_get_button_style")]
54 #[doc(alias = "get_button_style")]
55 #[doc(alias = "button-style")]
56 pub fn button_style(&self) -> BannerButtonStyle {
57 unsafe { from_glib(ffi::adw_banner_get_button_style(self.to_glib_none().0)) }
58 }
59
60 #[doc(alias = "adw_banner_get_revealed")]
61 #[doc(alias = "get_revealed")]
62 #[doc(alias = "revealed")]
63 pub fn is_revealed(&self) -> bool {
64 unsafe { from_glib(ffi::adw_banner_get_revealed(self.to_glib_none().0)) }
65 }
66
67 #[doc(alias = "adw_banner_get_title")]
68 #[doc(alias = "get_title")]
69 pub fn title(&self) -> glib::GString {
70 unsafe { from_glib_none(ffi::adw_banner_get_title(self.to_glib_none().0)) }
71 }
72
73 #[doc(alias = "adw_banner_get_use_markup")]
74 #[doc(alias = "get_use_markup")]
75 #[doc(alias = "use-markup")]
76 pub fn uses_markup(&self) -> bool {
77 unsafe { from_glib(ffi::adw_banner_get_use_markup(self.to_glib_none().0)) }
78 }
79
80 #[doc(alias = "adw_banner_set_button_label")]
81 #[doc(alias = "button-label")]
82 pub fn set_button_label(&self, label: Option<&str>) {
83 unsafe {
84 ffi::adw_banner_set_button_label(self.to_glib_none().0, label.to_glib_none().0);
85 }
86 }
87
88 #[cfg(feature = "v1_7")]
89 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
90 #[doc(alias = "adw_banner_set_button_style")]
91 #[doc(alias = "button-style")]
92 pub fn set_button_style(&self, style: BannerButtonStyle) {
93 unsafe {
94 ffi::adw_banner_set_button_style(self.to_glib_none().0, style.into_glib());
95 }
96 }
97
98 #[doc(alias = "adw_banner_set_revealed")]
99 #[doc(alias = "revealed")]
100 pub fn set_revealed(&self, revealed: bool) {
101 unsafe {
102 ffi::adw_banner_set_revealed(self.to_glib_none().0, revealed.into_glib());
103 }
104 }
105
106 #[doc(alias = "adw_banner_set_title")]
107 #[doc(alias = "title")]
108 pub fn set_title(&self, title: &str) {
109 unsafe {
110 ffi::adw_banner_set_title(self.to_glib_none().0, title.to_glib_none().0);
111 }
112 }
113
114 #[doc(alias = "adw_banner_set_use_markup")]
115 #[doc(alias = "use-markup")]
116 pub fn set_use_markup(&self, use_markup: bool) {
117 unsafe {
118 ffi::adw_banner_set_use_markup(self.to_glib_none().0, use_markup.into_glib());
119 }
120 }
121
122 #[cfg(feature = "v1_3")]
123 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
124 #[doc(alias = "button-clicked")]
125 pub fn connect_button_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
126 unsafe extern "C" fn button_clicked_trampoline<F: Fn(&Banner) + 'static>(
127 this: *mut ffi::AdwBanner,
128 f: glib::ffi::gpointer,
129 ) {
130 let f: &F = &*(f as *const F);
131 f(&from_glib_borrow(this))
132 }
133 unsafe {
134 let f: Box_<F> = Box_::new(f);
135 connect_raw(
136 self.as_ptr() as *mut _,
137 c"button-clicked".as_ptr() as *const _,
138 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
139 button_clicked_trampoline::<F> as *const (),
140 )),
141 Box_::into_raw(f),
142 )
143 }
144 }
145
146 #[cfg(feature = "v1_3")]
147 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
148 #[doc(alias = "button-label")]
149 pub fn connect_button_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150 unsafe extern "C" fn notify_button_label_trampoline<F: Fn(&Banner) + 'static>(
151 this: *mut ffi::AdwBanner,
152 _param_spec: glib::ffi::gpointer,
153 f: glib::ffi::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this))
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 c"notify::button-label".as_ptr() as *const _,
163 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164 notify_button_label_trampoline::<F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170
171 #[cfg(feature = "v1_7")]
172 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
173 #[doc(alias = "button-style")]
174 pub fn connect_button_style_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
175 unsafe extern "C" fn notify_button_style_trampoline<F: Fn(&Banner) + 'static>(
176 this: *mut ffi::AdwBanner,
177 _param_spec: glib::ffi::gpointer,
178 f: glib::ffi::gpointer,
179 ) {
180 let f: &F = &*(f as *const F);
181 f(&from_glib_borrow(this))
182 }
183 unsafe {
184 let f: Box_<F> = Box_::new(f);
185 connect_raw(
186 self.as_ptr() as *mut _,
187 c"notify::button-style".as_ptr() as *const _,
188 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
189 notify_button_style_trampoline::<F> as *const (),
190 )),
191 Box_::into_raw(f),
192 )
193 }
194 }
195
196 #[cfg(feature = "v1_3")]
197 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
198 #[doc(alias = "revealed")]
199 pub fn connect_revealed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
200 unsafe extern "C" fn notify_revealed_trampoline<F: Fn(&Banner) + 'static>(
201 this: *mut ffi::AdwBanner,
202 _param_spec: glib::ffi::gpointer,
203 f: glib::ffi::gpointer,
204 ) {
205 let f: &F = &*(f as *const F);
206 f(&from_glib_borrow(this))
207 }
208 unsafe {
209 let f: Box_<F> = Box_::new(f);
210 connect_raw(
211 self.as_ptr() as *mut _,
212 c"notify::revealed".as_ptr() as *const _,
213 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
214 notify_revealed_trampoline::<F> as *const (),
215 )),
216 Box_::into_raw(f),
217 )
218 }
219 }
220
221 #[cfg(feature = "v1_3")]
222 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
223 #[doc(alias = "title")]
224 pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225 unsafe extern "C" fn notify_title_trampoline<F: Fn(&Banner) + 'static>(
226 this: *mut ffi::AdwBanner,
227 _param_spec: glib::ffi::gpointer,
228 f: glib::ffi::gpointer,
229 ) {
230 let f: &F = &*(f as *const F);
231 f(&from_glib_borrow(this))
232 }
233 unsafe {
234 let f: Box_<F> = Box_::new(f);
235 connect_raw(
236 self.as_ptr() as *mut _,
237 c"notify::title".as_ptr() as *const _,
238 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
239 notify_title_trampoline::<F> as *const (),
240 )),
241 Box_::into_raw(f),
242 )
243 }
244 }
245
246 #[cfg(feature = "v1_3")]
247 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
248 #[doc(alias = "use-markup")]
249 pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
250 unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&Banner) + 'static>(
251 this: *mut ffi::AdwBanner,
252 _param_spec: glib::ffi::gpointer,
253 f: glib::ffi::gpointer,
254 ) {
255 let f: &F = &*(f as *const F);
256 f(&from_glib_borrow(this))
257 }
258 unsafe {
259 let f: Box_<F> = Box_::new(f);
260 connect_raw(
261 self.as_ptr() as *mut _,
262 c"notify::use-markup".as_ptr() as *const _,
263 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
264 notify_use_markup_trampoline::<F> as *const (),
265 )),
266 Box_::into_raw(f),
267 )
268 }
269 }
270}
271
272#[cfg(feature = "v1_3")]
273#[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
274impl Default for Banner {
275 fn default() -> Self {
276 glib::object::Object::new::<Self>()
277 }
278}
279
280#[must_use = "The builder must be built to be used"]
285pub struct BannerBuilder {
286 builder: glib::object::ObjectBuilder<'static, Banner>,
287}
288
289impl BannerBuilder {
290 fn new() -> Self {
291 Self {
292 builder: glib::object::Object::builder(),
293 }
294 }
295
296 #[cfg(feature = "v1_3")]
297 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
298 pub fn button_label(self, button_label: impl Into<glib::GString>) -> Self {
299 Self {
300 builder: self.builder.property("button-label", button_label.into()),
301 }
302 }
303
304 #[cfg(feature = "v1_7")]
305 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
306 pub fn button_style(self, button_style: BannerButtonStyle) -> Self {
307 Self {
308 builder: self.builder.property("button-style", button_style),
309 }
310 }
311
312 #[cfg(feature = "v1_3")]
313 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
314 pub fn revealed(self, revealed: bool) -> Self {
315 Self {
316 builder: self.builder.property("revealed", revealed),
317 }
318 }
319
320 #[cfg(feature = "v1_3")]
321 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
322 pub fn title(self, title: impl Into<glib::GString>) -> Self {
323 Self {
324 builder: self.builder.property("title", title.into()),
325 }
326 }
327
328 #[cfg(feature = "v1_3")]
329 #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
330 pub fn use_markup(self, use_markup: bool) -> Self {
331 Self {
332 builder: self.builder.property("use-markup", use_markup),
333 }
334 }
335
336 pub fn can_focus(self, can_focus: bool) -> Self {
337 Self {
338 builder: self.builder.property("can-focus", can_focus),
339 }
340 }
341
342 pub fn can_target(self, can_target: bool) -> Self {
343 Self {
344 builder: self.builder.property("can-target", can_target),
345 }
346 }
347
348 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
349 Self {
350 builder: self.builder.property("css-classes", css_classes.into()),
351 }
352 }
353
354 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
355 Self {
356 builder: self.builder.property("css-name", css_name.into()),
357 }
358 }
359
360 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
361 Self {
362 builder: self.builder.property("cursor", cursor.clone()),
363 }
364 }
365
366 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
367 Self {
368 builder: self.builder.property("focus-on-click", focus_on_click),
369 }
370 }
371
372 pub fn focusable(self, focusable: bool) -> Self {
373 Self {
374 builder: self.builder.property("focusable", focusable),
375 }
376 }
377
378 pub fn halign(self, halign: gtk::Align) -> Self {
379 Self {
380 builder: self.builder.property("halign", halign),
381 }
382 }
383
384 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
385 Self {
386 builder: self.builder.property("has-tooltip", has_tooltip),
387 }
388 }
389
390 pub fn height_request(self, height_request: i32) -> Self {
391 Self {
392 builder: self.builder.property("height-request", height_request),
393 }
394 }
395
396 pub fn hexpand(self, hexpand: bool) -> Self {
397 Self {
398 builder: self.builder.property("hexpand", hexpand),
399 }
400 }
401
402 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
403 Self {
404 builder: self.builder.property("hexpand-set", hexpand_set),
405 }
406 }
407
408 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
409 Self {
410 builder: self
411 .builder
412 .property("layout-manager", layout_manager.clone().upcast()),
413 }
414 }
415
416 #[cfg(feature = "gtk_v4_18")]
417 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
418 pub fn limit_events(self, limit_events: bool) -> Self {
419 Self {
420 builder: self.builder.property("limit-events", limit_events),
421 }
422 }
423
424 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
425 Self {
426 builder: self.builder.property("margin-bottom", margin_bottom),
427 }
428 }
429
430 pub fn margin_end(self, margin_end: i32) -> Self {
431 Self {
432 builder: self.builder.property("margin-end", margin_end),
433 }
434 }
435
436 pub fn margin_start(self, margin_start: i32) -> Self {
437 Self {
438 builder: self.builder.property("margin-start", margin_start),
439 }
440 }
441
442 pub fn margin_top(self, margin_top: i32) -> Self {
443 Self {
444 builder: self.builder.property("margin-top", margin_top),
445 }
446 }
447
448 pub fn name(self, name: impl Into<glib::GString>) -> Self {
449 Self {
450 builder: self.builder.property("name", name.into()),
451 }
452 }
453
454 pub fn opacity(self, opacity: f64) -> Self {
455 Self {
456 builder: self.builder.property("opacity", opacity),
457 }
458 }
459
460 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
461 Self {
462 builder: self.builder.property("overflow", overflow),
463 }
464 }
465
466 pub fn receives_default(self, receives_default: bool) -> Self {
467 Self {
468 builder: self.builder.property("receives-default", receives_default),
469 }
470 }
471
472 pub fn sensitive(self, sensitive: bool) -> Self {
473 Self {
474 builder: self.builder.property("sensitive", sensitive),
475 }
476 }
477
478 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
479 Self {
480 builder: self
481 .builder
482 .property("tooltip-markup", tooltip_markup.into()),
483 }
484 }
485
486 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
487 Self {
488 builder: self.builder.property("tooltip-text", tooltip_text.into()),
489 }
490 }
491
492 pub fn valign(self, valign: gtk::Align) -> Self {
493 Self {
494 builder: self.builder.property("valign", valign),
495 }
496 }
497
498 pub fn vexpand(self, vexpand: bool) -> Self {
499 Self {
500 builder: self.builder.property("vexpand", vexpand),
501 }
502 }
503
504 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
505 Self {
506 builder: self.builder.property("vexpand-set", vexpand_set),
507 }
508 }
509
510 pub fn visible(self, visible: bool) -> Self {
511 Self {
512 builder: self.builder.property("visible", visible),
513 }
514 }
515
516 pub fn width_request(self, width_request: i32) -> Self {
517 Self {
518 builder: self.builder.property("width-request", width_request),
519 }
520 }
521
522 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
523 Self {
524 builder: self.builder.property("accessible-role", accessible_role),
525 }
526 }
527
528 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
529 Self {
530 builder: self.builder.property("action-name", action_name.into()),
531 }
532 }
533
534 pub fn action_target(self, action_target: &glib::Variant) -> Self {
535 Self {
536 builder: self
537 .builder
538 .property("action-target", action_target.clone()),
539 }
540 }
541
542 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
545 pub fn build(self) -> Banner {
546 assert_initialized_main_thread!();
547 self.builder.build()
548 }
549}