diff --git a/Cargo.lock b/Cargo.lock index 8e1d8a9c..74c05fe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1341,6 +1341,14 @@ dependencies = [ "bitflags 2.5.0", ] +[[package]] +name = "grid" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "guillotiere" version = "0.6.2" @@ -2656,6 +2664,14 @@ dependencies = [ "tiny-skia", ] +[[package]] +name = "selection_list" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "self_cell" version = "1.0.4" @@ -2734,6 +2750,14 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slidebar" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "slotmap" version = "1.0.7" @@ -2825,6 +2849,14 @@ dependencies = [ "x11rb", ] +[[package]] +name = "spinner" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "spirv" version = "0.3.0+sdk-1.3.268.0" @@ -3824,6 +3856,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "wrap" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", + "rand", +] + [[package]] name = "x11-dl" version = "2.21.0" diff --git a/Cargo.toml b/Cargo.toml index c5efd51a..5d21a031 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,16 +42,16 @@ default = [ "number_input", "date_picker", "color_picker", - #"grid", + "grid", #"tab_bar", #"tabs", #"time_picker", - #"slide_bar", - #"wrap", - #"selection_list", + "slide_bar", + "wrap", + "selection_list", #"quad", #"context_menu", - #"spinner", + "spinner", #"drop_down", #"menu", ] @@ -82,16 +82,15 @@ members = [ "examples/number_input", "examples/date_picker", "examples/color_picker", - #"examples/font_loading", - #"examples/grid", + "examples/grid", #"examples/tab_bar", #"examples/tabs", #"examples/time_picker", - #"examples/sliderbar", - #"examples/wrap", - #"examples/selection_list", + "examples/sliderbar", + "examples/wrap", + "examples/selection_list", #"examples/context_menu", - #"examples/spinner", + "examples/spinner", #"examples/WidgetIDReturn", #"examples/drop_down", #"examples/menu", diff --git a/examples/font_loading/Cargo.toml b/examples/font_loading/Cargo.toml deleted file mode 100644 index ae41d710..00000000 --- a/examples/font_loading/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "font_loading" -version = "0.1.0" -authors = ["Redhawk18"] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -iced.workspace=true -iced_aw = { workspace = true, features = [ "icons" ] } - diff --git a/examples/font_loading/src/main.rs b/examples/font_loading/src/main.rs deleted file mode 100644 index d79cee55..00000000 --- a/examples/font_loading/src/main.rs +++ /dev/null @@ -1,70 +0,0 @@ -use iced::{ - font, - widget::{column, row, text}, - Application, Command, Element, Settings, Theme, -}; -use iced_aw::core::icons::{ - bootstrap::{self, Bootstrap}, - nerd::{self, Nerd}, -}; - -pub fn main() -> iced::Result { - MyApp::run(Settings::default()) -} - -struct MyApp; - -#[derive(Debug)] -enum Message { - FontLoaded(Result<(), font::Error>), -} - -impl Application for MyApp { - type Message = Message; - type Theme = Theme; - type Executor = iced::executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (MyApp, Command) { - ( - MyApp {}, - Command::batch(vec![ - // There is no automatic way for iced aw to load fonts, you the user have to load - // them and this is as simple as we can make it currently. - // Creating your own is easy, check out the source code of - // [`iced_aw::core::icons`], that's the simplest way to learn. - font::load(iced_aw::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded), - font::load(iced_aw::NERD_FONT_BYTES).map(Message::FontLoaded), - ]), - ) - } - - fn title(&self) -> String { - String::from("nerd font aint working") - } - - fn update(&mut self, message: Message) -> Command { - match message { - Message::FontLoaded(_) => {} - } - Command::none() - } - - fn view(&self) -> Element { - column!( - text("Bootstrap icons"), - row!( - bootstrap::icon_to_text(Bootstrap::FiletypeJava), - bootstrap::icon_to_text(Bootstrap::X), - ), - text("Nerd icons"), - row!( - nerd::icon_to_text(Nerd::LanguageJavascript), - nerd::icon_to_text(Nerd::SplitVertical), - nerd::icon_to_text(Nerd::X), - text('\u{f247}'.to_string()).font(iced_aw::NERD_FONT), - ), - ) - .into() - } -} diff --git a/examples/grid/src/main.rs b/examples/grid/src/main.rs index e73d24f0..d85fcf3c 100644 --- a/examples/grid/src/main.rs +++ b/examples/grid/src/main.rs @@ -2,7 +2,7 @@ use iced::widget::{checkbox, container, pick_list, row, slider}; use iced::Padding; use iced::{ alignment::{Horizontal, Vertical}, - Color, Element, Length, Sandbox, Settings, + Color, Element, Length, }; use iced_aw::{grid, grid_row}; @@ -17,22 +17,8 @@ struct App { debug_layout: bool, } -#[derive(Debug, Clone)] -enum Message { - HorizontalAlignment(Horizontal), - VerticalAlignment(Vertical), - ColumnSpacing(f32), - RowSpacing(f32), - FillWidth(bool), - FillHeight(bool), - Padding(f32), - DebugToggled(bool), -} - -impl Sandbox for App { - type Message = Message; - - fn new() -> Self { +impl Default for App { + fn default() -> Self { Self { horizontal_alignment: Horizontal::Left, vertical_alignment: Vertical::Center, @@ -44,12 +30,22 @@ impl Sandbox for App { debug_layout: false, } } +} - fn title(&self) -> String { - "Iced Grid widget example".into() - } +#[derive(Debug, Clone)] +enum Message { + HorizontalAlignment(Horizontal), + VerticalAlignment(Vertical), + ColumnSpacing(f32), + RowSpacing(f32), + FillWidth(bool), + FillHeight(bool), + Padding(f32), + DebugToggled(bool), +} - fn update(&mut self, message: Self::Message) { +impl App { + fn update(&mut self, message: Message) { match message { Message::HorizontalAlignment(align) => self.horizontal_alignment = align, Message::VerticalAlignment(align) => self.vertical_alignment = align, @@ -62,7 +58,7 @@ impl Sandbox for App { } } - fn view(&self) -> iced::Element<'_, Self::Message> { + fn view(&self) -> iced::Element<'_, Message> { let horizontal_align_pick = pick_list( HORIZONTAL_ALIGNMENTS .iter() @@ -126,8 +122,8 @@ impl Sandbox for App { container(contents) .width(Length::Fill) .height(Length::Fill) - .center_x() - .center_y() + .center_x(Length::Fill) + .center_y(Length::Fill) .into() } } @@ -174,5 +170,7 @@ fn string_to_vertical_align(input: &str) -> Vertical { } fn main() -> iced::Result { - App::run(Settings::default()) + iced::program("Grid example", App::update, App::view) + .font(iced_aw::BOOTSTRAP_FONT_BYTES) + .run() } diff --git a/examples/selection_list/src/main.rs b/examples/selection_list/src/main.rs index 865f923b..1e648e98 100644 --- a/examples/selection_list/src/main.rs +++ b/examples/selection_list/src/main.rs @@ -1,14 +1,15 @@ use iced::{ widget::{button, Column, Container, Text}, - Alignment, Element, Font, Length, Sandbox, Settings, + Alignment, Element, Font, Length, }; -use iced_aw::{selection_list::SelectionList, SelectionListStyles}; +use iced_aw::{selection_list::SelectionList, style::selection_list::primary}; pub fn main() -> iced::Result { - Example::run(Settings::default()) + iced::program("Selection list example", Example::update, Example::view) + .font(iced_aw::BOOTSTRAP_FONT_BYTES) + .run() } -#[derive(Default)] struct Example { vec: Vec, selected_language: String, @@ -16,33 +17,31 @@ struct Example { manual_select: Option, } -#[derive(Debug, Clone)] -enum Message { - LanguageSelected(usize, String), - AddAtSelection, - ManualSelection, -} - -impl Sandbox for Example { - type Message = Message; - - fn new() -> Self { +impl Default for Example { + fn default() -> Self { let mut vec = Vec::with_capacity(10); for i in Language::ALL.iter() { - vec.push(format!("{i}")) + vec.push(i.name()) } Self { vec, - ..Default::default() + selected_language: "".to_string(), + selected_index: 0, + manual_select: None, } } +} - fn title(&self) -> String { - String::from("Selection list - Iced") - } +#[derive(Debug, Clone)] +enum Message { + LanguageSelected(usize, String), + AddAtSelection, + ManualSelection, +} +impl Example { fn update(&mut self, message: Message) { match message { Message::LanguageSelected(index, language) => { @@ -76,7 +75,7 @@ impl Sandbox for Example { Message::LanguageSelected, 12.0, 5.0, - SelectionListStyles::Default, + primary, self.manual_select, Font::default(), ) @@ -99,8 +98,8 @@ impl Sandbox for Example { Container::new(content) .width(Length::Fill) .height(Length::Fill) - .center_x() - .center_y() + .center_x(Length::Fill) + .center_y(Length::Fill) .into() } } @@ -127,22 +126,16 @@ impl Language { Language::Javascript, Language::Other, ]; -} -impl std::fmt::Display for Language { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - match self { - Language::Rust => "Rust", - Language::Elm => "Elm", - Language::Ruby => "Ruby", - Language::Haskell => "Haskell", - Language::C => "C", - Language::Javascript => "Javascript", - Language::Other => "Some other language", - } - ) + pub fn name(&self) -> String { + match self { + Language::Rust => "Rust".to_owned(), + Language::Elm => "Elm".to_owned(), + Language::Ruby => "Ruby".to_owned(), + Language::Haskell => "Haskell".to_owned(), + Language::C => "C".to_owned(), + Language::Javascript => "Javascript".to_owned(), + Language::Other => "Some other language".to_owned(), + } } } diff --git a/examples/sliderbar/src/main.rs b/examples/sliderbar/src/main.rs index 912164a6..11beca23 100644 --- a/examples/sliderbar/src/main.rs +++ b/examples/sliderbar/src/main.rs @@ -1,12 +1,18 @@ use iced::{ widget::{Column, Container, Text}, - Element, Length, Sandbox, Settings, + Element, Length, }; use iced_aw::SlideBar; fn main() -> iced::Result { - SlideBarExample::run(Settings::default()) + iced::program( + "Slider Bar example", + SlideBarExample::update, + SlideBarExample::view, + ) + .font(iced_aw::BOOTSTRAP_FONT_BYTES) + .run() } #[derive(Debug, Clone)] @@ -14,21 +20,12 @@ enum Message { SliderBarChange(u32), } +#[derive(Debug, Default)] struct SlideBarExample { value: u32, } -impl Sandbox for SlideBarExample { - type Message = Message; - - fn new() -> Self { - SlideBarExample { value: 1 } - } - - fn title(&self) -> String { - String::from("Slider Bar example") - } - +impl SlideBarExample { fn update(&mut self, message: Message) { let Message::SliderBarChange(v) = message; self.value = v; @@ -51,8 +48,8 @@ impl Sandbox for SlideBarExample { Container::new(content_all) .width(Length::Fill) .height(Length::Fill) - .center_x() - .center_y() + .center_x(Length::Fill) + .center_y(Length::Fill) .into() } } diff --git a/examples/spinner/src/main.rs b/examples/spinner/src/main.rs index 842a8ae2..c2e6701c 100644 --- a/examples/spinner/src/main.rs +++ b/examples/spinner/src/main.rs @@ -1,90 +1,60 @@ use iced::widget::PickList; use iced::{ widget::{column, container}, - Application, Command, Element, Length, Settings, Theme, + Element, Length, Theme, }; use iced_aw::Spinner; -use std::fmt::{Display, Formatter}; struct SpinnerExample { - theme: ThemeSelection, + theme: Theme, } -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum ThemeSelection { - Dark, - Light, -} - -impl Display for ThemeSelection { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - ThemeSelection::Dark => write!(f, "Dark"), - ThemeSelection::Light => write!(f, "Light"), +impl Default for SpinnerExample { + fn default() -> Self { + Self { + theme: Theme::Light, } } } #[derive(Clone, Debug)] enum Message { - ThemeChanged(ThemeSelection), + ThemeChanged(Theme), } -const AVAILABLE_THEMES: [ThemeSelection; 2] = [ThemeSelection::Light, ThemeSelection::Dark]; - -impl Application for SpinnerExample { - type Executor = iced::executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: Self::Flags) -> (Self, Command) { - ( - Self { - theme: ThemeSelection::Light, - }, - Command::none(), - ) - } - - fn title(&self) -> String { - String::from("Spinner") - } - - fn update(&mut self, message: Self::Message) -> Command { +impl SpinnerExample { + fn update(&mut self, message: Message) { match message { Message::ThemeChanged(theme) => { self.theme = theme; } } - - Command::none() } - fn view(&self) -> Element { + fn view(&self) -> Element { column![ container(Spinner::new()) .width(Length::Fill) .height(Length::Fill) - .center_x() - .center_y(), - PickList::new( - AVAILABLE_THEMES.as_slice(), - Some(self.theme), - Message::ThemeChanged - ), + .center_x(Length::Fill) + .center_y(Length::Fill), + PickList::new(Theme::ALL, Some(&self.theme), Message::ThemeChanged), ] .into() } - fn theme(&self) -> Self::Theme { - match self.theme { - ThemeSelection::Dark => Theme::Dark, - ThemeSelection::Light => Theme::Light, - } + fn theme(&self) -> Theme { + self.theme.clone() } } fn main() -> iced::Result { - SpinnerExample::run(Settings::default()) + iced::program( + "Spinner example", + SpinnerExample::update, + SpinnerExample::view, + ) + .font(iced_aw::BOOTSTRAP_FONT_BYTES) + .theme(SpinnerExample::theme) + .run() } diff --git a/examples/wrap/src/main.rs b/examples/wrap/src/main.rs index 8a8d744d..76e90d40 100644 --- a/examples/wrap/src/main.rs +++ b/examples/wrap/src/main.rs @@ -1,23 +1,19 @@ use std::fmt::Display; use iced::{ - alignment, font, - widget::{container, text, Button, Column, Container, PickList, Row, Text}, - Application, Command, Element, Length, Settings, Theme, + widget::{Button, Column, Container, PickList, Row, Text}, + Element, }; use iced_aw::{NumberInput, Wrap}; use rand::Rng; fn main() -> iced::Result { - RandStrings::run(Settings::default()) + iced::program("Wrap example", RandStrings::update, RandStrings::view) + .font(iced_aw::BOOTSTRAP_FONT_BYTES) + .run() } -enum RandStrings { - Loading, - Loaded(State), -} - -struct State { +struct RandStrings { vbuttons: Vec, hbuttons: Vec, spacing: f32, @@ -25,6 +21,27 @@ struct State { line_minimal_length: f32, align: iced::Alignment, } + +impl Default for RandStrings { + fn default() -> Self { + let mut rng = rand::thread_rng(); + let data: Vec = (0..45) + .map(|s| StrButton { + str: s.to_string(), + size: rng.gen_range(15.0..50.0), + }) + .collect(); + Self { + vbuttons: data.clone(), + hbuttons: data, + align: iced::Alignment::Start, + spacing: 0.0, + line_spacing: 0.0, + line_minimal_length: 10.0, + } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum WrapAlign { Start, @@ -71,161 +88,93 @@ enum Message { ChangeSpacing(f32), ChangeLineSpacing(f32), ChangeMinimalLength(f32), - #[allow(dead_code)] - Loaded(Result<(), String>), - FontLoaded(Result<(), font::Error>), } -async fn load() -> Result<(), String> { - Ok(()) -} - -impl Application for RandStrings { - type Message = Message; - type Theme = Theme; - type Executor = iced::executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Self, Command) { - ( - Self::Loading, - Command::batch(vec![ - font::load(iced_aw::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded), - Command::perform(load(), Message::Loaded), - ]), - ) - } - - fn title(&self) -> String { - "wrap".to_owned() - } - - fn update(&mut self, message: Self::Message) -> Command { - match self { - Self::Loading => { - if let Message::Loaded(_) = message { - *self = Self::Loaded({ - let mut rng = rand::thread_rng(); - let data: Vec = (0..45) - .map(|s| StrButton { - str: s.to_string(), - size: rng.gen_range(15.0..50.0), - }) - .collect(); - State { - vbuttons: data.clone(), - hbuttons: data, - align: iced::Alignment::Start, - spacing: 0.0, - line_spacing: 0.0, - line_minimal_length: 10.0, - } - }) - } +impl RandStrings { + fn update(&mut self, message: Message) { + match message { + Message::ChangeAlign(align) => { + self.align = align.into(); + } + Message::ChangeSpacing(num) => { + self.spacing = num; + } + Message::ChangeLineSpacing(num) => { + self.line_spacing = num; + } + Message::ChangeMinimalLength(num) => { + self.line_minimal_length = num; } - Self::Loaded(state) => match message { - Message::ChangeAlign(align) => { - state.align = align.into(); - } - Message::ChangeSpacing(num) => { - state.spacing = num; - } - Message::ChangeLineSpacing(num) => { - state.line_spacing = num; - } - Message::ChangeMinimalLength(num) => { - state.line_minimal_length = num; - } - _ => {} - }, } - - Command::none() } - fn view(&self) -> Element<'_, Self::Message> { - match self { - Self::Loading => container( - text("Loading...") - .horizontal_alignment(alignment::Horizontal::Center) - .size(50), - ) - .width(Length::Fill) - .height(Length::Fill) - .center_y() - .center_x() - .into(), - Self::Loaded(state) => { - let vertical = Container::new( - state - .vbuttons - .iter() - .fold(Wrap::new_vertical(), |wrap, button| { - let StrButton { str, .. } = button; - wrap.push(Button::new(Text::new(str.as_str()).size(button.size))) - }) - .align_items(state.align) - .spacing(state.spacing) - .line_spacing(state.line_spacing) - .line_minimal_length(state.line_minimal_length), - ) - .width(iced::Length::FillPortion(5)); - let horizontal = Container::new( - state - .hbuttons - .iter() - .fold(Wrap::new(), |wrap, button| { - let StrButton { str, .. } = button; - wrap.push(Button::new(Text::new(str.as_str()).size(button.size))) - }) - .align_items(state.align) - .spacing(state.spacing) - .line_spacing(state.line_spacing) - .line_minimal_length(state.line_minimal_length), - ) - .width(iced::Length::FillPortion(5)); - let align_picklist = PickList::new( - vec![WrapAlign::Start, WrapAlign::Center, WrapAlign::End], - Some(Into::::into(state.align)), - Message::ChangeAlign, - ); - let spacing_input = - Column::new() - .push(Text::new("spacing")) - .push(NumberInput::new( - state.spacing, - 0.0..500.0, - Message::ChangeSpacing, - )); - let line_spacing_input = - Column::new() - .push(Text::new("line spacing")) - .push(NumberInput::new( - state.line_spacing, - 0.0..500.0, - Message::ChangeLineSpacing, - )); - let line_minimal_length_input = Column::new() - .push(Text::new("line minimal length")) - .push(NumberInput::new( - state.line_minimal_length, - 0.0..999.9, - Message::ChangeMinimalLength, - )); - let ctrls = Column::new() - .push(align_picklist) - .push(spacing_input) - .push(line_spacing_input) - .push(line_minimal_length_input) - .height(iced::Length::Shrink) - .align_items(iced::Alignment::Center); + fn view(&self) -> Element<'_, Message> { + let vertical = Container::new( + self.vbuttons + .iter() + .fold(Wrap::new_vertical(), |wrap, button| { + let StrButton { str, .. } = button; + wrap.push(Button::new(Text::new(str.as_str()).size(button.size))) + }) + .align_items(self.align) + .spacing(self.spacing) + .line_spacing(self.line_spacing) + .line_minimal_length(self.line_minimal_length), + ) + .width(iced::Length::FillPortion(5)); + let horizontal = Container::new( + self.hbuttons + .iter() + .fold(Wrap::new(), |wrap, button| { + let StrButton { str, .. } = button; + wrap.push(Button::new(Text::new(str.as_str()).size(button.size))) + }) + .align_items(self.align) + .spacing(self.spacing) + .line_spacing(self.line_spacing) + .line_minimal_length(self.line_minimal_length), + ) + .width(iced::Length::FillPortion(5)); + let align_picklist = PickList::new( + vec![WrapAlign::Start, WrapAlign::Center, WrapAlign::End], + Some(Into::::into(self.align)), + Message::ChangeAlign, + ); + let spacing_input = Column::new() + .push(Text::new("spacing")) + .push(NumberInput::new( + self.spacing, + 0.0..500.0, + Message::ChangeSpacing, + )); + let line_spacing_input = + Column::new() + .push(Text::new("line spacing")) + .push(NumberInput::new( + self.line_spacing, + 0.0..500.0, + Message::ChangeLineSpacing, + )); + let line_minimal_length_input = + Column::new() + .push(Text::new("line minimal length")) + .push(NumberInput::new( + self.line_minimal_length, + 0.0..999.9, + Message::ChangeMinimalLength, + )); + let ctrls = Column::new() + .push(align_picklist) + .push(spacing_input) + .push(line_spacing_input) + .push(line_minimal_length_input) + .height(iced::Length::Shrink) + .align_items(iced::Alignment::Center); - Row::new() - .push(ctrls) - .push(vertical) - .push(horizontal) - .into() - } - } + Row::new() + .push(ctrls) + .push(vertical) + .push(horizontal) + .into() } } diff --git a/src/lib.rs b/src/lib.rs index fc05045c..28014a2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,10 +119,7 @@ mod platform { #[doc(no_inline)] #[cfg(feature = "selection_list")] - pub use { - crate::style::SelectionListStyles, crate::widgets::selection_list, - selection_list::SelectionList, - }; + pub use {crate::widgets::selection_list, selection_list::SelectionList}; #[doc(no_inline)] #[cfg(feature = "menu")] @@ -134,7 +131,7 @@ mod platform { #[doc(no_inline)] #[cfg(feature = "spinner")] - pub use {crate::style::SpinnerStyle, crate::widgets::spinner, spinner::Spinner}; + pub use {crate::widgets::spinner, spinner::Spinner}; #[doc(no_inline)] #[cfg(feature = "slide_bar")] diff --git a/src/style.rs b/src/style.rs index bb6353b7..0e4c2d89 100644 --- a/src/style.rs +++ b/src/style.rs @@ -33,19 +33,12 @@ pub mod number_input; #[cfg(feature = "selection_list")] pub mod selection_list; -#[cfg(feature = "selection_list")] -pub use selection_list::SelectionListStyles; #[cfg(feature = "menu")] pub mod menu_bar; #[cfg(feature = "menu")] pub use menu_bar::MenuBarStyle; -#[cfg(feature = "spinner")] -pub mod spinner; -#[cfg(feature = "spinner")] -pub use spinner::SpinnerStyle; - #[cfg(feature = "context_menu")] pub mod context_menu; #[cfg(feature = "context_menu")] diff --git a/src/style/badge.rs b/src/style/badge.rs index 83bfbbe0..fa3dd2da 100644 --- a/src/style/badge.rs +++ b/src/style/badge.rs @@ -4,27 +4,27 @@ use super::{colors, Status, StyleFn}; use iced::{theme::palette, Background, Color, Theme}; -/// The style of a [`Badge`](crate::native::badge::Badge). +/// The style of a [`Badge`](crate::widgets::badge::Badge). #[derive(Clone, Copy, Debug)] pub struct Style { - /// The background of the [`Badge`](crate::native::badge::Badge). + /// The background of the [`Badge`](crate::widgets::badge::Badge). pub background: Background, - /// The border radius of the [`Badge`](crate::native::badge::Badge). + /// The border radius of the [`Badge`](crate::widgets::badge::Badge). /// If no radius is specified the default one will be used. pub border_radius: Option, - /// The border with of the [`Badge`](crate::native::badge::Badge). + /// The border with of the [`Badge`](crate::widgets::badge::Badge). pub border_width: f32, - /// The border color of the [`Badge`](crate::native::badge::Badge). + /// The border color of the [`Badge`](crate::widgets::badge::Badge). pub border_color: Option, - /// The default text color of the [`Badge`](crate::native::badge::Badge). + /// The default text color of the [`Badge`](crate::widgets::badge::Badge). pub text_color: Color, } -/// The Catalog of a [`Badge`](crate::native::badge::Badge). +/// The Catalog of a [`Badge`](crate::widgets::badge::Badge). pub trait Catalog { ///Style for the trait to use. type Class<'a>; @@ -60,7 +60,7 @@ impl Catalog for Theme { } } -/// The primary theme of a [`Badge`](crate::native::badge::Badge). +/// The primary theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn primary(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); @@ -76,7 +76,7 @@ pub fn primary(theme: &Theme, status: Status) -> Style { } } -/// The secondary theme of a [`Badge`](crate::native::badge::Badge). +/// The secondary theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn secondary(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); @@ -92,7 +92,7 @@ pub fn secondary(theme: &Theme, status: Status) -> Style { } } -/// The success theme of a [`Badge`](crate::native::badge::Badge). +/// The success theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn success(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); @@ -108,7 +108,7 @@ pub fn success(theme: &Theme, status: Status) -> Style { } } -/// The danger theme of a [`Badge`](crate::native::badge::Badge). +/// The danger theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn danger(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); @@ -124,7 +124,7 @@ pub fn danger(theme: &Theme, status: Status) -> Style { } } -/// The warning theme of a [`Badge`](crate::native::badge::Badge). +/// The warning theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn warning(_theme: &Theme, status: Status) -> Style { let base = from_color(colors::WARNING, colors::BLACK); @@ -139,7 +139,7 @@ pub fn warning(_theme: &Theme, status: Status) -> Style { } } -/// The info theme of a [`Badge`](crate::native::badge::Badge). +/// The info theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn info(_theme: &Theme, status: Status) -> Style { let base = from_color(colors::INFO, colors::BLACK); @@ -154,7 +154,7 @@ pub fn info(_theme: &Theme, status: Status) -> Style { } } -/// The light theme of a [`Badge`](crate::native::badge::Badge). +/// The light theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn light(_theme: &Theme, status: Status) -> Style { let base = from_color(colors::LIGHT, colors::BLACK); @@ -169,7 +169,7 @@ pub fn light(_theme: &Theme, status: Status) -> Style { } } -/// The dark theme of a [`Badge`](crate::native::badge::Badge). +/// The dark theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn dark(_theme: &Theme, status: Status) -> Style { let base = from_color(colors::DARK, colors::WHITE); @@ -184,7 +184,7 @@ pub fn dark(_theme: &Theme, status: Status) -> Style { } } -/// The white theme of a [`Badge`](crate::native::badge::Badge). +/// The white theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn white(_theme: &Theme, status: Status) -> Style { let base = from_color(colors::WHITE, colors::BLACK); diff --git a/src/style/card.rs b/src/style/card.rs index f8741902..93ef71b6 100644 --- a/src/style/card.rs +++ b/src/style/card.rs @@ -1,48 +1,48 @@ -//! Displays a [`Card`](crate::native::Card). +//! Displays a [`Card`](crate::widgets::Card). //! //! *This API requires the following crate features to be activated: card* use super::{colors, Status, StyleFn}; use iced::{Background, Color, Theme}; -/// The appearance of a [`Card`](crate::native::card::Card). +/// The appearance of a [`Card`](crate::widgets::card::Card). #[derive(Clone, Copy, Debug)] pub struct Style { - /// The background of the [`Card`](crate::native::card::Card). + /// The background of the [`Card`](crate::widgets::card::Card). pub background: Background, - /// The border radius of the [`Card`](crate::native::card::Card). + /// The border radius of the [`Card`](crate::widgets::card::Card). pub border_radius: f32, - /// The border width of the [`Card`](crate::native::card::Card). + /// The border width of the [`Card`](crate::widgets::card::Card). pub border_width: f32, - /// The border color of the [`Card`](crate::native::card::Card). + /// The border color of the [`Card`](crate::widgets::card::Card). pub border_color: Color, - /// The background of the head of the [`Card`](crate::native::card::Card). + /// The background of the head of the [`Card`](crate::widgets::card::Card). pub head_background: Background, - /// The text color of the head of the [`Card`](crate::native::card::Card). + /// The text color of the head of the [`Card`](crate::widgets::card::Card). pub head_text_color: Color, - /// The background of the body of the [`Card`](crate::native::card::Card). + /// The background of the body of the [`Card`](crate::widgets::card::Card). pub body_background: Background, - /// The text color of the body of the [`Card`](crate::native::card::Card). + /// The text color of the body of the [`Card`](crate::widgets::card::Card). pub body_text_color: Color, - /// The background of the foot of the [`Card`](crate::native::card::Card). + /// The background of the foot of the [`Card`](crate::widgets::card::Card). pub foot_background: Background, - /// The text color of the foot of the [`Card`](crate::native::card::Card). + /// The text color of the foot of the [`Card`](crate::widgets::card::Card). pub foot_text_color: Color, - /// The color of the close icon of the [`Card`](crate::native::card::Card). + /// The color of the close icon of the [`Card`](crate::widgets::card::Card). pub close_color: Color, } -/// The appearance of a [`Card`](crate::native::card::Card). +/// The appearance of a [`Card`](crate::widgets::card::Card). pub trait Catalog { ///Style for the trait to use. type Class<'a>; @@ -84,55 +84,55 @@ impl Catalog for Theme { } } -/// The primary theme of a [`Card`](crate::native::card::Card). +/// The primary theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn primary(theme: &Theme, _status: Status) -> Style { backing_with_text(theme, colors::PRIMARY, colors::WHITE) } -/// The secondary theme of a [`Card`](crate::native::card::Card). +/// The secondary theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn secondary(theme: &Theme, _status: Status) -> Style { backing_with_text(theme, colors::SECONDARY, colors::WHITE) } -/// The success theme of a [`Card`](crate::native::card::Card). +/// The success theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn success(theme: &Theme, _status: Status) -> Style { backing_with_text(theme, colors::SUCCESS, colors::WHITE) } -/// The danger theme of a [`Card`](crate::native::card::Card). +/// The danger theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn danger(theme: &Theme, _status: Status) -> Style { backing_with_text(theme, colors::DANGER, colors::WHITE) } -/// The warning theme of a [`Card`](crate::native::card::Card). +/// The warning theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn warning(theme: &Theme, _status: Status) -> Style { backing_only(theme, colors::WARNING) } -/// The info theme of a [`Card`](crate::native::card::Card). +/// The info theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn info(theme: &Theme, _status: Status) -> Style { backing_only(theme, colors::INFO) } -/// The light theme of a [`Card`](crate::native::card::Card). +/// The light theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn light(theme: &Theme, _status: Status) -> Style { backing_only(theme, colors::LIGHT) } -/// The dark theme of a [`Card`](crate::native::card::Card). +/// The dark theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn dark(theme: &Theme, _status: Status) -> Style { backing_with_text(theme, colors::DARK, colors::WHITE) } -/// The white theme of a [`Card`](crate::native::card::Card). +/// The white theme of a [`Card`](crate::widgets::card::Card). #[must_use] pub fn white(theme: &Theme, _status: Status) -> Style { backing_only(theme, colors::WHITE) diff --git a/src/style/color_picker.rs b/src/style/color_picker.rs index 85b9b6f2..42946f9c 100644 --- a/src/style/color_picker.rs +++ b/src/style/color_picker.rs @@ -5,32 +5,32 @@ use super::{Status, StyleFn}; use iced::{Background, Color, Theme}; -/// The appearance of a [`ColorPicker`](crate::native::ColorPicker). +/// The appearance of a [`ColorPicker`](crate::widgets::ColorPicker). #[derive(Clone, Copy, Debug)] pub struct Style { - /// The background of the [`ColorPicker`](crate::native::ColorPicker). + /// The background of the [`ColorPicker`](crate::widgets::ColorPicker). pub background: Background, - /// The border radius of the [`ColorPicker`](crate::native::ColorPicker). + /// The border radius of the [`ColorPicker`](crate::widgets::ColorPicker). pub border_radius: f32, - /// The border with of the [`ColorPicker`](crate::native::ColorPicker). + /// The border with of the [`ColorPicker`](crate::widgets::ColorPicker). pub border_width: f32, - /// The border color of the [`ColorPicker`](crate::native::ColorPicker). + /// The border color of the [`ColorPicker`](crate::widgets::ColorPicker). pub border_color: Color, - /// The border radius of the bars of the [`ColorPicker`](crate::native::ColorPicker). + /// The border radius of the bars of the [`ColorPicker`](crate::widgets::ColorPicker). pub bar_border_radius: f32, - /// The border width of the bars of the [`ColorPicker`](crate::native::ColorPicker). + /// The border width of the bars of the [`ColorPicker`](crate::widgets::ColorPicker). pub bar_border_width: f32, - /// The border color of the bars of the [`ColorPicker`](crate::native::ColorPicker). + /// The border color of the bars of the [`ColorPicker`](crate::widgets::ColorPicker). pub bar_border_color: Color, } -/// The Catalog of a [`ColorPicker`](crate::native::ColorPicker). +/// The Catalog of a [`ColorPicker`](crate::widgets::ColorPicker). pub trait Catalog { ///Style for the trait to use. type Class<'a>; @@ -54,7 +54,7 @@ impl Catalog for Theme { } } -/// The primary theme of a [`Badge`](crate::native::badge::Badge). +/// The primary theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn primary(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); diff --git a/src/style/context_menu.rs b/src/style/context_menu.rs index af9c3dd2..fbfb90c1 100644 --- a/src/style/context_menu.rs +++ b/src/style/context_menu.rs @@ -5,10 +5,10 @@ use std::rc::Rc; use iced::{Background, Color, Theme}; -/// The appearance of a [`ContextMenu`](crate::native::ContextMenu). +/// The appearance of a [`ContextMenu`](crate::widgets::ContextMenu). #[derive(Clone, Copy, Debug)] pub struct Appearance { - /// The background of the [`ContextMenu`](crate::native::ContextMenu). + /// The background of the [`ContextMenu`](crate::widgets::ContextMenu). /// /// This is used to color the backdrop of the modal. pub background: Background, @@ -22,15 +22,15 @@ impl Default for Appearance { } } -/// The appearance of a [`ContextMenu`](crate::native::ContextMenu). +/// The appearance of a [`ContextMenu`](crate::widgets::ContextMenu). pub trait StyleSheet { ///Style for the trait to use. type Style: Default + Clone; - /// The normal appearance of a [`ContextMenu`](crate::native::ContextMenu). + /// The normal appearance of a [`ContextMenu`](crate::widgets::ContextMenu). fn active(&self, style: &Self::Style) -> Appearance; } -/// The default appearance of a [`ContextMenu`](crate::native::ContextMenu). +/// The default appearance of a [`ContextMenu`](crate::widgets::ContextMenu). #[derive(Clone, Default)] #[allow(missing_docs, clippy::missing_docs_in_private_items)] pub enum ContextMenuStyle { diff --git a/src/style/date_picker.rs b/src/style/date_picker.rs index 87b05e58..395d333a 100644 --- a/src/style/date_picker.rs +++ b/src/style/date_picker.rs @@ -4,34 +4,34 @@ use super::{Status, StyleFn}; use iced::{Background, Color, Theme}; -/// The appearance of a [`DatePicker`](crate::native::DatePicker). +/// The appearance of a [`DatePicker`](crate::widgets::DatePicker). #[derive(Clone, Copy, Debug)] pub struct Style { - /// The background of the [`DatePicker`](crate::native::DatePicker). + /// The background of the [`DatePicker`](crate::widgets::DatePicker). pub background: Background, - /// The border radius of the [`DatePicker`](crate::native::DatePicker). + /// The border radius of the [`DatePicker`](crate::widgets::DatePicker). pub border_radius: f32, - /// The border with of the [`DatePicker`](crate::native::DatePicker). + /// The border with of the [`DatePicker`](crate::widgets::DatePicker). pub border_width: f32, - /// The border color of the [`DatePicker`](crate::native::DatePicker). + /// The border color of the [`DatePicker`](crate::widgets::DatePicker). pub border_color: Color, - /// The text color of the [`DatePicker`](crate::native::DatePicker). + /// The text color of the [`DatePicker`](crate::widgets::DatePicker). pub text_color: Color, /// The attenuated color of the days which are not in the selected month - /// of the [`DatePicker`](crate::native::DatePicker). + /// of the [`DatePicker`](crate::widgets::DatePicker). pub text_attenuated_color: Color, /// The background of the days in the calender of the - /// [`DatePicker`](crate::native::DatePicker). + /// [`DatePicker`](crate::widgets::DatePicker). pub day_background: Background, } -/// The Catalog of a [`DatePicker`](crate::native::DatePicker). +/// The Catalog of a [`DatePicker`](crate::widgets::DatePicker). pub trait Catalog { ///Style for the trait to use. type Class<'a>; @@ -55,7 +55,7 @@ impl Catalog for Theme { } } -/// The primary theme of a [`Badge`](crate::native::badge::Badge). +/// The primary theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn primary(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); diff --git a/src/style/number_input.rs b/src/style/number_input.rs index cae1aefa..e5d2656a 100644 --- a/src/style/number_input.rs +++ b/src/style/number_input.rs @@ -5,12 +5,12 @@ use super::{Status, StyleFn}; use iced::{widget, Background, Color, Theme}; -/// The appearance of a [`NumberInput`](crate::native::number_input::NumberInput). +/// The appearance of a [`NumberInput`](crate::widgets::number_input::NumberInput). #[derive(Clone, Copy, Debug)] pub struct Style { - /// The background of the [`NumberInput`](crate::native::number_input::NumberInput). + /// The background of the [`NumberInput`](crate::widgets::number_input::NumberInput). pub button_background: Option, - /// The Color of the arrows of [`NumberInput`](crate::native::number_input::NumberInput). + /// The Color of the arrows of [`NumberInput`](crate::widgets::number_input::NumberInput). pub icon_color: Color, } @@ -23,7 +23,7 @@ impl Default for Style { } } -/// The Catalog of a [`NumberInput`](crate::native::number_input::NumberInput). +/// The Catalog of a [`NumberInput`](crate::widgets::number_input::NumberInput). pub trait Catalog { ///Style for the trait to use. type Class<'a>; @@ -47,7 +47,7 @@ impl Catalog for Theme { } } -/// The Extended Catalog of a [`NumberInput`](crate::native::number_input::NumberInput). +/// The Extended Catalog of a [`NumberInput`](crate::widgets::number_input::NumberInput). pub trait ExtendedCatalog: widget::text_input::Catalog + widget::container::Catalog + widget::text::Catalog + self::Catalog { @@ -67,7 +67,7 @@ impl ExtendedCatalog for Theme { } } -/// The primary theme of a [`Badge`](crate::native::badge::Badge). +/// The primary theme of a [`Badge`](crate::widgets::badge::Badge). #[must_use] pub fn primary(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); diff --git a/src/style/selection_list.rs b/src/style/selection_list.rs index c473c029..34497789 100644 --- a/src/style/selection_list.rs +++ b/src/style/selection_list.rs @@ -2,13 +2,12 @@ //! //! *This API requires the following crate features to be activated: `selection_list`* -use std::rc::Rc; - +use super::{Status, StyleFn}; use iced::{Background, Color, Theme}; /// The appearance of a menu. #[derive(Debug, Clone, Copy)] -pub struct Appearance { +pub struct Style { /// The List Label Text Color pub text_color: Color, /// The background @@ -17,74 +16,59 @@ pub struct Appearance { pub border_width: f32, /// The container Border color pub border_color: Color, - /// The List Label Text Select Color - pub hovered_text_color: Color, - /// The List Label Text Select Background Color - pub hovered_background: Background, - /// The List Label Text Select Color - pub selected_text_color: Color, - /// The List Label Text Select Background Color - pub selected_background: Background, } -impl std::default::Default for Appearance { +impl std::default::Default for Style { fn default() -> Self { Self { text_color: Color::BLACK, background: Background::Color([0.87, 0.87, 0.87].into()), border_width: 1.0, border_color: [0.7, 0.7, 0.7].into(), - hovered_text_color: Color::WHITE, - hovered_background: Background::Color([0.0, 0.5, 1.0].into()), - selected_text_color: Color::WHITE, - selected_background: Background::Color([0.2, 0.5, 0.8].into()), } } } -/// A set of rules that dictate the style of a container. -pub trait StyleSheet { +/// The Catalog of a [`Badge`](crate::widgets::selection_list::SelectionList). +pub trait Catalog { ///Style for the trait to use. - type Style: Default + Clone; - /// Produces the style of a container. - fn style(&self, style: &Self::Style) -> Appearance; -} + type Class<'a>; + + /// The default class produced by the [`Catalog`]. + fn default<'a>() -> Self::Class<'a>; -#[derive(Clone, Default)] -#[allow(missing_docs, clippy::missing_docs_in_private_items)] -/// Default Prebuilt ``SelectionList`` Styles -pub enum SelectionListStyles { - #[default] - Default, - Custom(Rc>), + /// The [`Style`] of a class with the given status. + fn style(&self, class: &Self::Class<'_>, status: Status) -> Style; } -impl SelectionListStyles { - /// Creates a custom [`SelectionListStyles`] style variant. - pub fn custom(style_sheet: impl StyleSheet