libadwaita/auto/
tab_button.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{ffi, TabView};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "AdwTabButton")]
17    pub struct TabButton(Object<ffi::AdwTabButton, ffi::AdwTabButtonClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable;
18
19    match fn {
20        type_ => || ffi::adw_tab_button_get_type(),
21    }
22}
23
24impl TabButton {
25    #[doc(alias = "adw_tab_button_new")]
26    pub fn new() -> TabButton {
27        assert_initialized_main_thread!();
28        unsafe { gtk::Widget::from_glib_none(ffi::adw_tab_button_new()).unsafe_cast() }
29    }
30
31    // rustdoc-stripper-ignore-next
32    /// Creates a new builder-pattern struct instance to construct [`TabButton`] objects.
33    ///
34    /// This method returns an instance of [`TabButtonBuilder`](crate::builders::TabButtonBuilder) which can be used to create [`TabButton`] objects.
35    pub fn builder() -> TabButtonBuilder {
36        TabButtonBuilder::new()
37    }
38
39    #[doc(alias = "adw_tab_button_get_view")]
40    #[doc(alias = "get_view")]
41    pub fn view(&self) -> Option<TabView> {
42        unsafe { from_glib_none(ffi::adw_tab_button_get_view(self.to_glib_none().0)) }
43    }
44
45    #[doc(alias = "adw_tab_button_set_view")]
46    #[doc(alias = "view")]
47    pub fn set_view(&self, view: Option<&TabView>) {
48        unsafe {
49            ffi::adw_tab_button_set_view(self.to_glib_none().0, view.to_glib_none().0);
50        }
51    }
52
53    #[cfg(feature = "v1_3")]
54    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
55    #[doc(alias = "activate")]
56    pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
57        unsafe extern "C" fn activate_trampoline<F: Fn(&TabButton) + 'static>(
58            this: *mut ffi::AdwTabButton,
59            f: glib::ffi::gpointer,
60        ) {
61            let f: &F = &*(f as *const F);
62            f(&from_glib_borrow(this))
63        }
64        unsafe {
65            let f: Box_<F> = Box_::new(f);
66            connect_raw(
67                self.as_ptr() as *mut _,
68                c"activate".as_ptr() as *const _,
69                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
70                    activate_trampoline::<F> as *const (),
71                )),
72                Box_::into_raw(f),
73            )
74        }
75    }
76
77    #[cfg(feature = "v1_3")]
78    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
79    pub fn emit_activate(&self) {
80        self.emit_by_name::<()>("activate", &[]);
81    }
82
83    #[cfg(feature = "v1_3")]
84    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
85    #[doc(alias = "clicked")]
86    pub fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
87        unsafe extern "C" fn clicked_trampoline<F: Fn(&TabButton) + 'static>(
88            this: *mut ffi::AdwTabButton,
89            f: glib::ffi::gpointer,
90        ) {
91            let f: &F = &*(f as *const F);
92            f(&from_glib_borrow(this))
93        }
94        unsafe {
95            let f: Box_<F> = Box_::new(f);
96            connect_raw(
97                self.as_ptr() as *mut _,
98                c"clicked".as_ptr() as *const _,
99                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
100                    clicked_trampoline::<F> as *const (),
101                )),
102                Box_::into_raw(f),
103            )
104        }
105    }
106
107    #[cfg(feature = "v1_3")]
108    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
109    pub fn emit_clicked(&self) {
110        self.emit_by_name::<()>("clicked", &[]);
111    }
112
113    #[cfg(feature = "v1_3")]
114    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
115    #[doc(alias = "view")]
116    pub fn connect_view_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
117        unsafe extern "C" fn notify_view_trampoline<F: Fn(&TabButton) + 'static>(
118            this: *mut ffi::AdwTabButton,
119            _param_spec: glib::ffi::gpointer,
120            f: glib::ffi::gpointer,
121        ) {
122            let f: &F = &*(f as *const F);
123            f(&from_glib_borrow(this))
124        }
125        unsafe {
126            let f: Box_<F> = Box_::new(f);
127            connect_raw(
128                self.as_ptr() as *mut _,
129                c"notify::view".as_ptr() as *const _,
130                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
131                    notify_view_trampoline::<F> as *const (),
132                )),
133                Box_::into_raw(f),
134            )
135        }
136    }
137}
138
139#[cfg(feature = "v1_3")]
140#[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
141impl Default for TabButton {
142    fn default() -> Self {
143        Self::new()
144    }
145}
146
147// rustdoc-stripper-ignore-next
148/// A [builder-pattern] type to construct [`TabButton`] objects.
149///
150/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
151#[must_use = "The builder must be built to be used"]
152pub struct TabButtonBuilder {
153    builder: glib::object::ObjectBuilder<'static, TabButton>,
154}
155
156impl TabButtonBuilder {
157    fn new() -> Self {
158        Self {
159            builder: glib::object::Object::builder(),
160        }
161    }
162
163    #[cfg(feature = "v1_3")]
164    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
165    pub fn view(self, view: &TabView) -> Self {
166        Self {
167            builder: self.builder.property("view", view.clone()),
168        }
169    }
170
171    pub fn can_focus(self, can_focus: bool) -> Self {
172        Self {
173            builder: self.builder.property("can-focus", can_focus),
174        }
175    }
176
177    pub fn can_target(self, can_target: bool) -> Self {
178        Self {
179            builder: self.builder.property("can-target", can_target),
180        }
181    }
182
183    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
184        Self {
185            builder: self.builder.property("css-classes", css_classes.into()),
186        }
187    }
188
189    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
190        Self {
191            builder: self.builder.property("css-name", css_name.into()),
192        }
193    }
194
195    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
196        Self {
197            builder: self.builder.property("cursor", cursor.clone()),
198        }
199    }
200
201    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
202        Self {
203            builder: self.builder.property("focus-on-click", focus_on_click),
204        }
205    }
206
207    pub fn focusable(self, focusable: bool) -> Self {
208        Self {
209            builder: self.builder.property("focusable", focusable),
210        }
211    }
212
213    pub fn halign(self, halign: gtk::Align) -> Self {
214        Self {
215            builder: self.builder.property("halign", halign),
216        }
217    }
218
219    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
220        Self {
221            builder: self.builder.property("has-tooltip", has_tooltip),
222        }
223    }
224
225    pub fn height_request(self, height_request: i32) -> Self {
226        Self {
227            builder: self.builder.property("height-request", height_request),
228        }
229    }
230
231    pub fn hexpand(self, hexpand: bool) -> Self {
232        Self {
233            builder: self.builder.property("hexpand", hexpand),
234        }
235    }
236
237    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
238        Self {
239            builder: self.builder.property("hexpand-set", hexpand_set),
240        }
241    }
242
243    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
244        Self {
245            builder: self
246                .builder
247                .property("layout-manager", layout_manager.clone().upcast()),
248        }
249    }
250
251    #[cfg(feature = "gtk_v4_18")]
252    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
253    pub fn limit_events(self, limit_events: bool) -> Self {
254        Self {
255            builder: self.builder.property("limit-events", limit_events),
256        }
257    }
258
259    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
260        Self {
261            builder: self.builder.property("margin-bottom", margin_bottom),
262        }
263    }
264
265    pub fn margin_end(self, margin_end: i32) -> Self {
266        Self {
267            builder: self.builder.property("margin-end", margin_end),
268        }
269    }
270
271    pub fn margin_start(self, margin_start: i32) -> Self {
272        Self {
273            builder: self.builder.property("margin-start", margin_start),
274        }
275    }
276
277    pub fn margin_top(self, margin_top: i32) -> Self {
278        Self {
279            builder: self.builder.property("margin-top", margin_top),
280        }
281    }
282
283    pub fn name(self, name: impl Into<glib::GString>) -> Self {
284        Self {
285            builder: self.builder.property("name", name.into()),
286        }
287    }
288
289    pub fn opacity(self, opacity: f64) -> Self {
290        Self {
291            builder: self.builder.property("opacity", opacity),
292        }
293    }
294
295    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
296        Self {
297            builder: self.builder.property("overflow", overflow),
298        }
299    }
300
301    pub fn receives_default(self, receives_default: bool) -> Self {
302        Self {
303            builder: self.builder.property("receives-default", receives_default),
304        }
305    }
306
307    pub fn sensitive(self, sensitive: bool) -> Self {
308        Self {
309            builder: self.builder.property("sensitive", sensitive),
310        }
311    }
312
313    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
314        Self {
315            builder: self
316                .builder
317                .property("tooltip-markup", tooltip_markup.into()),
318        }
319    }
320
321    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
322        Self {
323            builder: self.builder.property("tooltip-text", tooltip_text.into()),
324        }
325    }
326
327    pub fn valign(self, valign: gtk::Align) -> Self {
328        Self {
329            builder: self.builder.property("valign", valign),
330        }
331    }
332
333    pub fn vexpand(self, vexpand: bool) -> Self {
334        Self {
335            builder: self.builder.property("vexpand", vexpand),
336        }
337    }
338
339    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
340        Self {
341            builder: self.builder.property("vexpand-set", vexpand_set),
342        }
343    }
344
345    pub fn visible(self, visible: bool) -> Self {
346        Self {
347            builder: self.builder.property("visible", visible),
348        }
349    }
350
351    pub fn width_request(self, width_request: i32) -> Self {
352        Self {
353            builder: self.builder.property("width-request", width_request),
354        }
355    }
356
357    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
358        Self {
359            builder: self.builder.property("accessible-role", accessible_role),
360        }
361    }
362
363    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
364        Self {
365            builder: self.builder.property("action-name", action_name.into()),
366        }
367    }
368
369    pub fn action_target(self, action_target: &glib::Variant) -> Self {
370        Self {
371            builder: self
372                .builder
373                .property("action-target", action_target.clone()),
374        }
375    }
376
377    // rustdoc-stripper-ignore-next
378    /// Build the [`TabButton`].
379    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
380    pub fn build(self) -> TabButton {
381        assert_initialized_main_thread!();
382        self.builder.build()
383    }
384}