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