1use crate::{ffi, PreferencesRow};
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 = "AdwButtonRow")]
17 pub struct ButtonRow(Object<ffi::AdwButtonRow, ffi::AdwButtonRowClass>) @extends PreferencesRow, gtk::ListBoxRow, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable;
18
19 match fn {
20 type_ => || ffi::adw_button_row_get_type(),
21 }
22}
23
24impl ButtonRow {
25 #[doc(alias = "adw_button_row_new")]
26 pub fn new() -> ButtonRow {
27 assert_initialized_main_thread!();
28 unsafe { gtk::Widget::from_glib_none(ffi::adw_button_row_new()).unsafe_cast() }
29 }
30
31 pub fn builder() -> ButtonRowBuilder {
36 ButtonRowBuilder::new()
37 }
38
39 #[doc(alias = "adw_button_row_get_end_icon_name")]
40 #[doc(alias = "get_end_icon_name")]
41 #[doc(alias = "end-icon-name")]
42 pub fn end_icon_name(&self) -> Option<glib::GString> {
43 unsafe { from_glib_none(ffi::adw_button_row_get_end_icon_name(self.to_glib_none().0)) }
44 }
45
46 #[doc(alias = "adw_button_row_get_start_icon_name")]
47 #[doc(alias = "get_start_icon_name")]
48 #[doc(alias = "start-icon-name")]
49 pub fn start_icon_name(&self) -> Option<glib::GString> {
50 unsafe {
51 from_glib_none(ffi::adw_button_row_get_start_icon_name(
52 self.to_glib_none().0,
53 ))
54 }
55 }
56
57 #[doc(alias = "adw_button_row_set_end_icon_name")]
58 #[doc(alias = "end-icon-name")]
59 pub fn set_end_icon_name(&self, icon_name: Option<&str>) {
60 unsafe {
61 ffi::adw_button_row_set_end_icon_name(
62 self.to_glib_none().0,
63 icon_name.to_glib_none().0,
64 );
65 }
66 }
67
68 #[doc(alias = "adw_button_row_set_start_icon_name")]
69 #[doc(alias = "start-icon-name")]
70 pub fn set_start_icon_name(&self, icon_name: Option<&str>) {
71 unsafe {
72 ffi::adw_button_row_set_start_icon_name(
73 self.to_glib_none().0,
74 icon_name.to_glib_none().0,
75 );
76 }
77 }
78
79 #[cfg(feature = "v1_6")]
80 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
81 #[doc(alias = "activated")]
82 pub fn connect_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
83 unsafe extern "C" fn activated_trampoline<F: Fn(&ButtonRow) + 'static>(
84 this: *mut ffi::AdwButtonRow,
85 f: glib::ffi::gpointer,
86 ) {
87 let f: &F = &*(f as *const F);
88 f(&from_glib_borrow(this))
89 }
90 unsafe {
91 let f: Box_<F> = Box_::new(f);
92 connect_raw(
93 self.as_ptr() as *mut _,
94 c"activated".as_ptr() as *const _,
95 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
96 activated_trampoline::<F> as *const (),
97 )),
98 Box_::into_raw(f),
99 )
100 }
101 }
102
103 #[cfg(feature = "v1_6")]
104 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
105 #[doc(alias = "end-icon-name")]
106 pub fn connect_end_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
107 unsafe extern "C" fn notify_end_icon_name_trampoline<F: Fn(&ButtonRow) + 'static>(
108 this: *mut ffi::AdwButtonRow,
109 _param_spec: glib::ffi::gpointer,
110 f: glib::ffi::gpointer,
111 ) {
112 let f: &F = &*(f as *const F);
113 f(&from_glib_borrow(this))
114 }
115 unsafe {
116 let f: Box_<F> = Box_::new(f);
117 connect_raw(
118 self.as_ptr() as *mut _,
119 c"notify::end-icon-name".as_ptr() as *const _,
120 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
121 notify_end_icon_name_trampoline::<F> as *const (),
122 )),
123 Box_::into_raw(f),
124 )
125 }
126 }
127
128 #[cfg(feature = "v1_6")]
129 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
130 #[doc(alias = "start-icon-name")]
131 pub fn connect_start_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
132 unsafe extern "C" fn notify_start_icon_name_trampoline<F: Fn(&ButtonRow) + 'static>(
133 this: *mut ffi::AdwButtonRow,
134 _param_spec: glib::ffi::gpointer,
135 f: glib::ffi::gpointer,
136 ) {
137 let f: &F = &*(f as *const F);
138 f(&from_glib_borrow(this))
139 }
140 unsafe {
141 let f: Box_<F> = Box_::new(f);
142 connect_raw(
143 self.as_ptr() as *mut _,
144 c"notify::start-icon-name".as_ptr() as *const _,
145 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
146 notify_start_icon_name_trampoline::<F> as *const (),
147 )),
148 Box_::into_raw(f),
149 )
150 }
151 }
152}
153
154#[cfg(feature = "v1_6")]
155#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
156impl Default for ButtonRow {
157 fn default() -> Self {
158 Self::new()
159 }
160}
161
162#[must_use = "The builder must be built to be used"]
167pub struct ButtonRowBuilder {
168 builder: glib::object::ObjectBuilder<'static, ButtonRow>,
169}
170
171impl ButtonRowBuilder {
172 fn new() -> Self {
173 Self {
174 builder: glib::object::Object::builder(),
175 }
176 }
177
178 #[cfg(feature = "v1_6")]
179 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
180 pub fn end_icon_name(self, end_icon_name: impl Into<glib::GString>) -> Self {
181 Self {
182 builder: self.builder.property("end-icon-name", end_icon_name.into()),
183 }
184 }
185
186 #[cfg(feature = "v1_6")]
187 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
188 pub fn start_icon_name(self, start_icon_name: impl Into<glib::GString>) -> Self {
189 Self {
190 builder: self
191 .builder
192 .property("start-icon-name", start_icon_name.into()),
193 }
194 }
195
196 pub fn title(self, title: impl Into<glib::GString>) -> Self {
197 Self {
198 builder: self.builder.property("title", title.into()),
199 }
200 }
201
202 #[cfg(feature = "v1_1")]
203 #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
204 pub fn title_selectable(self, title_selectable: bool) -> Self {
205 Self {
206 builder: self.builder.property("title-selectable", title_selectable),
207 }
208 }
209
210 #[cfg(feature = "v1_2")]
211 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
212 pub fn use_markup(self, use_markup: bool) -> Self {
213 Self {
214 builder: self.builder.property("use-markup", use_markup),
215 }
216 }
217
218 pub fn use_underline(self, use_underline: bool) -> Self {
219 Self {
220 builder: self.builder.property("use-underline", use_underline),
221 }
222 }
223
224 pub fn activatable(self, activatable: bool) -> Self {
225 Self {
226 builder: self.builder.property("activatable", activatable),
227 }
228 }
229
230 pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
231 Self {
232 builder: self.builder.property("child", child.clone().upcast()),
233 }
234 }
235
236 pub fn selectable(self, selectable: bool) -> Self {
237 Self {
238 builder: self.builder.property("selectable", selectable),
239 }
240 }
241
242 pub fn can_focus(self, can_focus: bool) -> Self {
243 Self {
244 builder: self.builder.property("can-focus", can_focus),
245 }
246 }
247
248 pub fn can_target(self, can_target: bool) -> Self {
249 Self {
250 builder: self.builder.property("can-target", can_target),
251 }
252 }
253
254 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
255 Self {
256 builder: self.builder.property("css-classes", css_classes.into()),
257 }
258 }
259
260 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
261 Self {
262 builder: self.builder.property("css-name", css_name.into()),
263 }
264 }
265
266 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
267 Self {
268 builder: self.builder.property("cursor", cursor.clone()),
269 }
270 }
271
272 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
273 Self {
274 builder: self.builder.property("focus-on-click", focus_on_click),
275 }
276 }
277
278 pub fn focusable(self, focusable: bool) -> Self {
279 Self {
280 builder: self.builder.property("focusable", focusable),
281 }
282 }
283
284 pub fn halign(self, halign: gtk::Align) -> Self {
285 Self {
286 builder: self.builder.property("halign", halign),
287 }
288 }
289
290 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
291 Self {
292 builder: self.builder.property("has-tooltip", has_tooltip),
293 }
294 }
295
296 pub fn height_request(self, height_request: i32) -> Self {
297 Self {
298 builder: self.builder.property("height-request", height_request),
299 }
300 }
301
302 pub fn hexpand(self, hexpand: bool) -> Self {
303 Self {
304 builder: self.builder.property("hexpand", hexpand),
305 }
306 }
307
308 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
309 Self {
310 builder: self.builder.property("hexpand-set", hexpand_set),
311 }
312 }
313
314 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
315 Self {
316 builder: self
317 .builder
318 .property("layout-manager", layout_manager.clone().upcast()),
319 }
320 }
321
322 #[cfg(feature = "gtk_v4_18")]
323 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
324 pub fn limit_events(self, limit_events: bool) -> Self {
325 Self {
326 builder: self.builder.property("limit-events", limit_events),
327 }
328 }
329
330 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
331 Self {
332 builder: self.builder.property("margin-bottom", margin_bottom),
333 }
334 }
335
336 pub fn margin_end(self, margin_end: i32) -> Self {
337 Self {
338 builder: self.builder.property("margin-end", margin_end),
339 }
340 }
341
342 pub fn margin_start(self, margin_start: i32) -> Self {
343 Self {
344 builder: self.builder.property("margin-start", margin_start),
345 }
346 }
347
348 pub fn margin_top(self, margin_top: i32) -> Self {
349 Self {
350 builder: self.builder.property("margin-top", margin_top),
351 }
352 }
353
354 pub fn name(self, name: impl Into<glib::GString>) -> Self {
355 Self {
356 builder: self.builder.property("name", name.into()),
357 }
358 }
359
360 pub fn opacity(self, opacity: f64) -> Self {
361 Self {
362 builder: self.builder.property("opacity", opacity),
363 }
364 }
365
366 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
367 Self {
368 builder: self.builder.property("overflow", overflow),
369 }
370 }
371
372 pub fn receives_default(self, receives_default: bool) -> Self {
373 Self {
374 builder: self.builder.property("receives-default", receives_default),
375 }
376 }
377
378 pub fn sensitive(self, sensitive: bool) -> Self {
379 Self {
380 builder: self.builder.property("sensitive", sensitive),
381 }
382 }
383
384 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
385 Self {
386 builder: self
387 .builder
388 .property("tooltip-markup", tooltip_markup.into()),
389 }
390 }
391
392 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
393 Self {
394 builder: self.builder.property("tooltip-text", tooltip_text.into()),
395 }
396 }
397
398 pub fn valign(self, valign: gtk::Align) -> Self {
399 Self {
400 builder: self.builder.property("valign", valign),
401 }
402 }
403
404 pub fn vexpand(self, vexpand: bool) -> Self {
405 Self {
406 builder: self.builder.property("vexpand", vexpand),
407 }
408 }
409
410 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
411 Self {
412 builder: self.builder.property("vexpand-set", vexpand_set),
413 }
414 }
415
416 pub fn visible(self, visible: bool) -> Self {
417 Self {
418 builder: self.builder.property("visible", visible),
419 }
420 }
421
422 pub fn width_request(self, width_request: i32) -> Self {
423 Self {
424 builder: self.builder.property("width-request", width_request),
425 }
426 }
427
428 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
429 Self {
430 builder: self.builder.property("accessible-role", accessible_role),
431 }
432 }
433
434 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
435 Self {
436 builder: self.builder.property("action-name", action_name.into()),
437 }
438 }
439
440 pub fn action_target(self, action_target: &glib::Variant) -> Self {
441 Self {
442 builder: self
443 .builder
444 .property("action-target", action_target.clone()),
445 }
446 }
447
448 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
451 pub fn build(self) -> ButtonRow {
452 assert_initialized_main_thread!();
453 self.builder.build()
454 }
455}