libadwaita/auto/button_content.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::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// A helper widget for creating buttons.
16 ///
17 /// <picture>
18 /// <source srcset="button-content-dark.png" media="(prefers-color-scheme: dark)">
19 /// <img src="button-content.png" alt="button-content">
20 /// </picture>
21 ///
22 /// [`ButtonContent`][crate::ButtonContent] is a box-like widget with an icon and a label.
23 ///
24 /// It's intended to be used as a direct child of `Gtk::Button`,
25 /// `Gtk::MenuButton` or [`SplitButton`][crate::SplitButton], when they need to have both an
26 /// icon and a label, as follows:
27 ///
28 /// ```xml
29 /// <object class="GtkButton">
30 /// <property name="child">
31 /// <object class="AdwButtonContent">
32 /// <property name="icon-name">document-open-symbolic</property>
33 /// <property name="label" translatable="yes">_Open</property>
34 /// <property name="use-underline">True</property>
35 /// </object>
36 /// </property>
37 /// </object>
38 /// ```
39 ///
40 /// [`ButtonContent`][crate::ButtonContent] handles style classes and connecting the mnemonic to the
41 /// button automatically.
42 ///
43 /// ## CSS nodes
44 ///
45 /// ```text
46 /// buttoncontent
47 /// ╰── box
48 /// ├── image
49 /// ╰── label
50 /// ```
51 ///
52 /// [`ButtonContent`][crate::ButtonContent]'s CSS node is called `buttoncontent`. It contains a `box`
53 /// subnode that serves as a container for the `image` and `label` nodes.
54 ///
55 /// When inside a `GtkButton` or [`SplitButton`][crate::SplitButton], the button will receive the
56 /// `.image-text-button` style class. When inside a `GtkMenuButton`, the
57 /// internal `GtkButton` will receive it instead.
58 ///
59 /// ## Accessibility
60 ///
61 /// [`ButtonContent`][crate::ButtonContent] uses the [enum@Gtk.AccessibleRole.group] role.
62 ///
63 /// ## Properties
64 ///
65 ///
66 /// #### `can-shrink`
67 /// Whether the button can be smaller than the natural size of its contents.
68 ///
69 /// If set to `TRUE`, the label will ellipsize.
70 ///
71 /// See [`can-shrink`][struct@crate::Gtk::Button#can-shrink].
72 ///
73 /// Readable | Writeable
74 ///
75 ///
76 /// #### `icon-name`
77 /// The name of the displayed icon.
78 ///
79 /// If empty, the icon is not shown.
80 ///
81 /// Readable | Writeable
82 ///
83 ///
84 /// #### `label`
85 /// The displayed label.
86 ///
87 /// Readable | Writeable
88 ///
89 ///
90 /// #### `use-underline`
91 /// Whether an underline in the text indicates a mnemonic.
92 ///
93 /// The mnemonic can be used to activate the parent button.
94 ///
95 /// See [`label`][struct@crate::ButtonContent#label].
96 ///
97 /// Readable | Writeable
98 /// <details><summary><h4>Widget</h4></summary>
99 ///
100 ///
101 /// #### `can-focus`
102 /// Whether the widget or any of its descendents can accept
103 /// the input focus.
104 ///
105 /// This property is meant to be set by widget implementations,
106 /// typically in their instance init function.
107 ///
108 /// Readable | Writeable
109 ///
110 ///
111 /// #### `can-target`
112 /// Whether the widget can receive pointer events.
113 ///
114 /// Readable | Writeable
115 ///
116 ///
117 /// #### `css-classes`
118 /// A list of css classes applied to this widget.
119 ///
120 /// Readable | Writeable
121 ///
122 ///
123 /// #### `css-name`
124 /// The name of this widget in the CSS tree.
125 ///
126 /// This property is meant to be set by widget implementations,
127 /// typically in their instance init function.
128 ///
129 /// Readable | Writeable | Construct Only
130 ///
131 ///
132 /// #### `cursor`
133 /// The cursor used by @widget.
134 ///
135 /// Readable | Writeable
136 ///
137 ///
138 /// #### `focus-on-click`
139 /// Whether the widget should grab focus when it is clicked with the mouse.
140 ///
141 /// This property is only relevant for widgets that can take focus.
142 ///
143 /// Readable | Writeable
144 ///
145 ///
146 /// #### `focusable`
147 /// Whether this widget itself will accept the input focus.
148 ///
149 /// Readable | Writeable
150 ///
151 ///
152 /// #### `halign`
153 /// How to distribute horizontal space if widget gets extra space.
154 ///
155 /// Readable | Writeable
156 ///
157 ///
158 /// #### `has-default`
159 /// Whether the widget is the default widget.
160 ///
161 /// Readable
162 ///
163 ///
164 /// #### `has-focus`
165 /// Whether the widget has the input focus.
166 ///
167 /// Readable
168 ///
169 ///
170 /// #### `has-tooltip`
171 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip]
172 /// signal on @widget.
173 ///
174 /// A true value indicates that @widget can have a tooltip, in this case
175 /// the widget will be queried using [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] to
176 /// determine whether it will provide a tooltip or not.
177 ///
178 /// Readable | Writeable
179 ///
180 ///
181 /// #### `height-request`
182 /// Overrides for height request of the widget.
183 ///
184 /// If this is -1, the natural request will be used.
185 ///
186 /// Readable | Writeable
187 ///
188 ///
189 /// #### `hexpand`
190 /// Whether to expand horizontally.
191 ///
192 /// Readable | Writeable
193 ///
194 ///
195 /// #### `hexpand-set`
196 /// Whether to use the `hexpand` property.
197 ///
198 /// Readable | Writeable
199 ///
200 ///
201 /// #### `layout-manager`
202 /// The [`gtk::LayoutManager`][crate::gtk::LayoutManager] instance to use to compute
203 /// the preferred size of the widget, and allocate its children.
204 ///
205 /// This property is meant to be set by widget implementations,
206 /// typically in their instance init function.
207 ///
208 /// Readable | Writeable
209 ///
210 ///
211 /// #### `limit-events`
212 /// Makes this widget act like a modal dialog, with respect to
213 /// event delivery.
214 ///
215 /// Global event controllers will not handle events with targets
216 /// inside the widget, unless they are set up to ignore propagation
217 /// limits. See `Gtk::EventController::set_propagation_limit()`.
218 ///
219 /// Readable | Writeable
220 ///
221 ///
222 /// #### `margin-bottom`
223 /// Margin on bottom side of widget.
224 ///
225 /// This property adds margin outside of the widget's normal size
226 /// request, the margin will be added in addition to the size from
227 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
228 ///
229 /// Readable | Writeable
230 ///
231 ///
232 /// #### `margin-end`
233 /// Margin on end of widget, horizontally.
234 ///
235 /// This property supports left-to-right and right-to-left text
236 /// directions.
237 ///
238 /// This property adds margin outside of the widget's normal size
239 /// request, the margin will be added in addition to the size from
240 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
241 ///
242 /// Readable | Writeable
243 ///
244 ///
245 /// #### `margin-start`
246 /// Margin on start of widget, horizontally.
247 ///
248 /// This property supports left-to-right and right-to-left text
249 /// directions.
250 ///
251 /// This property adds margin outside of the widget's normal size
252 /// request, the margin will be added in addition to the size from
253 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
254 ///
255 /// Readable | Writeable
256 ///
257 ///
258 /// #### `margin-top`
259 /// Margin on top side of widget.
260 ///
261 /// This property adds margin outside of the widget's normal size
262 /// request, the margin will be added in addition to the size from
263 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
264 ///
265 /// Readable | Writeable
266 ///
267 ///
268 /// #### `name`
269 /// The name of the widget.
270 ///
271 /// Readable | Writeable
272 ///
273 ///
274 /// #### `opacity`
275 /// The requested opacity of the widget.
276 ///
277 /// Readable | Writeable
278 ///
279 ///
280 /// #### `overflow`
281 /// How content outside the widget's content area is treated.
282 ///
283 /// This property is meant to be set by widget implementations,
284 /// typically in their instance init function.
285 ///
286 /// Readable | Writeable
287 ///
288 ///
289 /// #### `parent`
290 /// The parent widget of this widget.
291 ///
292 /// Readable
293 ///
294 ///
295 /// #### `receives-default`
296 /// Whether the widget will receive the default action when it is focused.
297 ///
298 /// Readable | Writeable
299 ///
300 ///
301 /// #### `root`
302 /// The [`gtk::Root`][crate::gtk::Root] widget of the widget tree containing this widget.
303 ///
304 /// This will be `NULL` if the widget is not contained in a root widget.
305 ///
306 /// Readable
307 ///
308 ///
309 /// #### `scale-factor`
310 /// The scale factor of the widget.
311 ///
312 /// Readable
313 ///
314 ///
315 /// #### `sensitive`
316 /// Whether the widget responds to input.
317 ///
318 /// Readable | Writeable
319 ///
320 ///
321 /// #### `tooltip-markup`
322 /// Sets the text of tooltip to be the given string, which is marked up
323 /// with Pango markup.
324 ///
325 /// Also see `Gtk::Tooltip::set_markup()`.
326 ///
327 /// This is a convenience property which will take care of getting the
328 /// tooltip shown if the given string is not `NULL`:
329 /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
330 /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
331 /// the default signal handler.
332 ///
333 /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
334 /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
335 ///
336 /// Readable | Writeable
337 ///
338 ///
339 /// #### `tooltip-text`
340 /// Sets the text of tooltip to be the given string.
341 ///
342 /// Also see `Gtk::Tooltip::set_text()`.
343 ///
344 /// This is a convenience property which will take care of getting the
345 /// tooltip shown if the given string is not `NULL`:
346 /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
347 /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
348 /// the default signal handler.
349 ///
350 /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
351 /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
352 ///
353 /// Readable | Writeable
354 ///
355 ///
356 /// #### `valign`
357 /// How to distribute vertical space if widget gets extra space.
358 ///
359 /// Readable | Writeable
360 ///
361 ///
362 /// #### `vexpand`
363 /// Whether to expand vertically.
364 ///
365 /// Readable | Writeable
366 ///
367 ///
368 /// #### `vexpand-set`
369 /// Whether to use the `vexpand` property.
370 ///
371 /// Readable | Writeable
372 ///
373 ///
374 /// #### `visible`
375 /// Whether the widget is visible.
376 ///
377 /// Readable | Writeable
378 ///
379 ///
380 /// #### `width-request`
381 /// Overrides for width request of the widget.
382 ///
383 /// If this is -1, the natural request will be used.
384 ///
385 /// Readable | Writeable
386 /// </details>
387 /// <details><summary><h4>Accessible</h4></summary>
388 ///
389 ///
390 /// #### `accessible-role`
391 /// The accessible role of the given [`gtk::Accessible`][crate::gtk::Accessible] implementation.
392 ///
393 /// The accessible role cannot be changed once set.
394 ///
395 /// Readable | Writeable
396 /// </details>
397 ///
398 /// # Implements
399 ///
400 /// [`trait@gtk::prelude::WidgetExt`], [`trait@glib::ObjectExt`], [`trait@gtk::prelude::AccessibleExt`], [`trait@gtk::prelude::BuildableExt`], [`trait@gtk::prelude::ConstraintTargetExt`]
401 #[doc(alias = "AdwButtonContent")]
402 pub struct ButtonContent(Object<ffi::AdwButtonContent, ffi::AdwButtonContentClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
403
404 match fn {
405 type_ => || ffi::adw_button_content_get_type(),
406 }
407}
408
409impl ButtonContent {
410 /// Creates a new [`ButtonContent`][crate::ButtonContent].
411 ///
412 /// # Returns
413 ///
414 /// the new created [`ButtonContent`][crate::ButtonContent]
415 #[doc(alias = "adw_button_content_new")]
416 pub fn new() -> ButtonContent {
417 assert_initialized_main_thread!();
418 unsafe { gtk::Widget::from_glib_none(ffi::adw_button_content_new()).unsafe_cast() }
419 }
420
421 // rustdoc-stripper-ignore-next
422 /// Creates a new builder-pattern struct instance to construct [`ButtonContent`] objects.
423 ///
424 /// This method returns an instance of [`ButtonContentBuilder`](crate::builders::ButtonContentBuilder) which can be used to create [`ButtonContent`] objects.
425 pub fn builder() -> ButtonContentBuilder {
426 ButtonContentBuilder::new()
427 }
428
429 /// gets whether the button can be smaller than the natural size of its contents.
430 ///
431 /// # Returns
432 ///
433 /// whether the button can shrink
434 #[cfg(feature = "v1_4")]
435 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
436 #[doc(alias = "adw_button_content_get_can_shrink")]
437 #[doc(alias = "get_can_shrink")]
438 #[doc(alias = "can-shrink")]
439 pub fn can_shrink(&self) -> bool {
440 unsafe {
441 from_glib(ffi::adw_button_content_get_can_shrink(
442 self.to_glib_none().0,
443 ))
444 }
445 }
446
447 /// Gets the name of the displayed icon.
448 ///
449 /// # Returns
450 ///
451 /// the icon name
452 #[doc(alias = "adw_button_content_get_icon_name")]
453 #[doc(alias = "get_icon_name")]
454 #[doc(alias = "icon-name")]
455 pub fn icon_name(&self) -> glib::GString {
456 unsafe { from_glib_none(ffi::adw_button_content_get_icon_name(self.to_glib_none().0)) }
457 }
458
459 /// Gets the displayed label.
460 ///
461 /// # Returns
462 ///
463 /// the label
464 #[doc(alias = "adw_button_content_get_label")]
465 #[doc(alias = "get_label")]
466 pub fn label(&self) -> glib::GString {
467 unsafe { from_glib_none(ffi::adw_button_content_get_label(self.to_glib_none().0)) }
468 }
469
470 /// Gets whether an underline in the text indicates a mnemonic.
471 ///
472 /// # Returns
473 ///
474 /// whether an underline in the text indicates a mnemonic
475 #[doc(alias = "adw_button_content_get_use_underline")]
476 #[doc(alias = "get_use_underline")]
477 #[doc(alias = "use-underline")]
478 pub fn uses_underline(&self) -> bool {
479 unsafe {
480 from_glib(ffi::adw_button_content_get_use_underline(
481 self.to_glib_none().0,
482 ))
483 }
484 }
485
486 /// Sets whether the button can be smaller than the natural size of its contents.
487 ///
488 /// If set to `TRUE`, the label will ellipsize.
489 ///
490 /// See `Gtk::Button::set_can_shrink()`.
491 /// ## `can_shrink`
492 /// whether the button can shrink
493 #[cfg(feature = "v1_4")]
494 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
495 #[doc(alias = "adw_button_content_set_can_shrink")]
496 #[doc(alias = "can-shrink")]
497 pub fn set_can_shrink(&self, can_shrink: bool) {
498 unsafe {
499 ffi::adw_button_content_set_can_shrink(self.to_glib_none().0, can_shrink.into_glib());
500 }
501 }
502
503 /// Sets the name of the displayed icon.
504 ///
505 /// If empty, the icon is not shown.
506 /// ## `icon_name`
507 /// the new icon name
508 #[doc(alias = "adw_button_content_set_icon_name")]
509 #[doc(alias = "icon-name")]
510 pub fn set_icon_name(&self, icon_name: &str) {
511 unsafe {
512 ffi::adw_button_content_set_icon_name(
513 self.to_glib_none().0,
514 icon_name.to_glib_none().0,
515 );
516 }
517 }
518
519 /// Sets the displayed label.
520 /// ## `label`
521 /// the new label
522 #[doc(alias = "adw_button_content_set_label")]
523 #[doc(alias = "label")]
524 pub fn set_label(&self, label: &str) {
525 unsafe {
526 ffi::adw_button_content_set_label(self.to_glib_none().0, label.to_glib_none().0);
527 }
528 }
529
530 /// Sets whether an underline in the text indicates a mnemonic.
531 ///
532 /// The mnemonic can be used to activate the parent button.
533 ///
534 /// See [`label`][struct@crate::ButtonContent#label].
535 /// ## `use_underline`
536 /// whether an underline in the text indicates a mnemonic
537 #[doc(alias = "adw_button_content_set_use_underline")]
538 #[doc(alias = "use-underline")]
539 pub fn set_use_underline(&self, use_underline: bool) {
540 unsafe {
541 ffi::adw_button_content_set_use_underline(
542 self.to_glib_none().0,
543 use_underline.into_glib(),
544 );
545 }
546 }
547
548 #[cfg(feature = "v1_4")]
549 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
550 #[doc(alias = "can-shrink")]
551 pub fn connect_can_shrink_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
552 unsafe extern "C" fn notify_can_shrink_trampoline<F: Fn(&ButtonContent) + 'static>(
553 this: *mut ffi::AdwButtonContent,
554 _param_spec: glib::ffi::gpointer,
555 f: glib::ffi::gpointer,
556 ) {
557 unsafe {
558 let f: &F = &*(f as *const F);
559 f(&from_glib_borrow(this))
560 }
561 }
562 unsafe {
563 let f: Box_<F> = Box_::new(f);
564 connect_raw(
565 self.as_ptr() as *mut _,
566 c"notify::can-shrink".as_ptr() as *const _,
567 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
568 notify_can_shrink_trampoline::<F> as *const (),
569 )),
570 Box_::into_raw(f),
571 )
572 }
573 }
574
575 #[doc(alias = "icon-name")]
576 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
577 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&ButtonContent) + 'static>(
578 this: *mut ffi::AdwButtonContent,
579 _param_spec: glib::ffi::gpointer,
580 f: glib::ffi::gpointer,
581 ) {
582 unsafe {
583 let f: &F = &*(f as *const F);
584 f(&from_glib_borrow(this))
585 }
586 }
587 unsafe {
588 let f: Box_<F> = Box_::new(f);
589 connect_raw(
590 self.as_ptr() as *mut _,
591 c"notify::icon-name".as_ptr() as *const _,
592 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
593 notify_icon_name_trampoline::<F> as *const (),
594 )),
595 Box_::into_raw(f),
596 )
597 }
598 }
599
600 #[doc(alias = "label")]
601 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
602 unsafe extern "C" fn notify_label_trampoline<F: Fn(&ButtonContent) + 'static>(
603 this: *mut ffi::AdwButtonContent,
604 _param_spec: glib::ffi::gpointer,
605 f: glib::ffi::gpointer,
606 ) {
607 unsafe {
608 let f: &F = &*(f as *const F);
609 f(&from_glib_borrow(this))
610 }
611 }
612 unsafe {
613 let f: Box_<F> = Box_::new(f);
614 connect_raw(
615 self.as_ptr() as *mut _,
616 c"notify::label".as_ptr() as *const _,
617 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
618 notify_label_trampoline::<F> as *const (),
619 )),
620 Box_::into_raw(f),
621 )
622 }
623 }
624
625 #[doc(alias = "use-underline")]
626 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
627 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&ButtonContent) + 'static>(
628 this: *mut ffi::AdwButtonContent,
629 _param_spec: glib::ffi::gpointer,
630 f: glib::ffi::gpointer,
631 ) {
632 unsafe {
633 let f: &F = &*(f as *const F);
634 f(&from_glib_borrow(this))
635 }
636 }
637 unsafe {
638 let f: Box_<F> = Box_::new(f);
639 connect_raw(
640 self.as_ptr() as *mut _,
641 c"notify::use-underline".as_ptr() as *const _,
642 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
643 notify_use_underline_trampoline::<F> as *const (),
644 )),
645 Box_::into_raw(f),
646 )
647 }
648 }
649}
650
651impl Default for ButtonContent {
652 fn default() -> Self {
653 Self::new()
654 }
655}
656
657// rustdoc-stripper-ignore-next
658/// A [builder-pattern] type to construct [`ButtonContent`] objects.
659///
660/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
661#[must_use = "The builder must be built to be used"]
662pub struct ButtonContentBuilder {
663 builder: glib::object::ObjectBuilder<'static, ButtonContent>,
664}
665
666impl ButtonContentBuilder {
667 fn new() -> Self {
668 Self {
669 builder: glib::object::Object::builder(),
670 }
671 }
672
673 /// Whether the button can be smaller than the natural size of its contents.
674 ///
675 /// If set to `TRUE`, the label will ellipsize.
676 ///
677 /// See [`can-shrink`][struct@crate::Gtk::Button#can-shrink].
678 #[cfg(feature = "v1_4")]
679 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
680 pub fn can_shrink(self, can_shrink: bool) -> Self {
681 Self {
682 builder: self.builder.property("can-shrink", can_shrink),
683 }
684 }
685
686 /// The name of the displayed icon.
687 ///
688 /// If empty, the icon is not shown.
689 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
690 Self {
691 builder: self.builder.property("icon-name", icon_name.into()),
692 }
693 }
694
695 /// The displayed label.
696 pub fn label(self, label: impl Into<glib::GString>) -> Self {
697 Self {
698 builder: self.builder.property("label", label.into()),
699 }
700 }
701
702 /// Whether an underline in the text indicates a mnemonic.
703 ///
704 /// The mnemonic can be used to activate the parent button.
705 ///
706 /// See [`label`][struct@crate::ButtonContent#label].
707 pub fn use_underline(self, use_underline: bool) -> Self {
708 Self {
709 builder: self.builder.property("use-underline", use_underline),
710 }
711 }
712
713 /// Whether the widget or any of its descendents can accept
714 /// the input focus.
715 ///
716 /// This property is meant to be set by widget implementations,
717 /// typically in their instance init function.
718 pub fn can_focus(self, can_focus: bool) -> Self {
719 Self {
720 builder: self.builder.property("can-focus", can_focus),
721 }
722 }
723
724 /// Whether the widget can receive pointer events.
725 pub fn can_target(self, can_target: bool) -> Self {
726 Self {
727 builder: self.builder.property("can-target", can_target),
728 }
729 }
730
731 /// A list of css classes applied to this widget.
732 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
733 Self {
734 builder: self.builder.property("css-classes", css_classes.into()),
735 }
736 }
737
738 /// The name of this widget in the CSS tree.
739 ///
740 /// This property is meant to be set by widget implementations,
741 /// typically in their instance init function.
742 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
743 Self {
744 builder: self.builder.property("css-name", css_name.into()),
745 }
746 }
747
748 /// The cursor used by @widget.
749 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
750 Self {
751 builder: self.builder.property("cursor", cursor.clone()),
752 }
753 }
754
755 /// Whether the widget should grab focus when it is clicked with the mouse.
756 ///
757 /// This property is only relevant for widgets that can take focus.
758 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
759 Self {
760 builder: self.builder.property("focus-on-click", focus_on_click),
761 }
762 }
763
764 /// Whether this widget itself will accept the input focus.
765 pub fn focusable(self, focusable: bool) -> Self {
766 Self {
767 builder: self.builder.property("focusable", focusable),
768 }
769 }
770
771 /// How to distribute horizontal space if widget gets extra space.
772 pub fn halign(self, halign: gtk::Align) -> Self {
773 Self {
774 builder: self.builder.property("halign", halign),
775 }
776 }
777
778 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip]
779 /// signal on @widget.
780 ///
781 /// A true value indicates that @widget can have a tooltip, in this case
782 /// the widget will be queried using [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] to
783 /// determine whether it will provide a tooltip or not.
784 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
785 Self {
786 builder: self.builder.property("has-tooltip", has_tooltip),
787 }
788 }
789
790 /// Overrides for height request of the widget.
791 ///
792 /// If this is -1, the natural request will be used.
793 pub fn height_request(self, height_request: i32) -> Self {
794 Self {
795 builder: self.builder.property("height-request", height_request),
796 }
797 }
798
799 /// Whether to expand horizontally.
800 pub fn hexpand(self, hexpand: bool) -> Self {
801 Self {
802 builder: self.builder.property("hexpand", hexpand),
803 }
804 }
805
806 /// Whether to use the `hexpand` property.
807 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
808 Self {
809 builder: self.builder.property("hexpand-set", hexpand_set),
810 }
811 }
812
813 /// The [`gtk::LayoutManager`][crate::gtk::LayoutManager] instance to use to compute
814 /// the preferred size of the widget, and allocate its children.
815 ///
816 /// This property is meant to be set by widget implementations,
817 /// typically in their instance init function.
818 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
819 Self {
820 builder: self
821 .builder
822 .property("layout-manager", layout_manager.clone().upcast()),
823 }
824 }
825
826 /// Makes this widget act like a modal dialog, with respect to
827 /// event delivery.
828 ///
829 /// Global event controllers will not handle events with targets
830 /// inside the widget, unless they are set up to ignore propagation
831 /// limits. See `Gtk::EventController::set_propagation_limit()`.
832 #[cfg(feature = "gtk_v4_18")]
833 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
834 pub fn limit_events(self, limit_events: bool) -> Self {
835 Self {
836 builder: self.builder.property("limit-events", limit_events),
837 }
838 }
839
840 /// Margin on bottom side of widget.
841 ///
842 /// This property adds margin outside of the widget's normal size
843 /// request, the margin will be added in addition to the size from
844 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
845 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
846 Self {
847 builder: self.builder.property("margin-bottom", margin_bottom),
848 }
849 }
850
851 /// Margin on end of widget, horizontally.
852 ///
853 /// This property supports left-to-right and right-to-left text
854 /// directions.
855 ///
856 /// This property adds margin outside of the widget's normal size
857 /// request, the margin will be added in addition to the size from
858 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
859 pub fn margin_end(self, margin_end: i32) -> Self {
860 Self {
861 builder: self.builder.property("margin-end", margin_end),
862 }
863 }
864
865 /// Margin on start of widget, horizontally.
866 ///
867 /// This property supports left-to-right and right-to-left text
868 /// directions.
869 ///
870 /// This property adds margin outside of the widget's normal size
871 /// request, the margin will be added in addition to the size from
872 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
873 pub fn margin_start(self, margin_start: i32) -> Self {
874 Self {
875 builder: self.builder.property("margin-start", margin_start),
876 }
877 }
878
879 /// Margin on top side of widget.
880 ///
881 /// This property adds margin outside of the widget's normal size
882 /// request, the margin will be added in addition to the size from
883 /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
884 pub fn margin_top(self, margin_top: i32) -> Self {
885 Self {
886 builder: self.builder.property("margin-top", margin_top),
887 }
888 }
889
890 /// The name of the widget.
891 pub fn name(self, name: impl Into<glib::GString>) -> Self {
892 Self {
893 builder: self.builder.property("name", name.into()),
894 }
895 }
896
897 /// The requested opacity of the widget.
898 pub fn opacity(self, opacity: f64) -> Self {
899 Self {
900 builder: self.builder.property("opacity", opacity),
901 }
902 }
903
904 /// How content outside the widget's content area is treated.
905 ///
906 /// This property is meant to be set by widget implementations,
907 /// typically in their instance init function.
908 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
909 Self {
910 builder: self.builder.property("overflow", overflow),
911 }
912 }
913
914 /// Whether the widget will receive the default action when it is focused.
915 pub fn receives_default(self, receives_default: bool) -> Self {
916 Self {
917 builder: self.builder.property("receives-default", receives_default),
918 }
919 }
920
921 /// Whether the widget responds to input.
922 pub fn sensitive(self, sensitive: bool) -> Self {
923 Self {
924 builder: self.builder.property("sensitive", sensitive),
925 }
926 }
927
928 /// Sets the text of tooltip to be the given string, which is marked up
929 /// with Pango markup.
930 ///
931 /// Also see `Gtk::Tooltip::set_markup()`.
932 ///
933 /// This is a convenience property which will take care of getting the
934 /// tooltip shown if the given string is not `NULL`:
935 /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
936 /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
937 /// the default signal handler.
938 ///
939 /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
940 /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
941 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
942 Self {
943 builder: self
944 .builder
945 .property("tooltip-markup", tooltip_markup.into()),
946 }
947 }
948
949 /// Sets the text of tooltip to be the given string.
950 ///
951 /// Also see `Gtk::Tooltip::set_text()`.
952 ///
953 /// This is a convenience property which will take care of getting the
954 /// tooltip shown if the given string is not `NULL`:
955 /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
956 /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
957 /// the default signal handler.
958 ///
959 /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
960 /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
961 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
962 Self {
963 builder: self.builder.property("tooltip-text", tooltip_text.into()),
964 }
965 }
966
967 /// How to distribute vertical space if widget gets extra space.
968 pub fn valign(self, valign: gtk::Align) -> Self {
969 Self {
970 builder: self.builder.property("valign", valign),
971 }
972 }
973
974 /// Whether to expand vertically.
975 pub fn vexpand(self, vexpand: bool) -> Self {
976 Self {
977 builder: self.builder.property("vexpand", vexpand),
978 }
979 }
980
981 /// Whether to use the `vexpand` property.
982 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
983 Self {
984 builder: self.builder.property("vexpand-set", vexpand_set),
985 }
986 }
987
988 /// Whether the widget is visible.
989 pub fn visible(self, visible: bool) -> Self {
990 Self {
991 builder: self.builder.property("visible", visible),
992 }
993 }
994
995 /// Overrides for width request of the widget.
996 ///
997 /// If this is -1, the natural request will be used.
998 pub fn width_request(self, width_request: i32) -> Self {
999 Self {
1000 builder: self.builder.property("width-request", width_request),
1001 }
1002 }
1003
1004 /// The accessible role of the given [`gtk::Accessible`][crate::gtk::Accessible] implementation.
1005 ///
1006 /// The accessible role cannot be changed once set.
1007 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
1008 Self {
1009 builder: self.builder.property("accessible-role", accessible_role),
1010 }
1011 }
1012
1013 // rustdoc-stripper-ignore-next
1014 /// Build the [`ButtonContent`].
1015 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1016 pub fn build(self) -> ButtonContent {
1017 assert_initialized_main_thread!();
1018 self.builder.build()
1019 }
1020}