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
124pub mod color_picker;
125#[doc(inline)]
126pub use color_picker::{ColorPicker, ColorPickerModel};
127
128#[cfg(feature = "qr_code")]
129#[doc(inline)]
130pub use iced::widget::qr_code;
131
132mod cards;
133#[doc(inline)]
134pub use cards::cards;
135
136pub mod context_drawer;
137#[doc(inline)]
138pub use context_drawer::{ContextDrawer, context_drawer};
139
140pub mod layer_container;
141#[doc(inline)]
142pub use layer_container::{LayerContainer, layer_container};
143
144pub mod context_menu;
145#[doc(inline)]
146pub use context_menu::{ContextMenu, context_menu};
147
148pub mod dialog;
149#[doc(inline)]
150pub use dialog::{Dialog, dialog};
151
152/// An element to distinguish a boundary between two elements.
153pub mod divider {
154    /// Horizontal variant of a divider.
155    pub mod horizontal {
156        use iced::widget::{Rule, rule};
157
158        /// Horizontal divider with default thickness
159        #[must_use]
160        pub fn default<'a>() -> Rule<'a, crate::Theme> {
161            rule::horizontal(1).class(crate::theme::Rule::Default)
162        }
163
164        /// Horizontal divider with light thickness
165        #[must_use]
166        pub fn light<'a>() -> Rule<'a, crate::Theme> {
167            rule::horizontal(1).class(crate::theme::Rule::LightDivider)
168        }
169
170        /// Horizontal divider with heavy thickness.
171        #[must_use]
172        pub fn heavy<'a>() -> Rule<'a, crate::Theme> {
173            rule::horizontal(4).class(crate::theme::Rule::HeavyDivider)
174        }
175    }
176
177    /// Vertical variant of a divider.
178    pub mod vertical {
179        use iced::widget::{Rule, rule};
180
181        /// Vertical divider with default thickness
182        #[must_use]
183        pub fn default<'a>() -> Rule<'a, crate::Theme> {
184            rule::vertical(1).class(crate::theme::Rule::Default)
185        }
186
187        /// Vertical divider with light thickness
188        #[must_use]
189        pub fn light<'a>() -> Rule<'a, crate::Theme> {
190            rule::vertical(4).class(crate::theme::Rule::LightDivider)
191        }
192
193        /// Vertical divider with heavy thickness.
194        #[must_use]
195        pub fn heavy<'a>() -> Rule<'a, crate::Theme> {
196            rule::vertical(10).class(crate::theme::Rule::HeavyDivider)
197        }
198    }
199}
200
201pub mod dnd_destination;
202#[doc(inline)]
203pub use dnd_destination::{DndDestination, dnd_destination};
204
205pub mod dnd_source;
206#[doc(inline)]
207pub use dnd_source::{DndSource, dnd_source};
208
209pub mod dropdown;
210#[doc(inline)]
211pub use dropdown::{Dropdown, dropdown};
212
213pub mod flex_row;
214#[doc(inline)]
215pub use flex_row::{FlexRow, flex_row};
216
217pub mod reorderable_flex_row;
218#[doc(inline)]
219pub use reorderable_flex_row::{ReorderableFlexRow, reorderable_flex_row};
220
221pub mod grid;
222#[doc(inline)]
223pub use grid::{Grid, grid};
224
225mod header_bar;
226#[doc(inline)]
227pub use header_bar::{HeaderBar, header_bar};
228
229pub mod icon;
230#[doc(inline)]
231pub use icon::{Icon, icon};
232
233pub mod id_container;
234#[doc(inline)]
235pub use id_container::{IdContainer, id_container};
236
237#[cfg(feature = "animated-image")]
238pub mod frames;
239
240pub use taffy::{JustifyContent, JustifyItems};
241
242pub mod list;
243#[doc(inline)]
244pub use list::{ListColumn, list_column};
245
246pub mod menu;
247
248pub mod nav_bar;
249#[doc(inline)]
250pub use nav_bar::{nav_bar, nav_bar_dnd};
251
252pub mod nav_bar_toggle;
253#[doc(inline)]
254pub use nav_bar_toggle::{NavBarToggle, nav_bar_toggle};
255
256pub mod popover;
257#[doc(inline)]
258pub use popover::{Popover, popover};
259
260pub mod progress_bar;
261#[doc(inline)]
262pub use progress_bar::{
263    circular, circular::Circular, determinate_circular, determinate_linear, indeterminate_circular,
264    indeterminate_linear, linear, linear::Linear, style,
265};
266
267pub mod radio;
268#[doc(inline)]
269pub use radio::{Radio, radio};
270
271pub mod rectangle_tracker;
272#[doc(inline)]
273pub use rectangle_tracker::{RectangleTracker, rectangle_tracking_container};
274
275pub mod scrollable;
276pub use scrollable::vertical as scrollable;
277
278pub mod segmented_button;
279pub mod segmented_control;
280
281pub mod settings;
282
283pub mod spin_button;
284#[doc(inline)]
285pub use spin_button::{SpinButton, spin_button, vertical as vertical_spin_button};
286
287pub mod tab_bar;
288
289pub mod table;
290#[doc(inline)]
291pub use table::{compact_table, table};
292
293pub mod text;
294#[doc(inline)]
295pub use text::{Text, text};
296
297pub mod selectable_text;
298#[doc(inline)]
299pub use selectable_text::{SelectableText, selectable_text};
300
301pub mod text_context_menu;
302#[doc(inline)]
303pub use text_context_menu::HasSelectableText;
304
305pub mod text_input;
306#[doc(inline)]
307pub use text_input::{
308    TextInput, editable_input, inline_input, search_input, secure_input, text_input,
309};
310
311pub mod toaster;
312#[doc(inline)]
313pub use toaster::{Toast, ToastId, Toasts, toaster};
314
315mod toggler;
316#[doc(inline)]
317pub use toggler::{Toggler, toggler};
318
319#[doc(inline)]
320pub use tooltip::{Tooltip, tooltip};
321
322#[cfg(wayland_platform)]
323pub mod wayland;
324
325pub mod tooltip {
326    use crate::Element;
327
328    pub use iced::widget::tooltip::Position;
329
330    pub type Tooltip<'a, Message> =
331        iced::widget::Tooltip<'a, Message, crate::Theme, crate::Renderer>;
332
333    pub fn tooltip<'a, Message>(
334        content: impl Into<Element<'a, Message>>,
335        tooltip: impl Into<Element<'a, Message>>,
336        position: Position,
337    ) -> Tooltip<'a, Message> {
338        let xxs = crate::theme::spacing().space_xxs;
339
340        Tooltip::new(content, tooltip, position)
341            .class(crate::theme::Container::Tooltip)
342            .padding(xxs)
343            .gap(1)
344    }
345}
346
347pub mod warning;
348#[doc(inline)]
349pub use warning::*;
350
351pub mod wrapper;
352#[doc(inline)]
353pub use wrapper::*;
354
355#[cfg(feature = "markdown")]
356#[doc(inline)]
357pub use iced::widget::markdown;
358
359#[cfg(feature = "about")]
360pub mod about;
361#[cfg(feature = "about")]
362#[doc(inline)]
363pub use about::about;