#[cfg(any(feature = "resize", feature = "label"))]
use super::Dp;
#[cfg(any(
feature = "resize",
feature = "label",
feature = "icon",
feature = "button"
))]
use super::Element;
#[cfg(any(feature = "split-view", feature = "label"))]
use super::WidgetId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub enum Icon {
App,
Calculator,
History,
Backspace,
Add,
Search,
Settings,
Sidebar,
Inspector,
More,
Attach,
Enter,
Send,
Stop,
Refresh,
Retry,
Code,
Tool,
Check,
Info,
Success,
Warning,
Error,
Minimize,
Close,
Text,
Image,
File,
Folder,
Save,
Undo,
Cut,
Pin,
Delete,
Copy,
Paste,
Edit,
Group,
Phrase,
ChevronUp,
ChevronDown,
Calendar,
ChevronLeft,
ChevronRight,
PasswordReveal,
}
impl Icon {
pub const ALL: [Self; 45] = [
Self::App,
Self::Calculator,
Self::History,
Self::Backspace,
Self::Add,
Self::Search,
Self::Settings,
Self::Sidebar,
Self::Inspector,
Self::More,
Self::Attach,
Self::Enter,
Self::Send,
Self::Stop,
Self::Refresh,
Self::Retry,
Self::Code,
Self::Tool,
Self::Check,
Self::Info,
Self::Success,
Self::Warning,
Self::Error,
Self::Minimize,
Self::Close,
Self::Text,
Self::Image,
Self::File,
Self::Folder,
Self::Save,
Self::Undo,
Self::Cut,
Self::Pin,
Self::Delete,
Self::Copy,
Self::Paste,
Self::Edit,
Self::Group,
Self::Phrase,
Self::ChevronUp,
Self::ChevronDown,
Self::Calendar,
Self::ChevronLeft,
Self::ChevronRight,
Self::PasswordReveal,
];
#[cfg(any(feature = "icon", feature = "button"))]
const fn into_raw(self) -> crate::ZsIcon {
match self {
Self::App => crate::ZsIcon::App,
Self::Calculator => crate::ZsIcon::Calculator,
Self::History => crate::ZsIcon::History,
Self::Backspace => crate::ZsIcon::Backspace,
Self::Add => crate::ZsIcon::Add,
Self::Search => crate::ZsIcon::Search,
Self::Settings => crate::ZsIcon::Settings,
Self::Sidebar => crate::ZsIcon::Sidebar,
Self::Inspector => crate::ZsIcon::Inspector,
Self::More => crate::ZsIcon::More,
Self::Attach => crate::ZsIcon::Attach,
Self::Enter => crate::ZsIcon::Enter,
Self::Send => crate::ZsIcon::Send,
Self::Stop => crate::ZsIcon::Stop,
Self::Refresh => crate::ZsIcon::Refresh,
Self::Retry => crate::ZsIcon::Retry,
Self::Code => crate::ZsIcon::Code,
Self::Tool => crate::ZsIcon::Tool,
Self::Check => crate::ZsIcon::Check,
Self::Info => crate::ZsIcon::Info,
Self::Success => crate::ZsIcon::Success,
Self::Warning => crate::ZsIcon::Warning,
Self::Error => crate::ZsIcon::Error,
Self::Minimize => crate::ZsIcon::Minimize,
Self::Close => crate::ZsIcon::Close,
Self::Text => crate::ZsIcon::Text,
Self::Image => crate::ZsIcon::Image,
Self::File => crate::ZsIcon::File,
Self::Folder => crate::ZsIcon::Folder,
Self::Save => crate::ZsIcon::Save,
Self::Undo => crate::ZsIcon::Undo,
Self::Cut => crate::ZsIcon::Cut,
Self::Pin => crate::ZsIcon::Pin,
Self::Delete => crate::ZsIcon::Delete,
Self::Copy => crate::ZsIcon::Copy,
Self::Paste => crate::ZsIcon::Paste,
Self::Edit => crate::ZsIcon::Edit,
Self::Group => crate::ZsIcon::Group,
Self::Phrase => crate::ZsIcon::Phrase,
Self::ChevronUp => crate::ZsIcon::ChevronUp,
Self::ChevronDown => crate::ZsIcon::ChevronDown,
Self::Calendar => crate::ZsIcon::Calendar,
Self::ChevronLeft => crate::ZsIcon::ChevronLeft,
Self::ChevronRight => crate::ZsIcon::ChevronRight,
Self::PasswordReveal => crate::ZsIcon::PasswordReveal,
}
}
}
pub use crate::ColorRole;
pub use crate::ZsIconRole as IconRole;
#[cfg(feature = "icon")]
pub use crate::ZsIconSize as IconSize;
#[cfg(feature = "resize")]
pub use crate::ZsResizeAxis as ResizeAxis;
#[cfg(feature = "resize")]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct ResizeLimits(crate::ZsResizeLimits);
#[cfg(feature = "resize")]
impl ResizeLimits {
pub fn new(minimum: Dp, maximum: Dp) -> Result<Self, super::Error> {
crate::ZsResizeLimits::new(minimum.into(), maximum.into())
.map(Self)
.map_err(super::Error)
}
}
#[cfg(feature = "split-view")]
#[derive(Debug, Clone, Copy)]
pub struct PanelSpec(crate::ZsSplitViewSpec);
#[cfg(feature = "split-view")]
impl PanelSpec {
pub fn new(extent: Dp) -> Self {
Self(
crate::ZsSplitViewSpec::new(true)
.display_mode(crate::ZsSplitViewDisplayMode::Inline)
.pane_extent(extent.into()),
)
}
pub fn axis(mut self, axis: ResizeAxis) -> Self {
self.0 = self.0.axis(axis);
self
}
pub fn trailing(mut self, trailing: bool) -> Self {
self.0 = self.0.pane_placement(if trailing {
crate::ZsSplitViewPanePlacement::Trailing
} else {
crate::ZsSplitViewPanePlacement::Leading
});
self
}
pub fn minimum_content_extent(mut self, extent: Dp) -> Self {
self.0 = self.0.minimum_content_extent(extent.into());
self
}
pub fn adaptive(mut self) -> Self {
self.0 = self.0.display_mode(crate::ZsSplitViewDisplayMode::Adaptive);
self
}
}
#[cfg(feature = "split-view")]
pub fn split_panel<Message>(
id: WidgetId,
spec: PanelSpec,
pane: Element<Message>,
content: Element<Message>,
) -> Element<Message> {
Element::from_raw(crate::split_view(
id.into(),
spec.0,
pane.into_raw(),
content.into_raw(),
))
}
#[cfg(feature = "icon")]
pub fn icon<Message>(icon: Icon) -> Element<Message> {
Element::from_raw(crate::icon(icon.into_raw()))
}
#[cfg(feature = "icon")]
impl<Message> Element<Message> {
pub fn icon_size(mut self, size: IconSize) -> Self {
self.inner = self.inner.icon_size(size);
self
}
pub fn icon_role(mut self, role: IconRole) -> Self {
self.inner = self.inner.icon_role(role);
self
}
pub fn icon_color(mut self, color: ColorRole) -> Self {
self.inner = self.inner.icon_color(color);
self
}
}
#[cfg(feature = "resize")]
impl<Message: 'static> Element<Message> {
#[cfg(feature = "label")]
pub fn on_navigation_open_change(mut self, map: fn(bool) -> Message) -> Self {
self.inner = self.inner.on_navigation_open_change(map);
self
}
pub fn pane_resize_limits(mut self, limits: ResizeLimits) -> Self {
self.inner = self.inner.pane_resize_limits(limits.0);
self
}
pub fn on_resize(mut self, map: fn(Dp) -> Message) -> Self {
self.inner = self
.inner
.on_pane_resize_with(move |extent| map(Dp::new(extent.0)));
self
}
}
#[cfg(feature = "label")]
pub struct NavigationSpec<Message>(crate::ZsNavigationViewSpec<Message>);
#[cfg(feature = "label")]
impl<Message> NavigationSpec<Message> {
pub fn new(title: impl Into<String>, subtitle: impl Into<String>) -> Self {
Self(crate::ZsNavigationViewSpec::new(title, subtitle))
}
pub fn item(mut self, item: Element<Message>) -> Self {
self.0 = self.0.item(item.into_raw());
self
}
pub fn footer_item(mut self, item: Element<Message>) -> Self {
self.0 = self.0.footer_item(item.into_raw());
self
}
pub fn pane_width(mut self, width: Dp) -> Self {
self.0 = self.0.pane_width(width.into());
self
}
pub fn pane_open(mut self, open: bool) -> Self {
self.0 = self.0.pane_open(open);
self
}
pub fn minimum_content_width(mut self, width: Dp) -> Self {
self.0 = self.0.minimum_content_width(width.into());
self
}
pub fn content(mut self, id: WidgetId, content: Element<Message>) -> Self {
self.0 = self.0.content(id.into(), content.into_raw());
self
}
}
#[cfg(feature = "label")]
pub fn navigation_view<Message>(spec: NavigationSpec<Message>) -> Element<Message> {
Element::from_raw(crate::navigation_view(spec.0))
}
#[cfg(feature = "button")]
pub fn navigation_item<Message>(
label: impl Into<String>,
icon: Icon,
selected: bool,
) -> Element<Message> {
Element::from_raw(crate::navigation_item(label, icon.into_raw(), selected))
}
#[cfg(feature = "table")]
pub use crate::ZsTableColumnId as ColumnId;
#[cfg(feature = "table")]
pub use crate::ZsTableRow as TableRow;
#[cfg(feature = "table")]
pub use crate::ZsTableRowId as RowId;
#[cfg(feature = "table")]
pub use crate::ZsTableSort as TableSort;
#[cfg(feature = "table")]
#[derive(Debug, Clone)]
pub struct TableColumn(crate::ZsTableColumn);
#[cfg(feature = "table")]
impl TableColumn {
pub fn new(id: ColumnId, header: impl Into<String>) -> Self {
Self(crate::ZsTableColumn::new(id, header))
}
pub fn width(mut self, width: Dp) -> Self {
self.0 = self.0.fixed_width(width.into());
self
}
pub fn fill(mut self, weight: u16) -> Self {
self.0 = self.0.fill_width(weight);
self
}
pub fn sortable(mut self, enabled: bool) -> Self {
self.0 = self.0.sortable(enabled);
self
}
pub fn resizable(mut self, enabled: bool) -> Self {
self.0 = self.0.resizable(enabled);
self
}
pub fn resize_limits(mut self, limits: ResizeLimits) -> Self {
self.0 = self.0.resize_limits(limits.0);
self
}
pub fn id(&self) -> ColumnId {
self.0.id()
}
pub fn resize_to(&mut self, width: Dp) {
self.0.resize_to(width.into());
}
}
#[cfg(feature = "table")]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ColumnResize {
pub column: ColumnId,
pub width: Dp,
}
#[cfg(feature = "table")]
pub fn data_grid<Message>(
columns: impl IntoIterator<Item = TableColumn>,
rows: impl IntoIterator<Item = TableRow>,
) -> Element<Message> {
Element::from_raw(crate::data_grid(
columns.into_iter().map(|column| column.0),
rows,
))
}
#[cfg(feature = "table")]
impl<Message: Clone + 'static> Element<Message> {
pub fn on_column_resize(mut self, map: fn(ColumnResize) -> Message) -> Self {
self.inner = self.inner.on_table_column_resize_with(move |change| {
map(ColumnResize {
column: change.column,
width: Dp::new(change.width.0),
})
});
self
}
pub fn on_row_select(mut self, map: fn(RowId) -> Message) -> Self {
self.inner = self.inner.on_table_select(map);
self
}
pub fn on_sort(mut self, map: fn(TableSort) -> Message) -> Self {
self.inner = self.inner.on_table_sort(map);
self
}
pub fn selected_row(mut self, selected: Option<RowId>) -> Self {
self.inner = self.inner.selected_table_row(selected);
self
}
}
#[cfg(feature = "button")]
pub fn icon_button<Message>(label: impl Into<String>, icon: Icon) -> Element<Message> {
Element::from_raw(crate::icon_button(label, icon.into_raw()))
}
#[cfg(feature = "button")]
pub fn toolbar_button<Message>(label: impl Into<String>, icon: Icon) -> Element<Message> {
Element::from_raw(crate::toolbar_button(label, icon.into_raw()))
}