Skip to main content

cosmic/widget/
mod.rs

1// Copyright 2022 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4//! The COSMIC widget library
5//!
6//! This module contains a wide variety of widgets used throughout the COSMIC app ecosystem.
7//!
8//! # Overview
9//!
10//! Add widgets to your application view by calling the modules and functions below.
11//! Widgets are constructed by chaining their property methods using a functional paradigm.
12//! Modules may contain additional functions for constructing different variations of a widget.
13//! Each module will typically have one widget with the same name as the module, which will be re-exported here.
14//!
15//! ```no_run,ignore
16//! use cosmic::prelude::*;
17//! use cosmic::{cosmic_theme, theme, widget};
18//!
19//! const REPOSITORY: &str = "https://github.com/pop-os/libcosmic";
20//!
21//! let cosmic_theme::Spacing { space_xxs, .. } = theme::spacing();
22//!
23//! let link = widget::button::link(REPOSITORY)
24//!     .on_press(Message::LaunchUrl(REPOSITORY))
25//!     .padding(0);
26//!
27//! let content = widget::column::with_capacity(3)
28//!     .push(widget::icon::from_name("my-app-icon"))
29//!     .push(widget::text::title3("My App Name"))
30//!     .push(link)
31//!     .align_items(Alignment::Center)
32//!     .spacing(space_xxs);
33//! ```
34//!
35//! Widgets may borrow data from your application struct, and should do so to avoid allocating.
36//!
37//! ```no_run,ignore
38//! let text = widget::text::body(&self.cached_text);
39//! ```
40//!
41//! Use the [`cosmic::Apply`](crate::Apply) trait to embed widgets into other widgets which accept them.
42//!
43//! ```no_run,ignore
44//! let button = widget::icon::from_name("printer-symbolic")
45//!     .apply(widget::button::icon)
46//!     .on_press(Message::Print);
47//! ```
48
49// Re-exports from Iced
50#[doc(inline)]
51pub use iced::widget::{Canvas, canvas};
52
53#[doc(inline)]
54pub use iced::widget::{Checkbox, checkbox};
55
56#[doc(inline)]
57pub use iced::widget::{Column, column};
58
59#[doc(inline)]
60pub use iced::widget::{ComboBox, combo_box};
61
62#[doc(inline)]
63pub use iced::widget::{Container, container};
64
65#[doc(inline)]
66pub use iced::widget::{Space, space};
67
68#[doc(inline)]
69pub use iced::widget::{Image, image};
70
71#[doc(inline)]
72pub use iced::widget::{Lazy, lazy};
73
74#[doc(inline)]
75pub use iced::widget::{MouseArea, mouse_area};
76
77#[doc(inline)]
78pub use iced::widget::{PaneGrid, pane_grid};
79
80#[doc(inline)]
81pub use iced::widget::{Responsive, responsive};
82
83#[doc(inline)]
84pub use iced::widget::{Row, row};
85
86#[doc(inline)]
87pub use iced::widget::{Slider, VerticalSlider, slider, vertical_slider};
88
89#[doc(inline)]
90pub use iced::widget::{Svg, svg};
91
92pub mod text_editor;
93#[doc(inline)]
94pub use text_editor::TextEditor;
95
96#[doc(inline)]
97pub use iced_core::widget::{Id, Operation, Widget};
98
99pub mod aspect_ratio;
100
101#[cfg(feature = "autosize")]
102pub mod autosize;
103
104pub(crate) mod responsive_container;
105
106#[cfg(feature = "surface-message")]
107mod responsive_menu_bar;
108#[cfg(feature = "surface-message")]
109#[doc(inline)]
110pub use responsive_menu_bar::{ResponsiveMenuBar, responsive_menu_bar};
111
112pub mod button;
113#[doc(inline)]
114pub use button::{Button, IconButton, LinkButton, TextButton};
115
116pub(crate) mod common;
117
118pub mod calendar;
119#[doc(inline)]
120pub use calendar::{Calendar, calendar};
121
122pub mod card;
123#[doc(inline)]
124pub use card::*;
125
126pub mod color_picker;
127#[doc(inline)]
128pub use color_picker::{ColorPicker, ColorPickerModel};
129
130#[cfg(feature = "qr_code")]
131#[doc(inline)]
132pub use iced::widget::qr_code;
133
134mod cards;
135#[doc(inline)]
136pub use cards::cards;
137
138pub mod context_drawer;
139#[doc(inline)]
140pub use context_drawer::{ContextDrawer, context_drawer};
141
142pub mod layer_container;
143#[doc(inline)]
144pub use layer_container::{LayerContainer, layer_container};
145
146pub mod context_menu;
147#[doc(inline)]
148pub use context_menu::{ContextMenu, context_menu};
149
150pub mod dialog;
151#[doc(inline)]
152pub use dialog::{Dialog, dialog};
153
154/// An element to distinguish a boundary between two elements.
155pub mod divider {
156    /// Horizontal variant of a divider.
157    pub mod horizontal {
158        use iced::widget::{Rule, rule};
159
160        /// Horizontal divider with default thickness
161        #[must_use]
162        pub fn default<'a>() -> Rule<'a, crate::Theme> {
163            rule::horizontal(1).class(crate::theme::Rule::Default)
164        }
165
166        /// Horizontal divider with light thickness
167        #[must_use]
168        pub fn light<'a>() -> Rule<'a, crate::Theme> {
169            rule::horizontal(1).class(crate::theme::Rule::LightDivider)
170        }
171
172        /// Horizontal divider with heavy thickness.
173        #[must_use]
174        pub fn heavy<'a>() -> Rule<'a, crate::Theme> {
175            rule::horizontal(4).class(crate::theme::Rule::HeavyDivider)
176        }
177    }
178
179    /// Vertical variant of a divider.
180    pub mod vertical {
181        use iced::widget::{Rule, rule};
182
183        /// Vertical divider with default thickness
184        #[must_use]
185        pub fn default<'a>() -> Rule<'a, crate::Theme> {
186            rule::vertical(1).class(crate::theme::Rule::Default)
187        }
188
189        /// Vertical divider with light thickness
190        #[must_use]
191        pub fn light<'a>() -> Rule<'a, crate::Theme> {
192            rule::vertical(4).class(crate::theme::Rule::LightDivider)
193        }
194
195        /// Vertical divider with heavy thickness.
196        #[must_use]
197        pub fn heavy<'a>() -> Rule<'a, crate::Theme> {
198            rule::vertical(10).class(crate::theme::Rule::HeavyDivider)
199        }
200    }
201}
202
203pub mod dnd_destination;
204#[doc(inline)]
205pub use dnd_destination::{DndDestination, dnd_destination};
206
207pub mod dnd_source;
208#[doc(inline)]
209pub use dnd_source::{DndSource, dnd_source};
210
211pub mod dropdown;
212#[doc(inline)]
213pub use dropdown::{Dropdown, dropdown};
214
215pub mod flex_row;
216#[doc(inline)]
217pub use flex_row::{FlexRow, flex_row};
218
219pub mod reorderable_flex_row;
220#[doc(inline)]
221pub use reorderable_flex_row::{ReorderableFlexRow, reorderable_flex_row};
222
223pub mod grid;
224#[doc(inline)]
225pub use grid::{Grid, grid};
226
227mod header_bar;
228#[doc(inline)]
229pub use header_bar::{HeaderBar, header_bar};
230
231pub mod icon;
232#[doc(inline)]
233pub use icon::{Icon, icon};
234
235pub mod id_container;
236#[doc(inline)]
237pub use id_container::{IdContainer, id_container};
238
239#[cfg(feature = "animated-image")]
240pub mod frames;
241
242pub use taffy::{JustifyContent, JustifyItems};
243
244pub mod list;
245#[doc(inline)]
246pub use list::{ListColumn, list_column};
247
248pub mod menu;
249
250pub mod nav_bar;
251#[doc(inline)]
252pub use nav_bar::{nav_bar, nav_bar_dnd};
253
254pub mod nav_bar_toggle;
255#[doc(inline)]
256pub use nav_bar_toggle::{NavBarToggle, nav_bar_toggle};
257
258pub mod popover;
259#[doc(inline)]
260pub use popover::{Popover, popover};
261
262pub mod progress_bar;
263#[doc(inline)]
264pub use progress_bar::{
265    circular, circular::Circular, determinate_circular, determinate_linear, indeterminate_circular,
266    indeterminate_linear, linear, linear::Linear, style,
267};
268
269pub mod radio;
270#[doc(inline)]
271pub use radio::{Radio, radio};
272
273pub mod rectangle_tracker;
274#[doc(inline)]
275pub use rectangle_tracker::{RectangleTracker, rectangle_tracking_container};
276
277pub mod scrollable;
278#[doc(inline)]
279pub use scrollable::scrollable;
280pub mod segmented_button;
281pub mod segmented_control;
282
283pub mod settings;
284
285pub mod spin_button;
286#[doc(inline)]
287pub use spin_button::{SpinButton, spin_button, vertical as vertical_spin_button};
288
289pub mod tab_bar;
290
291pub mod table;
292#[doc(inline)]
293pub use table::{compact_table, table};
294
295pub mod text;
296#[doc(inline)]
297pub use text::{Text, text};
298
299pub mod selectable_text;
300#[doc(inline)]
301pub use selectable_text::{SelectableText, selectable_text};
302
303pub mod text_context_menu;
304#[doc(inline)]
305pub use text_context_menu::HasSelectableText;
306
307pub mod text_input;
308#[doc(inline)]
309pub use text_input::{
310    TextInput, editable_input, inline_input, search_input, secure_input, text_input,
311};
312
313pub mod toaster;
314#[doc(inline)]
315pub use toaster::{Toast, ToastId, Toasts, toaster};
316
317mod toggler;
318#[doc(inline)]
319pub use toggler::{Toggler, toggler};
320
321#[doc(inline)]
322pub use tooltip::{Tooltip, tooltip};
323
324#[cfg(wayland_platform)]
325pub mod wayland;
326
327pub mod tooltip {
328    use crate::Element;
329
330    pub use iced::widget::tooltip::Position;
331
332    pub type Tooltip<'a, Message> =
333        iced::widget::Tooltip<'a, Message, crate::Theme, crate::Renderer>;
334
335    pub fn tooltip<'a, Message>(
336        content: impl Into<Element<'a, Message>>,
337        tooltip: impl Into<Element<'a, Message>>,
338        position: Position,
339    ) -> Tooltip<'a, Message> {
340        let xxs = crate::theme::spacing().space_xxs;
341
342        Tooltip::new(content, tooltip, position)
343            .class(crate::theme::Container::Tooltip)
344            .padding(xxs)
345            .gap(1)
346    }
347}
348
349pub mod warning;
350#[doc(inline)]
351pub use warning::*;
352
353pub mod wrapper;
354#[doc(inline)]
355pub use wrapper::*;
356
357#[cfg(feature = "markdown")]
358#[doc(inline)]
359pub use iced::widget::markdown;
360
361#[cfg(feature = "about")]
362pub mod about;
363#[cfg(feature = "about")]
364#[doc(inline)]
365pub use about::about;