From 712c8e53f2385ed425173cab327e06a214248579 Mon Sep 17 00:00:00 2001 From: Daniel Yoon <101683475+Koranir@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:27:24 +1100 Subject: Fix alpha mode configuration in `iced_wgpu` --- examples/gradient/src/main.rs | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 1bf5822d..5fbf1c54 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,11 +1,20 @@ -use iced::gradient; -use iced::widget::{column, container, horizontal_space, row, slider, text}; +use iced::theme::Palette; +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()) + Gradient::run(Settings { + window: window::Settings { + transparent: true, + ..Default::default() + }, + ..Default::default() + }) } #[derive(Debug, Clone, Copy)] @@ -13,6 +22,7 @@ struct Gradient { start: Color, end: Color, angle: Radians, + transparent_window: bool, } #[derive(Debug, Clone, Copy)] @@ -20,6 +30,7 @@ enum Message { StartChanged(Color), EndChanged(Color), AngleChanged(Radians), + SetTransparent(bool), } impl Sandbox for Gradient { @@ -30,6 +41,7 @@ impl Sandbox for Gradient { start: Color::WHITE, end: Color::new(0.0, 0.0, 1.0, 1.0), angle: Radians(0.0), + transparent_window: false, } } @@ -42,11 +54,19 @@ impl Sandbox for Gradient { Message::StartChanged(color) => self.start = color, Message::EndChanged(color) => self.end = color, Message::AngleChanged(angle) => self.angle = angle, + Message::SetTransparent(transparent) => { + self.transparent_window = transparent; + } } } fn view(&self) -> Element { - let Self { start, end, angle } = *self; + let Self { + start, + end, + angle, + transparent_window, + } = *self; let gradient_box = container(horizontal_space(Length::Fill)) .width(Length::Fill) @@ -72,14 +92,35 @@ impl Sandbox for Gradient { .padding(8) .align_items(Alignment::Center); + let transparency_toggle = iced::widget::Container::new( + checkbox("Transparent window", transparent_window) + .on_toggle(Message::SetTransparent), + ) + .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 theme(&self) -> iced::Theme { + if self.transparent_window { + iced::Theme::custom( + String::new(), + Palette { + background: Color::TRANSPARENT, + ..iced::Theme::default().palette() + }, + ) + } else { + iced::Theme::default() + } + } } fn color_picker(label: &str, color: Color) -> Element<'_, Color> { @@ -91,6 +132,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) -- cgit From 81bed94148dfdc60997d14db603a4c7f2d13bb51 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 10 Feb 2024 00:32:03 +0100 Subject: Use custom `Application::style` to enable transparency --- examples/gradient/src/main.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'examples') diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 5fbf1c54..5eacd7a6 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,4 +1,5 @@ -use iced::theme::Palette; +use iced::application; +use iced::theme::{self, Theme}; use iced::widget::{ checkbox, column, container, horizontal_space, row, slider, text, }; @@ -22,7 +23,7 @@ struct Gradient { start: Color, end: Color, angle: Radians, - transparent_window: bool, + transparent: bool, } #[derive(Debug, Clone, Copy)] @@ -30,7 +31,7 @@ enum Message { StartChanged(Color), EndChanged(Color), AngleChanged(Radians), - SetTransparent(bool), + TransparentToggled(bool), } impl Sandbox for Gradient { @@ -41,7 +42,7 @@ impl Sandbox for Gradient { start: Color::WHITE, end: Color::new(0.0, 0.0, 1.0, 1.0), angle: Radians(0.0), - transparent_window: false, + transparent: false, } } @@ -54,8 +55,8 @@ impl Sandbox for Gradient { Message::StartChanged(color) => self.start = color, Message::EndChanged(color) => self.end = color, Message::AngleChanged(angle) => self.angle = angle, - Message::SetTransparent(transparent) => { - self.transparent_window = transparent; + Message::TransparentToggled(transparent) => { + self.transparent = transparent; } } } @@ -65,7 +66,7 @@ impl Sandbox for Gradient { start, end, angle, - transparent_window, + transparent, } = *self; let gradient_box = container(horizontal_space(Length::Fill)) @@ -93,8 +94,8 @@ impl Sandbox for Gradient { .align_items(Alignment::Center); let transparency_toggle = iced::widget::Container::new( - checkbox("Transparent window", transparent_window) - .on_toggle(Message::SetTransparent), + checkbox("Transparent window", transparent) + .on_toggle(Message::TransparentToggled), ) .padding(8); @@ -108,17 +109,16 @@ impl Sandbox for Gradient { .into() } - fn theme(&self) -> iced::Theme { - if self.transparent_window { - iced::Theme::custom( - String::new(), - Palette { - background: Color::TRANSPARENT, - ..iced::Theme::default().palette() - }, - ) + 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 { - iced::Theme::default() + theme::Application::Default } } } -- cgit From 8a8c1ab2c8a0777425c60d4a36d6dd4b2589501f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 10 Feb 2024 00:38:25 +0100 Subject: Log available formats and alpha modes in `wgpu::window::compositor` --- examples/gradient/Cargo.toml | 5 ++++- examples/gradient/src/main.rs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/gradient/Cargo.toml b/examples/gradient/Cargo.toml index 2dea2c4f..8102b866 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 5eacd7a6..32b2e4aa 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -9,6 +9,8 @@ use iced::{ }; pub fn main() -> iced::Result { + tracing_subscriber::fmt::init(); + Gradient::run(Settings { window: window::Settings { transparent: true, -- cgit From 6600f66cbd7c3c4538c7fd77ba3517fcb60da606 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 10 Feb 2024 00:39:31 +0100 Subject: Fix `style` in `solar_system` example --- examples/solar_system/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 82421a86..a58ca683 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 { -- cgit