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