This allows us to introduce a platform-specific `Action` to both `iced_native` and `iced_web` and remove the `Clipboard` from `Application::update` to maintain purity. Additionally, this should let us implement further actions to let users query and modify the shell environment (e.g. window, clipboard, and more!)
105 lines
2.9 KiB
Rust
105 lines
2.9 KiB
Rust
use iced_glow::Renderer;
|
|
use iced_glutin::{
|
|
slider, Align, Color, Column, Command, Element, Length, Program, Row,
|
|
Slider, Text,
|
|
};
|
|
|
|
pub struct Controls {
|
|
background_color: Color,
|
|
sliders: [slider::State; 3],
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Message {
|
|
BackgroundColorChanged(Color),
|
|
}
|
|
|
|
impl Controls {
|
|
pub fn new() -> Controls {
|
|
Controls {
|
|
background_color: Color::BLACK,
|
|
sliders: Default::default(),
|
|
}
|
|
}
|
|
|
|
pub fn background_color(&self) -> Color {
|
|
self.background_color
|
|
}
|
|
}
|
|
|
|
impl Program for Controls {
|
|
type Renderer = Renderer;
|
|
type Message = Message;
|
|
|
|
fn update(&mut self, message: Message) -> Command<Message> {
|
|
match message {
|
|
Message::BackgroundColorChanged(color) => {
|
|
self.background_color = color;
|
|
}
|
|
}
|
|
|
|
Command::none()
|
|
}
|
|
|
|
fn view(&mut self) -> Element<Message, Renderer> {
|
|
let [r, g, b] = &mut self.sliders;
|
|
let background_color = self.background_color;
|
|
|
|
let sliders = Row::new()
|
|
.width(Length::Units(500))
|
|
.spacing(20)
|
|
.push(
|
|
Slider::new(r, 0.0..=1.0, background_color.r, move |r| {
|
|
Message::BackgroundColorChanged(Color {
|
|
r,
|
|
..background_color
|
|
})
|
|
})
|
|
.step(0.01),
|
|
)
|
|
.push(
|
|
Slider::new(g, 0.0..=1.0, background_color.g, move |g| {
|
|
Message::BackgroundColorChanged(Color {
|
|
g,
|
|
..background_color
|
|
})
|
|
})
|
|
.step(0.01),
|
|
)
|
|
.push(
|
|
Slider::new(b, 0.0..=1.0, background_color.b, move |b| {
|
|
Message::BackgroundColorChanged(Color {
|
|
b,
|
|
..background_color
|
|
})
|
|
})
|
|
.step(0.01),
|
|
);
|
|
|
|
Row::new()
|
|
.width(Length::Fill)
|
|
.height(Length::Fill)
|
|
.align_items(Align::End)
|
|
.push(
|
|
Column::new()
|
|
.width(Length::Fill)
|
|
.align_items(Align::End)
|
|
.push(
|
|
Column::new()
|
|
.padding(10)
|
|
.spacing(10)
|
|
.push(
|
|
Text::new("Background color")
|
|
.color(Color::WHITE),
|
|
)
|
|
.push(sliders)
|
|
.push(
|
|
Text::new(format!("{:?}", background_color))
|
|
.size(14)
|
|
.color(Color::WHITE),
|
|
),
|
|
),
|
|
)
|
|
.into()
|
|
}
|
|
}
|