diff --git a/CHANGELOG.md b/CHANGELOG.md index 8660cc5a01..748bdfd01b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `hovered` styling for `Svg` widget. [#2163](https://github.com/iced-rs/iced/pull/2163) - `height` method for `TextEditor`. [#2221](https://github.com/iced-rs/iced/pull/2221) - Customizable style for `TextEditor`. [#2159](https://github.com/iced-rs/iced/pull/2159) +- Customizable style for `QRCode`. [#2229](https://github.com/iced-rs/iced/pull/2229) - Border width styling for `Toggler`. [#2219](https://github.com/iced-rs/iced/pull/2219) - `RawText` variant for `Primitive` in `iced_graphics`. [#2158](https://github.com/iced-rs/iced/pull/2158) - `Stream` support for `Command`. [#2150](https://github.com/iced-rs/iced/pull/2150) @@ -38,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Custom` variant to `command::Action`. [#2146](https://github.com/iced-rs/iced/pull/2146) - Mouse movement events for `MouseArea`. [#2147](https://github.com/iced-rs/iced/pull/2147) - Dracula, Nord, Solarized, and Gruvbox variants for `Theme`. [#2170](https://github.com/iced-rs/iced/pull/2170) +- Catppuccin, Tokyo Night, Kanagawa, Moonfly, Nightfly and Oxocarbon variants for `Theme`. [#2233](https://github.com/iced-rs/iced/pull/2233) + - `From where T: Into` for `svg::Handle`. [#2235](https://github.com/iced-rs/iced/pull/2235) - `on_open` and `on_close` handlers for `PickList`. [#2174](https://github.com/iced-rs/iced/pull/2174) - Support for generic `Element` in `Tooltip`. [#2228](https://github.com/iced-rs/iced/pull/2228) @@ -102,6 +105,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Subscription::map` using unreliable function pointer hash to identify mappers. [#2237](https://github.com/iced-rs/iced/pull/2237) - Missing feature flag docs for `time::every`. [#2188](https://github.com/iced-rs/iced/pull/2188) - Event loop not being resumed on Windows while resizing. [#2214](https://github.com/iced-rs/iced/pull/2214) +- Alpha mode misconfiguration in `iced_wgpu`. [#2231](https://github.com/iced-rs/iced/pull/2231) +- Outdated documentation leading to a dead link. [#2232](https://github.com/iced-rs/iced/pull/2232) Many thanks to... @@ -116,6 +121,7 @@ Many thanks to... - @Calastrophe - @casperstorm - @cfrenette +- @clarkmoody - @Davidster - @Decodetalkers - @derezzedex @@ -132,6 +138,8 @@ Many thanks to... - @jim-ec - @joshuamegnauth54 - @jpttrssn +- @julianbraha +- @Koranir - @lufte - @matze - @MichalLebeda diff --git a/examples/gradient/Cargo.toml b/examples/gradient/Cargo.toml index 2dea2c4f59..8102b8665f 100644 --- a/examples/gradient/Cargo.toml +++ b/examples/gradient/Cargo.toml @@ -5,4 +5,7 @@ edition = "2021" publish = false [dependencies] -iced = { path = "../.." } +iced.workspace = true +iced.features = ["debug"] + +tracing-subscriber = "0.3" diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 1bf5822dc3..32b2e4aaa6 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,11 +1,23 @@ -use iced::gradient; -use iced::widget::{column, container, horizontal_space, row, slider, text}; +use iced::application; +use iced::theme::{self, Theme}; +use iced::widget::{ + checkbox, column, container, horizontal_space, row, slider, text, +}; +use iced::{gradient, window}; use iced::{ Alignment, Background, Color, Element, Length, Radians, Sandbox, Settings, }; pub fn main() -> iced::Result { - Gradient::run(Settings::default()) + tracing_subscriber::fmt::init(); + + Gradient::run(Settings { + window: window::Settings { + transparent: true, + ..Default::default() + }, + ..Default::default() + }) } #[derive(Debug, Clone, Copy)] @@ -13,6 +25,7 @@ struct Gradient { start: Color, end: Color, angle: Radians, + transparent: bool, } #[derive(Debug, Clone, Copy)] @@ -20,6 +33,7 @@ enum Message { StartChanged(Color), EndChanged(Color), AngleChanged(Radians), + TransparentToggled(bool), } impl Sandbox for Gradient { @@ -30,6 +44,7 @@ impl Sandbox for Gradient { start: Color::WHITE, end: Color::new(0.0, 0.0, 1.0, 1.0), angle: Radians(0.0), + transparent: false, } } @@ -42,11 +57,19 @@ impl Sandbox for Gradient { Message::StartChanged(color) => self.start = color, Message::EndChanged(color) => self.end = color, Message::AngleChanged(angle) => self.angle = angle, + Message::TransparentToggled(transparent) => { + self.transparent = transparent; + } } } fn view(&self) -> Element { - let Self { start, end, angle } = *self; + let Self { + start, + end, + angle, + transparent, + } = *self; let gradient_box = container(horizontal_space(Length::Fill)) .width(Length::Fill) @@ -72,14 +95,34 @@ impl Sandbox for Gradient { .padding(8) .align_items(Alignment::Center); + let transparency_toggle = iced::widget::Container::new( + checkbox("Transparent window", transparent) + .on_toggle(Message::TransparentToggled), + ) + .padding(8); + column![ color_picker("Start", self.start).map(Message::StartChanged), color_picker("End", self.end).map(Message::EndChanged), angle_picker, - gradient_box + transparency_toggle, + gradient_box, ] .into() } + + fn style(&self) -> theme::Application { + if self.transparent { + theme::Application::custom(|theme: &Theme| { + application::Appearance { + background_color: Color::TRANSPARENT, + text_color: theme.palette().text, + } + }) + } else { + theme::Application::Default + } + } } fn color_picker(label: &str, color: Color) -> Element<'_, Color> { @@ -91,6 +134,8 @@ fn color_picker(label: &str, color: Color) -> Element<'_, Color> { .step(0.01), slider(0.0..=1.0, color.b, move |b| { Color { b, ..color } }) .step(0.01), + slider(0.0..=1.0, color.a, move |a| { Color { a, ..color } }) + .step(0.01), ] .spacing(8) .padding(8) diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index 867ebfa415..8b2e950020 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -1,6 +1,6 @@ use iced::widget::qr_code::{self, QRCode}; -use iced::widget::{column, container, text, text_input}; -use iced::{Alignment, Color, Element, Length, Sandbox, Settings}; +use iced::widget::{column, container, pick_list, row, text, text_input}; +use iced::{Alignment, Element, Length, Sandbox, Settings, Theme}; pub fn main() -> iced::Result { QRGenerator::run(Settings::default()) @@ -9,12 +9,14 @@ pub fn main() -> iced::Result { #[derive(Default)] struct QRGenerator { data: String, - qr_code: Option, + qr_code: Option, + theme: Theme, } #[derive(Debug, Clone)] enum Message { DataChanged(String), + ThemeChanged(Theme), } impl Sandbox for QRGenerator { @@ -36,18 +38,19 @@ impl Sandbox for QRGenerator { self.qr_code = if data.is_empty() { None } else { - qr_code::State::new(&data).ok() + qr_code::Data::new(&data).ok() }; self.data = data; } + Message::ThemeChanged(theme) => { + self.theme = theme; + } } } fn view(&self) -> Element { - let title = text("QR Code Generator") - .size(70) - .style(Color::from([0.5, 0.5, 0.5])); + let title = text("QR Code Generator").size(70); let input = text_input("Type the data of your QR code here...", &self.data) @@ -55,7 +58,18 @@ impl Sandbox for QRGenerator { .size(30) .padding(15); - let mut content = column![title, input] + let choose_theme = row![ + text("Theme:"), + pick_list( + Theme::ALL, + Some(self.theme.clone()), + Message::ThemeChanged, + ) + ] + .spacing(10) + .align_items(Alignment::Center); + + let mut content = column![title, input, choose_theme] .width(700) .spacing(20) .align_items(Alignment::Center); @@ -72,4 +86,8 @@ impl Sandbox for QRGenerator { .center_y() .into() } + + fn theme(&self) -> Theme { + self.theme.clone() + } } diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 82421a8684..a58ca683df 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -88,7 +88,7 @@ impl Application for SolarSystem { } } - theme::Application::from(dark_background as fn(&Theme) -> _) + theme::Application::custom(dark_background) } fn subscription(&self) -> Subscription { diff --git a/examples/websocket/Cargo.toml b/examples/websocket/Cargo.toml index 8f1b876a0e..c7075fb301 100644 --- a/examples/websocket/Cargo.toml +++ b/examples/websocket/Cargo.toml @@ -13,7 +13,7 @@ once_cell.workspace = true warp = "0.3" [dependencies.async-tungstenite] -version = "0.24" +version = "0.25" features = ["tokio-rustls-webpki-roots"] [dependencies.tokio] diff --git a/graphics/src/text.rs b/graphics/src/text.rs index 7c4b5e31fe..217a23e2e4 100644 --- a/graphics/src/text.rs +++ b/graphics/src/text.rs @@ -98,12 +98,7 @@ pub fn measure(buffer: &cosmic_text::Buffer) -> Size { (run.line_w.max(width), total_lines + 1) }); - let (max_width, max_height) = buffer.size(); - - Size::new( - width.min(max_width), - (total_lines as f32 * buffer.metrics().line_height).min(max_height), - ) + Size::new(width, total_lines as f32 * buffer.metrics().line_height) } /// Returns the attributes of the given [`Font`]. diff --git a/style/src/lib.rs b/style/src/lib.rs index e4097434c1..3c2865ebeb 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -24,6 +24,7 @@ pub mod menu; pub mod pane_grid; pub mod pick_list; pub mod progress_bar; +pub mod qr_code; pub mod radio; pub mod rule; pub mod scrollable; diff --git a/style/src/qr_code.rs b/style/src/qr_code.rs new file mode 100644 index 0000000000..02c4709a5f --- /dev/null +++ b/style/src/qr_code.rs @@ -0,0 +1,20 @@ +//! Change the appearance of a QR code. +use crate::core::Color; + +/// The appearance of a QR code. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Appearance { + /// The color of the QR code data cells + pub cell: Color, + /// The color of the QR code background + pub background: Color, +} + +/// A set of rules that dictate the style of a QR code. +pub trait StyleSheet { + /// The supported style of the [`StyleSheet`]. + type Style: Default; + + /// Produces the style of a QR code. + fn appearance(&self, style: &Self::Style) -> Appearance; +} diff --git a/style/src/theme.rs b/style/src/theme.rs index e579a1c20d..5909498f0d 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -12,6 +12,7 @@ use crate::menu; use crate::pane_grid; use crate::pick_list; use crate::progress_bar; +use crate::qr_code; use crate::radio; use crate::rule; use crate::scrollable; @@ -47,6 +48,32 @@ pub enum Theme { GruvboxLight, /// The built-in Gruvbox Dark variant. GruvboxDark, + /// The built-in Catppuccin Latte variant. + CatppuccinLatte, + /// The built-in Catppuccin Frappé variant. + CatppuccinFrappe, + /// The built-in Catppuccin Macchiato variant. + CatppuccinMacchiato, + /// The built-in Catppuccin Mocha variant. + CatppuccinMocha, + /// The built-in Tokyo Night variant. + TokyoNight, + /// The built-in Tokyo Night Storm variant. + TokyoNightStorm, + /// The built-in Tokyo Night Light variant. + TokyoNightLight, + /// The built-in Kanagawa Wave variant. + KanagawaWave, + /// The built-in Kanagawa Dragon variant. + KanagawaDragon, + /// The built-in Kanagawa Lotus variant. + KanagawaLotus, + /// The built-in Moonfly variant. + Moonfly, + /// The built-in Nightfly variant. + Nightfly, + /// The built-in Oxocarbon variant. + Oxocarbon, /// A [`Theme`] that uses a [`Custom`] palette. Custom(Arc), } @@ -62,6 +89,19 @@ impl Theme { Self::SolarizedDark, Self::GruvboxLight, Self::GruvboxDark, + Self::CatppuccinLatte, + Self::CatppuccinFrappe, + Self::CatppuccinMacchiato, + Self::CatppuccinMocha, + Self::TokyoNight, + Self::TokyoNightStorm, + Self::TokyoNightLight, + Self::KanagawaWave, + Self::KanagawaDragon, + Self::KanagawaLotus, + Self::Moonfly, + Self::Nightfly, + Self::Oxocarbon, ]; /// Creates a new custom [`Theme`] from the given [`Palette`]. @@ -90,6 +130,19 @@ impl Theme { Self::SolarizedDark => Palette::SOLARIZED_DARK, Self::GruvboxLight => Palette::GRUVBOX_LIGHT, Self::GruvboxDark => Palette::GRUVBOX_DARK, + Self::CatppuccinLatte => Palette::CATPPUCCIN_LATTE, + Self::CatppuccinFrappe => Palette::CATPPUCCIN_FRAPPE, + Self::CatppuccinMacchiato => Palette::CATPPUCCIN_MACCHIATO, + Self::CatppuccinMocha => Palette::CATPPUCCIN_MOCHA, + Self::TokyoNight => Palette::TOKYO_NIGHT, + Self::TokyoNightStorm => Palette::TOKYO_NIGHT_STORM, + Self::TokyoNightLight => Palette::TOKYO_NIGHT_LIGHT, + Self::KanagawaWave => Palette::KANAGAWA_WAVE, + Self::KanagawaDragon => Palette::KANAGAWA_DRAGON, + Self::KanagawaLotus => Palette::KANAGAWA_LOTUS, + Self::Moonfly => Palette::MOONFLY, + Self::Nightfly => Palette::NIGHTFLY, + Self::Oxocarbon => Palette::OXOCARBON, Self::Custom(custom) => custom.palette, } } @@ -105,6 +158,21 @@ impl Theme { Self::SolarizedDark => &palette::EXTENDED_SOLARIZED_DARK, Self::GruvboxLight => &palette::EXTENDED_GRUVBOX_LIGHT, Self::GruvboxDark => &palette::EXTENDED_GRUVBOX_DARK, + Self::CatppuccinLatte => &palette::EXTENDED_CATPPUCCIN_LATTE, + Self::CatppuccinFrappe => &palette::EXTENDED_CATPPUCCIN_FRAPPE, + Self::CatppuccinMacchiato => { + &palette::EXTENDED_CATPPUCCIN_MACCHIATO + } + Self::CatppuccinMocha => &palette::EXTENDED_CATPPUCCIN_MOCHA, + Self::TokyoNight => &palette::EXTENDED_TOKYO_NIGHT, + Self::TokyoNightStorm => &palette::EXTENDED_TOKYO_NIGHT_STORM, + Self::TokyoNightLight => &palette::EXTENDED_TOKYO_NIGHT_LIGHT, + Self::KanagawaWave => &palette::EXTENDED_KANAGAWA_WAVE, + Self::KanagawaDragon => &palette::EXTENDED_KANAGAWA_DRAGON, + Self::KanagawaLotus => &palette::EXTENDED_KANAGAWA_LOTUS, + Self::Moonfly => &palette::EXTENDED_MOONFLY, + Self::Nightfly => &palette::EXTENDED_NIGHTFLY, + Self::Oxocarbon => &palette::EXTENDED_OXOCARBON, Self::Custom(custom) => &custom.extended, } } @@ -121,6 +189,19 @@ impl fmt::Display for Theme { Self::SolarizedDark => write!(f, "Solarized Dark"), Self::GruvboxLight => write!(f, "Gruvbox Light"), Self::GruvboxDark => write!(f, "Gruvbox Dark"), + Self::CatppuccinLatte => write!(f, "Catppuccin Latte"), + Self::CatppuccinFrappe => write!(f, "Catppuccin Frappé"), + Self::CatppuccinMacchiato => write!(f, "Catppuccin Macchiato"), + Self::CatppuccinMocha => write!(f, "Catppuccin Mocha"), + Self::TokyoNight => write!(f, "Tokyo Night"), + Self::TokyoNightStorm => write!(f, "Tokyo Night Storm"), + Self::TokyoNightLight => write!(f, "Tokyo Night Light"), + Self::KanagawaWave => write!(f, "Kanagawa Wave"), + Self::KanagawaDragon => write!(f, "Kanagawa Dragon"), + Self::KanagawaLotus => write!(f, "Kanagawa Lotus"), + Self::Moonfly => write!(f, "Moonfly"), + Self::Nightfly => write!(f, "Nightfly"), + Self::Oxocarbon => write!(f, "Oxocarbon"), Self::Custom(custom) => custom.fmt(f), } } @@ -171,6 +252,15 @@ pub enum Application { Custom(Box>), } +impl Application { + /// Creates a custom [`Application`] style. + pub fn custom( + custom: impl application::StyleSheet