Module widget

Source
Expand description

The COSMIC widget library

This module contains a wide variety of widgets used throughout the COSMIC app ecosystem.

§Overview

Add widgets to your application view by calling the modules and functions below. Widgets are constructed by chaining their property methods using a functional paradigm. Modules may contain additional functions for constructing different variations of a widget. Each module will typically have one widget with the same name as the module, which will be re-exported here.

use cosmic::prelude::*;
use cosmic::{cosmic_theme, theme, widget};

const REPOSITORY: &str = "https://github.com/pop-os/libcosmic";

let cosmic_theme::Spacing { space_xxs, .. } = theme::spacing();

let link = widget::button::link(REPOSITORY)
    .on_press(Message::LaunchUrl(REPOSITORY))
    .padding(0);

let content = widget::column::with_capacity(3)
    .push(widget::icon::from_name("my-app-icon"))
    .push(widget::text::title3("My App Name"))
    .push(link)
    .align_items(Alignment::Center)
    .spacing(space_xxs);

Widgets may borrow data from your application struct, and should do so to avoid allocating.

let text = widget::text::body(&self.cached_text);

Use the cosmic::Apply trait to embed widgets into other widgets which accept them.

let button = widget::icon::from_name("printer-symbolic")
    .apply(widget::button::icon)
    .on_press(Message::Print);

Modules§

aspect_ratio
A container which constraints itself to a specific aspect ratio.
autosizeautosize
Autosize Container, which will resize the window to its contents.
button
Button widgets for COSMIC applications.
calendar
A widget that displays an interactive calendar.
canvas
Canvases can be leveraged to draw interactive 2D graphics.
card
checkbox
Checkboxes can be used to let users make binary choices.
circular
Show a circular progress indicator.
color_picker
Widgets for selecting colors with a color picker.
column
Distribute content vertically.
combo_box
Combo boxes display a dropdown list of searchable and selectable options.
container
Containers let you align a widget inside their boundaries.
context_drawer
An overlayed widget that attaches a toggleable context drawer to the view.
context_menu
A context menu is a menu in a graphical user interface that appears upon user interaction, such as a right-click mouse operation.
dialog
divider
An element to distinguish a boundary between two elements.
dnd_destination
dnd_source
dropdown
Displays a list of options in a popover menu on select.
flex_row
Responsively generates rows of widgets based on the dimensions of its children.
grid
Arrange widgets with a grid layout.
icon
Lazily-generated SVG icon widget for Iced.
id_container
image
Images display raster graphics in different formats (PNG, JPG, etc.).
layer_container
linear
Show a linear progress indicator.
list
list_column
menu
A MenuBar widget for displaying [MenuTree]s
nav_bar
Navigation side panel for switching between views.
nav_bar_toggle
A button for toggling the navigation side panel.
pane_grid
Pane grids let your users split regions of your application and organize layout dynamically.
popover
A container which displays an overlay when a popup widget is attached.
progress_bar
radio
Create choices using radio buttons.
rectangle_tracker
row
Distribute content horizontally.
scrollable
segmented_button
A widget providing a conjoined set of linear items that function in conjunction as a single button.
segmented_control
A selection of multiple choices appearing as a conjoined button.
settings
slider
Sliders let users set a value by moving an indicator.
space
Add some explicit spacing between elements.
spin_button
A control for incremental adjustments of a value.
style
svg
Svg widgets display vector graphics in your application.
tab_bar
A collection of tabs for developing a tabbed interface.
table
A widget allowing the user to display tables of information with optional sorting by category
text
text_editor
Text editors display a multi-line text input for text editing.
text_input
A text input widget from iced widgets plus some added details.
toaster
A widget that displays toasts.
tooltip
vertical_slider
Sliders let users set a value by moving an indicator.
warning
waylandwayland and Linux and winit
wrapper

Macros§

column
Creates a Column with the given children.
row
Creates a Row with the given children.

Structs§

Button
A generic button which emits a message when pressed.
Calendar
Canvas
A widget capable of drawing 2D graphics.
Checkbox
A box that can be checked.
Circular
ColorPicker
ColorPickerModel
Column
A container that distributes its contents vertically.
ComboBox
A widget for searching and selecting a single value from a list of options.
Container
A widget that aligns its contents inside of its boundaries.
ContextDrawer
ContextMenu
A context menu is a menu in a graphical user interface that appears upon user interaction, such as a right-click mouse operation.
Dialog
DndDestination
DndSource
Dropdown
A widget for selecting a single value from a list of selections.
FlexRow
Responsively generates rows and columns of widgets based on its dimensions.
Grid
Responsively generates rows and columns of widgets based on its dimmensions.
HeaderBar
Icon
An image which may be an SVG or PNG.
Id
The identifier of a generic widget.
IdContainer
An element decorating some content.
Image
A frame that displays an image while keeping aspect ratio.
LayerContainer
An element decorating some content.
Lazy
A widget that only rebuilds its contents when necessary.
Linear
ListColumn
MouseArea
Emit messages on mouse events.
NavBarToggle
PaneGrid
A collection of panes distributed using either vertical or horizontal splits to completely fill the space available.
Popover
A container which displays overlays when a popup widget is assigned.
Radio
A circular button representing a choice.
RcElementWrapper
RcWrapper
RectangleTracker
Responsive
A widget that is aware of its dimensions.
ResponsiveMenuBarsurface-message
Row
A container that distributes its contents horizontally.
Slider
An horizontal bar and a handle that selects a single value from a range of values.
Space
An amount of empty space.
SpinButton
Svg
A vector graphics image.
TextEditor
A multi-line text input.
TextInput
A field that can be filled with text.
Toast
Represent the data used to display a Toast
ToastId
Toasts
Toggler
A toggler widget.
VerticalSlider
An vertical bar and a handle that selects a single value from a range of values.
Warning

Traits§

Operation
A piece of logic that can traverse the widget tree of an application in order to query or update some widget state.
Widget
A component that displays information and allows interaction.

Functions§

calendar
A widget that displays an interactive calendar.
canvas
Creates a new Canvas.
cards
get an expandable stack of cards
checkbox
Creates a new Checkbox.
column
Creates a new Column with the given children.
combo_box
Creates a new ComboBox.
compact_table
container
Creates a new Container with the provided content.
context_drawer
An overlayed widget that attaches a toggleable context drawer to the view.
context_menu
A context menu is a menu in a graphical user interface that appears upon user interaction, such as a right-click mouse operation.
determinate_circular
A circular progress spinner widget that can be used to indicate the progress of some operation.
determinate_linear
A linear progress bar widget that can be used to indicate the progress of some operation.
dialog
dnd_destination
dnd_source
dropdown
Displays a list of options in a popover menu on select.
editable_input
A text label which can transform into a text input on activation.
flex_row
Responsively generates rows of widgets based on the dimensions of its children.
grid
Arrange widgets with a grid layout.
header_bar
icon
Create an Icon from a pre-existing Handle
id_container
image
Creates a new Image.
indeterminate_circular
A spinner / throbber widget that can be used to indicate that some operation is in progress.
indeterminate_linear
A linear throbber widget that can be used to indicate that some operation is in progress.
inline_input
Creates a new inline TextInput.
layer_container
lazy
Creates a new Lazy widget with the given data Dependency and a closure that can turn this data into a widget tree.
list_column
mouse_area
Creates a new MouseArea.
nav_bar
Navigation side panel for switching between views.
nav_bar_dnd
Navigation side panel for switching between views. Can receive drag and drop events.
nav_bar_toggle
pane_grid
Creates a PaneGrid with the given pane_grid::State and view function.
popover
radio
rectangle_tracking_container
responsive
Creates a new Responsive widget with a closure that produces its contents.
responsive_menu_barsurface-message
row
Creates a new Row from an iterator.
scrollable
search_input
Creates a new search TextInput.
secure_input
Creates a new secure TextInput.
slider
Creates a new Slider.
space
Creates some empty Space with no size.
spin_button
Horizontal spin button widget.
svg
Creates a new Svg widget from the given Handle.
table
text
Creates a new Text widget with the provided content.
text_editor
Creates a new TextEditor.
text_input
Creates a new TextInput.
toaster
Create a new Toaster widget.
toggler
tooltip
vertical_slider
Creates a new VerticalSlider.
vertical_spin_button
Vertical spin button widget.
warning
warning_container

Type Aliases§

IconButton
JustifyContent
Sets the distribution of space between and around content items For Flexbox it controls alignment in the main axis For Grid it controls alignment in the inline axis
JustifyItems
Used to control how child nodes are aligned. Does not apply to Flexbox, and will be ignored if specified on a flex container For Grid it controls alignment in the inline axis
LinkButton
Text
A bunch of text.
TextButton
Tooltip