1use crate::{
6 Align, BaselinePosition, Box, Buildable, ButtonBoxStyle, Container, Orientable, Orientation,
7 ResizeMode, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem::transmute};
15
16glib::wrapper! {
17 #[doc(alias = "GtkButtonBox")]
18 pub struct ButtonBox(Object<ffi::GtkButtonBox, ffi::GtkButtonBoxClass>) @extends Box, Container, Widget, @implements Buildable, Orientable;
19
20 match fn {
21 type_ => || ffi::gtk_button_box_get_type(),
22 }
23}
24
25impl ButtonBox {
26 pub const NONE: Option<&'static ButtonBox> = None;
27
28 #[doc(alias = "gtk_button_box_new")]
29 pub fn new(orientation: Orientation) -> ButtonBox {
30 assert_initialized_main_thread!();
31 unsafe {
32 Widget::from_glib_none(ffi::gtk_button_box_new(orientation.into_glib())).unsafe_cast()
33 }
34 }
35
36 pub fn builder() -> ButtonBoxBuilder {
41 ButtonBoxBuilder::new()
42 }
43}
44
45impl Default for ButtonBox {
46 fn default() -> Self {
47 glib::object::Object::new::<Self>()
48 }
49}
50
51#[must_use = "The builder must be built to be used"]
56pub struct ButtonBoxBuilder {
57 builder: glib::object::ObjectBuilder<'static, ButtonBox>,
58}
59
60impl ButtonBoxBuilder {
61 fn new() -> Self {
62 Self {
63 builder: glib::object::Object::builder(),
64 }
65 }
66
67 pub fn layout_style(self, layout_style: ButtonBoxStyle) -> Self {
68 Self {
69 builder: self.builder.property("layout-style", layout_style),
70 }
71 }
72
73 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
74 Self {
75 builder: self
76 .builder
77 .property("baseline-position", baseline_position),
78 }
79 }
80
81 pub fn homogeneous(self, homogeneous: bool) -> Self {
82 Self {
83 builder: self.builder.property("homogeneous", homogeneous),
84 }
85 }
86
87 pub fn spacing(self, spacing: i32) -> Self {
88 Self {
89 builder: self.builder.property("spacing", spacing),
90 }
91 }
92
93 pub fn border_width(self, border_width: u32) -> Self {
94 Self {
95 builder: self.builder.property("border-width", border_width),
96 }
97 }
98
99 pub fn child(self, child: &impl IsA<Widget>) -> Self {
100 Self {
101 builder: self.builder.property("child", child.clone().upcast()),
102 }
103 }
104
105 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
106 Self {
107 builder: self.builder.property("resize-mode", resize_mode),
108 }
109 }
110
111 pub fn app_paintable(self, app_paintable: bool) -> Self {
112 Self {
113 builder: self.builder.property("app-paintable", app_paintable),
114 }
115 }
116
117 pub fn can_default(self, can_default: bool) -> Self {
118 Self {
119 builder: self.builder.property("can-default", can_default),
120 }
121 }
122
123 pub fn can_focus(self, can_focus: bool) -> Self {
124 Self {
125 builder: self.builder.property("can-focus", can_focus),
126 }
127 }
128
129 pub fn events(self, events: gdk::EventMask) -> Self {
130 Self {
131 builder: self.builder.property("events", events),
132 }
133 }
134
135 pub fn expand(self, expand: bool) -> Self {
136 Self {
137 builder: self.builder.property("expand", expand),
138 }
139 }
140
141 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
142 Self {
143 builder: self.builder.property("focus-on-click", focus_on_click),
144 }
145 }
146
147 pub fn halign(self, halign: Align) -> Self {
148 Self {
149 builder: self.builder.property("halign", halign),
150 }
151 }
152
153 pub fn has_default(self, has_default: bool) -> Self {
154 Self {
155 builder: self.builder.property("has-default", has_default),
156 }
157 }
158
159 pub fn has_focus(self, has_focus: bool) -> Self {
160 Self {
161 builder: self.builder.property("has-focus", has_focus),
162 }
163 }
164
165 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
166 Self {
167 builder: self.builder.property("has-tooltip", has_tooltip),
168 }
169 }
170
171 pub fn height_request(self, height_request: i32) -> Self {
172 Self {
173 builder: self.builder.property("height-request", height_request),
174 }
175 }
176
177 pub fn hexpand(self, hexpand: bool) -> Self {
178 Self {
179 builder: self.builder.property("hexpand", hexpand),
180 }
181 }
182
183 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
184 Self {
185 builder: self.builder.property("hexpand-set", hexpand_set),
186 }
187 }
188
189 pub fn is_focus(self, is_focus: bool) -> Self {
190 Self {
191 builder: self.builder.property("is-focus", is_focus),
192 }
193 }
194
195 pub fn margin(self, margin: i32) -> Self {
196 Self {
197 builder: self.builder.property("margin", margin),
198 }
199 }
200
201 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
202 Self {
203 builder: self.builder.property("margin-bottom", margin_bottom),
204 }
205 }
206
207 pub fn margin_end(self, margin_end: i32) -> Self {
208 Self {
209 builder: self.builder.property("margin-end", margin_end),
210 }
211 }
212
213 pub fn margin_start(self, margin_start: i32) -> Self {
214 Self {
215 builder: self.builder.property("margin-start", margin_start),
216 }
217 }
218
219 pub fn margin_top(self, margin_top: i32) -> Self {
220 Self {
221 builder: self.builder.property("margin-top", margin_top),
222 }
223 }
224
225 pub fn name(self, name: impl Into<glib::GString>) -> Self {
226 Self {
227 builder: self.builder.property("name", name.into()),
228 }
229 }
230
231 pub fn no_show_all(self, no_show_all: bool) -> Self {
232 Self {
233 builder: self.builder.property("no-show-all", no_show_all),
234 }
235 }
236
237 pub fn opacity(self, opacity: f64) -> Self {
238 Self {
239 builder: self.builder.property("opacity", opacity),
240 }
241 }
242
243 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
244 Self {
245 builder: self.builder.property("parent", parent.clone().upcast()),
246 }
247 }
248
249 pub fn receives_default(self, receives_default: bool) -> Self {
250 Self {
251 builder: self.builder.property("receives-default", receives_default),
252 }
253 }
254
255 pub fn sensitive(self, sensitive: bool) -> Self {
256 Self {
257 builder: self.builder.property("sensitive", sensitive),
258 }
259 }
260
261 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
262 Self {
263 builder: self
264 .builder
265 .property("tooltip-markup", tooltip_markup.into()),
266 }
267 }
268
269 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
270 Self {
271 builder: self.builder.property("tooltip-text", tooltip_text.into()),
272 }
273 }
274
275 pub fn valign(self, valign: Align) -> Self {
276 Self {
277 builder: self.builder.property("valign", valign),
278 }
279 }
280
281 pub fn vexpand(self, vexpand: bool) -> Self {
282 Self {
283 builder: self.builder.property("vexpand", vexpand),
284 }
285 }
286
287 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
288 Self {
289 builder: self.builder.property("vexpand-set", vexpand_set),
290 }
291 }
292
293 pub fn visible(self, visible: bool) -> Self {
294 Self {
295 builder: self.builder.property("visible", visible),
296 }
297 }
298
299 pub fn width_request(self, width_request: i32) -> Self {
300 Self {
301 builder: self.builder.property("width-request", width_request),
302 }
303 }
304
305 pub fn orientation(self, orientation: Orientation) -> Self {
306 Self {
307 builder: self.builder.property("orientation", orientation),
308 }
309 }
310
311 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
314 pub fn build(self) -> ButtonBox {
315 self.builder.build()
316 }
317}
318
319mod sealed {
320 pub trait Sealed {}
321 impl<T: super::IsA<super::ButtonBox>> Sealed for T {}
322}
323
324pub trait ButtonBoxExt: IsA<ButtonBox> + sealed::Sealed + 'static {
325 #[doc(alias = "gtk_button_box_get_child_non_homogeneous")]
326 #[doc(alias = "get_child_non_homogeneous")]
327 fn child_is_non_homogeneous(&self, child: &impl IsA<Widget>) -> bool {
328 unsafe {
329 from_glib(ffi::gtk_button_box_get_child_non_homogeneous(
330 self.as_ref().to_glib_none().0,
331 child.as_ref().to_glib_none().0,
332 ))
333 }
334 }
335
336 #[doc(alias = "gtk_button_box_get_child_secondary")]
337 #[doc(alias = "get_child_secondary")]
338 fn child_is_secondary(&self, child: &impl IsA<Widget>) -> bool {
339 unsafe {
340 from_glib(ffi::gtk_button_box_get_child_secondary(
341 self.as_ref().to_glib_none().0,
342 child.as_ref().to_glib_none().0,
343 ))
344 }
345 }
346
347 #[doc(alias = "gtk_button_box_get_layout")]
348 #[doc(alias = "get_layout")]
349 fn layout(&self) -> ButtonBoxStyle {
350 unsafe {
351 from_glib(ffi::gtk_button_box_get_layout(
352 self.as_ref().to_glib_none().0,
353 ))
354 }
355 }
356
357 #[doc(alias = "gtk_button_box_set_child_non_homogeneous")]
358 fn set_child_non_homogeneous(&self, child: &impl IsA<Widget>, non_homogeneous: bool) {
359 unsafe {
360 ffi::gtk_button_box_set_child_non_homogeneous(
361 self.as_ref().to_glib_none().0,
362 child.as_ref().to_glib_none().0,
363 non_homogeneous.into_glib(),
364 );
365 }
366 }
367
368 #[doc(alias = "gtk_button_box_set_child_secondary")]
369 fn set_child_secondary(&self, child: &impl IsA<Widget>, is_secondary: bool) {
370 unsafe {
371 ffi::gtk_button_box_set_child_secondary(
372 self.as_ref().to_glib_none().0,
373 child.as_ref().to_glib_none().0,
374 is_secondary.into_glib(),
375 );
376 }
377 }
378
379 #[doc(alias = "gtk_button_box_set_layout")]
380 fn set_layout(&self, layout_style: ButtonBoxStyle) {
381 unsafe {
382 ffi::gtk_button_box_set_layout(
383 self.as_ref().to_glib_none().0,
384 layout_style.into_glib(),
385 );
386 }
387 }
388
389 #[doc(alias = "layout-style")]
390 fn layout_style(&self) -> ButtonBoxStyle {
391 ObjectExt::property(self.as_ref(), "layout-style")
392 }
393
394 #[doc(alias = "layout-style")]
395 fn set_layout_style(&self, layout_style: ButtonBoxStyle) {
396 ObjectExt::set_property(self.as_ref(), "layout-style", layout_style)
397 }
398
399 #[doc(alias = "layout-style")]
400 fn connect_layout_style_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
401 unsafe extern "C" fn notify_layout_style_trampoline<
402 P: IsA<ButtonBox>,
403 F: Fn(&P) + 'static,
404 >(
405 this: *mut ffi::GtkButtonBox,
406 _param_spec: glib::ffi::gpointer,
407 f: glib::ffi::gpointer,
408 ) {
409 let f: &F = &*(f as *const F);
410 f(ButtonBox::from_glib_borrow(this).unsafe_cast_ref())
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 b"notify::layout-style\0".as_ptr() as *const _,
417 Some(transmute::<_, unsafe extern "C" fn()>(
418 notify_layout_style_trampoline::<Self, F> as *const (),
419 )),
420 Box_::into_raw(f),
421 )
422 }
423 }
424}
425
426impl<O: IsA<ButtonBox>> ButtonBoxExt for O {}
427
428impl fmt::Display for ButtonBox {
429 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
430 f.write_str("ButtonBox")
431 }
432}