1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7 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 = "GtkHeaderBar")]
18 pub struct HeaderBar(Object<ffi::GtkHeaderBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
19
20 match fn {
21 type_ => || ffi::gtk_header_bar_get_type(),
22 }
23}
24
25impl HeaderBar {
26 #[doc(alias = "gtk_header_bar_new")]
27 pub fn new() -> HeaderBar {
28 assert_initialized_main_thread!();
29 unsafe { Widget::from_glib_none(ffi::gtk_header_bar_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> HeaderBarBuilder {
37 HeaderBarBuilder::new()
38 }
39
40 #[doc(alias = "gtk_header_bar_get_decoration_layout")]
41 #[doc(alias = "get_decoration_layout")]
42 #[doc(alias = "decoration-layout")]
43 pub fn decoration_layout(&self) -> Option<glib::GString> {
44 unsafe {
45 from_glib_none(ffi::gtk_header_bar_get_decoration_layout(
46 self.to_glib_none().0,
47 ))
48 }
49 }
50
51 #[doc(alias = "gtk_header_bar_get_show_title_buttons")]
52 #[doc(alias = "get_show_title_buttons")]
53 #[doc(alias = "show-title-buttons")]
54 pub fn shows_title_buttons(&self) -> bool {
55 unsafe {
56 from_glib(ffi::gtk_header_bar_get_show_title_buttons(
57 self.to_glib_none().0,
58 ))
59 }
60 }
61
62 #[doc(alias = "gtk_header_bar_get_title_widget")]
63 #[doc(alias = "get_title_widget")]
64 #[doc(alias = "title-widget")]
65 pub fn title_widget(&self) -> Option<Widget> {
66 unsafe { from_glib_none(ffi::gtk_header_bar_get_title_widget(self.to_glib_none().0)) }
67 }
68
69 #[cfg(feature = "v4_18")]
70 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
71 #[doc(alias = "gtk_header_bar_get_use_native_controls")]
72 #[doc(alias = "get_use_native_controls")]
73 #[doc(alias = "use-native-controls")]
74 pub fn uses_native_controls(&self) -> bool {
75 unsafe {
76 from_glib(ffi::gtk_header_bar_get_use_native_controls(
77 self.to_glib_none().0,
78 ))
79 }
80 }
81
82 #[doc(alias = "gtk_header_bar_pack_end")]
83 pub fn pack_end(&self, child: &impl IsA<Widget>) {
84 unsafe {
85 ffi::gtk_header_bar_pack_end(self.to_glib_none().0, child.as_ref().to_glib_none().0);
86 }
87 }
88
89 #[doc(alias = "gtk_header_bar_pack_start")]
90 pub fn pack_start(&self, child: &impl IsA<Widget>) {
91 unsafe {
92 ffi::gtk_header_bar_pack_start(self.to_glib_none().0, child.as_ref().to_glib_none().0);
93 }
94 }
95
96 #[doc(alias = "gtk_header_bar_remove")]
97 pub fn remove(&self, child: &impl IsA<Widget>) {
98 unsafe {
99 ffi::gtk_header_bar_remove(self.to_glib_none().0, child.as_ref().to_glib_none().0);
100 }
101 }
102
103 #[doc(alias = "gtk_header_bar_set_decoration_layout")]
104 #[doc(alias = "decoration-layout")]
105 pub fn set_decoration_layout(&self, layout: Option<&str>) {
106 unsafe {
107 ffi::gtk_header_bar_set_decoration_layout(
108 self.to_glib_none().0,
109 layout.to_glib_none().0,
110 );
111 }
112 }
113
114 #[doc(alias = "gtk_header_bar_set_show_title_buttons")]
115 #[doc(alias = "show-title-buttons")]
116 pub fn set_show_title_buttons(&self, setting: bool) {
117 unsafe {
118 ffi::gtk_header_bar_set_show_title_buttons(self.to_glib_none().0, setting.into_glib());
119 }
120 }
121
122 #[doc(alias = "gtk_header_bar_set_title_widget")]
123 #[doc(alias = "title-widget")]
124 pub fn set_title_widget(&self, title_widget: Option<&impl IsA<Widget>>) {
125 unsafe {
126 ffi::gtk_header_bar_set_title_widget(
127 self.to_glib_none().0,
128 title_widget.map(|p| p.as_ref()).to_glib_none().0,
129 );
130 }
131 }
132
133 #[cfg(feature = "v4_18")]
134 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
135 #[doc(alias = "gtk_header_bar_set_use_native_controls")]
136 #[doc(alias = "use-native-controls")]
137 pub fn set_use_native_controls(&self, setting: bool) {
138 unsafe {
139 ffi::gtk_header_bar_set_use_native_controls(self.to_glib_none().0, setting.into_glib());
140 }
141 }
142
143 #[doc(alias = "decoration-layout")]
144 pub fn connect_decoration_layout_notify<F: Fn(&Self) + 'static>(
145 &self,
146 f: F,
147 ) -> SignalHandlerId {
148 unsafe extern "C" fn notify_decoration_layout_trampoline<F: Fn(&HeaderBar) + 'static>(
149 this: *mut ffi::GtkHeaderBar,
150 _param_spec: glib::ffi::gpointer,
151 f: glib::ffi::gpointer,
152 ) {
153 let f: &F = &*(f as *const F);
154 f(&from_glib_borrow(this))
155 }
156 unsafe {
157 let f: Box_<F> = Box_::new(f);
158 connect_raw(
159 self.as_ptr() as *mut _,
160 c"notify::decoration-layout".as_ptr() as *const _,
161 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
162 notify_decoration_layout_trampoline::<F> as *const (),
163 )),
164 Box_::into_raw(f),
165 )
166 }
167 }
168
169 #[doc(alias = "show-title-buttons")]
170 pub fn connect_show_title_buttons_notify<F: Fn(&Self) + 'static>(
171 &self,
172 f: F,
173 ) -> SignalHandlerId {
174 unsafe extern "C" fn notify_show_title_buttons_trampoline<F: Fn(&HeaderBar) + 'static>(
175 this: *mut ffi::GtkHeaderBar,
176 _param_spec: glib::ffi::gpointer,
177 f: glib::ffi::gpointer,
178 ) {
179 let f: &F = &*(f as *const F);
180 f(&from_glib_borrow(this))
181 }
182 unsafe {
183 let f: Box_<F> = Box_::new(f);
184 connect_raw(
185 self.as_ptr() as *mut _,
186 c"notify::show-title-buttons".as_ptr() as *const _,
187 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188 notify_show_title_buttons_trampoline::<F> as *const (),
189 )),
190 Box_::into_raw(f),
191 )
192 }
193 }
194
195 #[doc(alias = "title-widget")]
196 pub fn connect_title_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
197 unsafe extern "C" fn notify_title_widget_trampoline<F: Fn(&HeaderBar) + 'static>(
198 this: *mut ffi::GtkHeaderBar,
199 _param_spec: glib::ffi::gpointer,
200 f: glib::ffi::gpointer,
201 ) {
202 let f: &F = &*(f as *const F);
203 f(&from_glib_borrow(this))
204 }
205 unsafe {
206 let f: Box_<F> = Box_::new(f);
207 connect_raw(
208 self.as_ptr() as *mut _,
209 c"notify::title-widget".as_ptr() as *const _,
210 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
211 notify_title_widget_trampoline::<F> as *const (),
212 )),
213 Box_::into_raw(f),
214 )
215 }
216 }
217
218 #[cfg(feature = "v4_18")]
219 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
220 #[doc(alias = "use-native-controls")]
221 pub fn connect_use_native_controls_notify<F: Fn(&Self) + 'static>(
222 &self,
223 f: F,
224 ) -> SignalHandlerId {
225 unsafe extern "C" fn notify_use_native_controls_trampoline<F: Fn(&HeaderBar) + 'static>(
226 this: *mut ffi::GtkHeaderBar,
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::use-native-controls".as_ptr() as *const _,
238 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
239 notify_use_native_controls_trampoline::<F> as *const (),
240 )),
241 Box_::into_raw(f),
242 )
243 }
244 }
245}
246
247impl Default for HeaderBar {
248 fn default() -> Self {
249 Self::new()
250 }
251}
252
253#[must_use = "The builder must be built to be used"]
258pub struct HeaderBarBuilder {
259 builder: glib::object::ObjectBuilder<'static, HeaderBar>,
260}
261
262impl HeaderBarBuilder {
263 fn new() -> Self {
264 Self {
265 builder: glib::object::Object::builder(),
266 }
267 }
268
269 pub fn decoration_layout(self, decoration_layout: impl Into<glib::GString>) -> Self {
270 Self {
271 builder: self
272 .builder
273 .property("decoration-layout", decoration_layout.into()),
274 }
275 }
276
277 pub fn show_title_buttons(self, show_title_buttons: bool) -> Self {
278 Self {
279 builder: self
280 .builder
281 .property("show-title-buttons", show_title_buttons),
282 }
283 }
284
285 pub fn title_widget(self, title_widget: &impl IsA<Widget>) -> Self {
286 Self {
287 builder: self
288 .builder
289 .property("title-widget", title_widget.clone().upcast()),
290 }
291 }
292
293 #[cfg(feature = "v4_18")]
294 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
295 pub fn use_native_controls(self, use_native_controls: bool) -> Self {
296 Self {
297 builder: self
298 .builder
299 .property("use-native-controls", use_native_controls),
300 }
301 }
302
303 pub fn can_focus(self, can_focus: bool) -> Self {
304 Self {
305 builder: self.builder.property("can-focus", can_focus),
306 }
307 }
308
309 pub fn can_target(self, can_target: bool) -> Self {
310 Self {
311 builder: self.builder.property("can-target", can_target),
312 }
313 }
314
315 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
316 Self {
317 builder: self.builder.property("css-classes", css_classes.into()),
318 }
319 }
320
321 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
322 Self {
323 builder: self.builder.property("css-name", css_name.into()),
324 }
325 }
326
327 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
328 Self {
329 builder: self.builder.property("cursor", cursor.clone()),
330 }
331 }
332
333 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
334 Self {
335 builder: self.builder.property("focus-on-click", focus_on_click),
336 }
337 }
338
339 pub fn focusable(self, focusable: bool) -> Self {
340 Self {
341 builder: self.builder.property("focusable", focusable),
342 }
343 }
344
345 pub fn halign(self, halign: Align) -> Self {
346 Self {
347 builder: self.builder.property("halign", halign),
348 }
349 }
350
351 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
352 Self {
353 builder: self.builder.property("has-tooltip", has_tooltip),
354 }
355 }
356
357 pub fn height_request(self, height_request: i32) -> Self {
358 Self {
359 builder: self.builder.property("height-request", height_request),
360 }
361 }
362
363 pub fn hexpand(self, hexpand: bool) -> Self {
364 Self {
365 builder: self.builder.property("hexpand", hexpand),
366 }
367 }
368
369 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
370 Self {
371 builder: self.builder.property("hexpand-set", hexpand_set),
372 }
373 }
374
375 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
376 Self {
377 builder: self
378 .builder
379 .property("layout-manager", layout_manager.clone().upcast()),
380 }
381 }
382
383 #[cfg(feature = "v4_18")]
384 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
385 pub fn limit_events(self, limit_events: bool) -> Self {
386 Self {
387 builder: self.builder.property("limit-events", limit_events),
388 }
389 }
390
391 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
392 Self {
393 builder: self.builder.property("margin-bottom", margin_bottom),
394 }
395 }
396
397 pub fn margin_end(self, margin_end: i32) -> Self {
398 Self {
399 builder: self.builder.property("margin-end", margin_end),
400 }
401 }
402
403 pub fn margin_start(self, margin_start: i32) -> Self {
404 Self {
405 builder: self.builder.property("margin-start", margin_start),
406 }
407 }
408
409 pub fn margin_top(self, margin_top: i32) -> Self {
410 Self {
411 builder: self.builder.property("margin-top", margin_top),
412 }
413 }
414
415 pub fn name(self, name: impl Into<glib::GString>) -> Self {
416 Self {
417 builder: self.builder.property("name", name.into()),
418 }
419 }
420
421 pub fn opacity(self, opacity: f64) -> Self {
422 Self {
423 builder: self.builder.property("opacity", opacity),
424 }
425 }
426
427 pub fn overflow(self, overflow: Overflow) -> Self {
428 Self {
429 builder: self.builder.property("overflow", overflow),
430 }
431 }
432
433 pub fn receives_default(self, receives_default: bool) -> Self {
434 Self {
435 builder: self.builder.property("receives-default", receives_default),
436 }
437 }
438
439 pub fn sensitive(self, sensitive: bool) -> Self {
440 Self {
441 builder: self.builder.property("sensitive", sensitive),
442 }
443 }
444
445 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
446 Self {
447 builder: self
448 .builder
449 .property("tooltip-markup", tooltip_markup.into()),
450 }
451 }
452
453 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
454 Self {
455 builder: self.builder.property("tooltip-text", tooltip_text.into()),
456 }
457 }
458
459 pub fn valign(self, valign: Align) -> Self {
460 Self {
461 builder: self.builder.property("valign", valign),
462 }
463 }
464
465 pub fn vexpand(self, vexpand: bool) -> Self {
466 Self {
467 builder: self.builder.property("vexpand", vexpand),
468 }
469 }
470
471 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
472 Self {
473 builder: self.builder.property("vexpand-set", vexpand_set),
474 }
475 }
476
477 pub fn visible(self, visible: bool) -> Self {
478 Self {
479 builder: self.builder.property("visible", visible),
480 }
481 }
482
483 pub fn width_request(self, width_request: i32) -> Self {
484 Self {
485 builder: self.builder.property("width-request", width_request),
486 }
487 }
488
489 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
490 Self {
491 builder: self.builder.property("accessible-role", accessible_role),
492 }
493 }
494
495 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
498 pub fn build(self) -> HeaderBar {
499 assert_initialized_main_thread!();
500 self.builder.build()
501 }
502}