gtk4/auto/
flow_box_child.rs

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