summaryrefslogtreecommitdiffstats
path: root/examples/gradient
diff options
context:
space:
mode:
authorLibravatar Daniel Yoon <101683475+Koranir@users.noreply.github.com>2024-02-03 17:27:24 +1100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-10 00:24:41 +0100
commit712c8e53f2385ed425173cab327e06a214248579 (patch)
tree25db3ee83b7094a316fb494ef4a912dec3334166 /examples/gradient
parent7ee00e751a8fe5cedadeeb478c6f0e7d6a5dc0dc (diff)
downloadiced-712c8e53f2385ed425173cab327e06a214248579.tar.gz
iced-712c8e53f2385ed425173cab327e06a214248579.tar.bz2
iced-712c8e53f2385ed425173cab327e06a214248579.zip
Fix alpha mode configuration in `iced_wgpu`
Diffstat (limited to 'examples/gradient')
-rw-r--r--examples/gradient/src/main.rs53
1 files changed, 48 insertions, 5 deletions
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<Message> {
- 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)