2020-02-09 05:32:56 +01:00
|
|
|
use iced_wgpu::Renderer;
|
2025-01-24 15:55:24 +01:00
|
|
|
use iced_widget::{bottom, column, row, slider, text, text_input};
|
|
|
|
|
use iced_winit::core::{Color, Element, Theme};
|
2020-02-09 05:32:56 +01:00
|
|
|
|
|
|
|
|
pub struct Controls {
|
2020-05-21 04:54:26 +02:00
|
|
|
background_color: Color,
|
2024-03-04 19:31:26 +01:00
|
|
|
input: String,
|
2020-02-09 05:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-08 02:07:45 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2020-02-09 05:32:56 +01:00
|
|
|
pub enum Message {
|
|
|
|
|
BackgroundColorChanged(Color),
|
2024-03-04 19:31:26 +01:00
|
|
|
InputChanged(String),
|
2020-02-09 05:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Controls {
|
|
|
|
|
pub fn new() -> Controls {
|
|
|
|
|
Controls {
|
2020-05-21 04:54:26 +02:00
|
|
|
background_color: Color::BLACK,
|
2024-03-04 19:31:26 +01:00
|
|
|
input: String::default(),
|
2020-02-09 05:32:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 04:54:26 +02:00
|
|
|
pub fn background_color(&self) -> Color {
|
|
|
|
|
self.background_color
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-04 19:11:37 +01:00
|
|
|
impl Controls {
|
|
|
|
|
pub fn update(&mut self, message: Message) {
|
2020-02-09 05:32:56 +01:00
|
|
|
match message {
|
|
|
|
|
Message::BackgroundColorChanged(color) => {
|
2020-05-21 04:54:26 +02:00
|
|
|
self.background_color = color;
|
2020-02-09 05:32:56 +01:00
|
|
|
}
|
2024-03-04 19:31:26 +01:00
|
|
|
Message::InputChanged(input) => {
|
|
|
|
|
self.input = input;
|
2021-10-21 22:42:14 +03:00
|
|
|
}
|
2020-02-09 05:32:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 14:29:36 +02:00
|
|
|
pub fn view(&self) -> Element<'_, Message, Theme, Renderer> {
|
2020-05-21 04:54:26 +02:00
|
|
|
let background_color = self.background_color;
|
2020-02-09 05:32:56 +01:00
|
|
|
|
2024-03-04 19:31:26 +01:00
|
|
|
let sliders = row![
|
|
|
|
|
slider(0.0..=1.0, background_color.r, move |r| {
|
|
|
|
|
Message::BackgroundColorChanged(Color {
|
|
|
|
|
r,
|
|
|
|
|
..background_color
|
2020-05-21 04:54:26 +02:00
|
|
|
})
|
2024-03-04 19:31:26 +01:00
|
|
|
})
|
|
|
|
|
.step(0.01),
|
|
|
|
|
slider(0.0..=1.0, background_color.g, move |g| {
|
|
|
|
|
Message::BackgroundColorChanged(Color {
|
|
|
|
|
g,
|
|
|
|
|
..background_color
|
2020-05-21 04:54:26 +02:00
|
|
|
})
|
2024-03-04 19:31:26 +01:00
|
|
|
})
|
|
|
|
|
.step(0.01),
|
|
|
|
|
slider(0.0..=1.0, background_color.b, move |b| {
|
|
|
|
|
Message::BackgroundColorChanged(Color {
|
|
|
|
|
b,
|
|
|
|
|
..background_color
|
2020-05-21 04:54:26 +02:00
|
|
|
})
|
2024-03-04 19:31:26 +01:00
|
|
|
})
|
|
|
|
|
.step(0.01),
|
|
|
|
|
]
|
|
|
|
|
.width(500)
|
|
|
|
|
.spacing(20);
|
2020-02-09 05:32:56 +01:00
|
|
|
|
2025-01-24 15:55:24 +01:00
|
|
|
bottom(
|
2024-03-04 19:31:26 +01:00
|
|
|
column![
|
|
|
|
|
text("Background color").color(Color::WHITE),
|
2024-03-18 18:24:57 -03:00
|
|
|
text!("{background_color:?}").size(14).color(Color::WHITE),
|
2024-03-04 19:31:26 +01:00
|
|
|
sliders,
|
2025-01-24 15:55:24 +01:00
|
|
|
text_input("Type something...", &self.input)
|
|
|
|
|
.on_input(Message::InputChanged),
|
2024-03-04 19:31:26 +01:00
|
|
|
]
|
|
|
|
|
.spacing(10),
|
|
|
|
|
)
|
|
|
|
|
.padding(10)
|
|
|
|
|
.into()
|
2020-02-09 05:32:56 +01:00
|
|
|
}
|
|
|
|
|
}
|