Fix alpha mode configuration in iced_wgpu
This commit is contained in:
parent
7ee00e751a
commit
712c8e53f2
2 changed files with 83 additions and 20 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue