summaryrefslogtreecommitdiffstats
path: root/examples/integration/src/controls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/integration/src/controls.rs')
-rw-r--r--examples/integration/src/controls.rs64
1 files changed, 35 insertions, 29 deletions
diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs
index 0999336b..824f9f53 100644
--- a/examples/integration/src/controls.rs
+++ b/examples/integration/src/controls.rs
@@ -1,15 +1,15 @@
-use crate::Scene;
-
use iced_wgpu::Renderer;
use iced_winit::{
- slider, Align, Color, Column, Element, Length, Row, Slider, Text,
+ slider, Align, Color, Column, Command, Element, Length, Program, Row,
+ Slider, Text,
};
pub struct Controls {
+ background_color: Color,
sliders: [slider::State; 3],
}
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub enum Message {
BackgroundColorChanged(Color),
}
@@ -17,58 +17,64 @@ pub enum Message {
impl Controls {
pub fn new() -> Controls {
Controls {
+ background_color: Color::BLACK,
sliders: Default::default(),
}
}
- pub fn update(&self, message: Message, scene: &mut Scene) {
+ 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) => {
- scene.background_color = color;
+ self.background_color = color;
}
}
+
+ Command::none()
}
- pub fn view(&mut self, scene: &Scene) -> Element<Message, Renderer> {
+ fn view(&mut self) -> Element<Message, Renderer> {
let [r, g, b] = &mut self.sliders;
- let background_color = scene.background_color;
+ let background_color = self.background_color;
let sliders = Row::new()
.width(Length::Units(500))
.spacing(20)
- .push(Slider::new(
- r,
- 0.0..=1.0,
- scene.background_color.r,
- move |r| {
+ .push(
+ Slider::new(r, 0.0..=1.0, background_color.r, move |r| {
Message::BackgroundColorChanged(Color {
r,
..background_color
})
- },
- ))
- .push(Slider::new(
- g,
- 0.0..=1.0,
- scene.background_color.g,
- move |g| {
+ })
+ .step(0.01),
+ )
+ .push(
+ Slider::new(g, 0.0..=1.0, background_color.g, move |g| {
Message::BackgroundColorChanged(Color {
g,
..background_color
})
- },
- ))
- .push(Slider::new(
- b,
- 0.0..=1.0,
- scene.background_color.b,
- move |b| {
+ })
+ .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)