1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
34//! Button widgets for COSMIC applications.
56pub use crate::theme::Button as ButtonClass;
78pub mod link;
9use derive_setters::Setters;
10#[doc(inline)]
11pub use link::Button as LinkButton;
12#[doc(inline)]
13pub use link::link;
1415mod icon;
16#[doc(inline)]
17pub use icon::Button as IconButton;
18#[doc(inline)]
19pub use icon::icon;
2021mod image;
22#[doc(inline)]
23pub use image::Button as ImageButton;
24#[doc(inline)]
25pub use image::image;
2627mod style;
28#[doc(inline)]
29pub use style::{Catalog, Style};
3031mod text;
32#[doc(inline)]
33pub use text::Button as TextButton;
34#[doc(inline)]
35pub use text::{destructive, standard, suggested, text};
3637mod widget;
38#[doc(inline)]
39pub use widget::{Button, draw, focus, layout, mouse_interaction};
4041use iced_core::font::Weight;
42use iced_core::widget::Id;
43use iced_core::{Length, Padding};
44use std::borrow::Cow;
4546/// A button with a custom element for its content.
47pub fn custom<'a, Message: Clone + 'a>(
48 content: impl Into<crate::Element<'a, Message>>,
49) -> Button<'a, Message> {
50 Button::new(content.into())
51}
5253/// An image button which may contain any widget as its content.
54pub fn custom_image_button<'a, Message: Clone + 'a>(
55 content: impl Into<crate::Element<'a, Message>>,
56 on_remove: Option<Message>,
57) -> Button<'a, Message> {
58 Button::new_image(content.into(), on_remove)
59}
6061/// A builder for constructing a custom [`Button`].
62#[must_use]
63#[derive(Setters)]
64pub struct Builder<'a, Message, Variant> {
65/// Sets the [`Id`] of the button.
66id: Id,
6768/// The label to display within the button.
69#[setters(into)]
70label: Cow<'a, str>,
7172// Adds a tooltip to the button.
73#[setters(into)]
74tooltip: Cow<'a, str>,
7576/// Sets the message that will be produced when the button is pressed.
77 ///
78 /// If `None`, the button will be disabled.
79#[setters(strip_option)]
80on_press: Option<Message>,
8182/// Sets the preferred width of the button.
83#[setters(into)]
84width: Length,
8586/// Sets the preferred height of the button.
87#[setters(into)]
88height: Length,
8990/// Sets the preferred padding of the button.
91#[setters(into)]
92padding: Padding,
9394/// Sets the preferred spacing between elements in the button.
95spacing: u16,
9697/// Sets the preferred size of icons.
98icon_size: u16,
99100/// Sets the prefered font line height.
101line_height: u16,
102103/// Sets the preferred font size.
104font_size: u16,
105106/// Sets the preferred font weight.
107font_weight: Weight,
108109/// The preferred style of the button.
110class: ButtonClass,
111112#[setters(skip)]
113variant: Variant,
114}
115116impl<Message, Variant> Builder<'_, Message, Variant> {
117/// Set the value of [`on_press`] as either `Some` or `None`.
118pub fn on_press_maybe(mut self, on_press: Option<Message>) -> Self {
119self.on_press = on_press;
120self
121}
122}