summaryrefslogtreecommitdiffstats
path: root/examples/integration/src/controls.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-02-10 19:49:08 +0100
committerLibravatar GitHub <noreply@github.com>2020-02-10 19:49:08 +0100
commit5d16f431b3088189579cf096b3abf89578cc73f6 (patch)
treec7efea00fabd87133a59760e902548d39822a844 /examples/integration/src/controls.rs
parent95880ca74bddb6a23774621ef766b91956d40a61 (diff)
parent4337daddb2a02a2c60dfc5beb896e3059588312a (diff)
downloadiced-5d16f431b3088189579cf096b3abf89578cc73f6.tar.gz
iced-5d16f431b3088189579cf096b3abf89578cc73f6.tar.bz2
iced-5d16f431b3088189579cf096b3abf89578cc73f6.zip
Merge pull request #183 from hecrj/feature/wgpu-integration
Integration with existing `wgpu` projects
Diffstat (limited to 'examples/integration/src/controls.rs')
-rw-r--r--examples/integration/src/controls.rs102
1 files changed, 102 insertions, 0 deletions
diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs
new file mode 100644
index 00000000..0457a058
--- /dev/null
+++ b/examples/integration/src/controls.rs
@@ -0,0 +1,102 @@
+use crate::Scene;
+
+use iced_wgpu::Renderer;
+use iced_winit::{
+ slider, Align, Color, Column, Element, Length, Row, Slider, Text,
+};
+
+pub struct Controls {
+ sliders: [slider::State; 3],
+}
+
+#[derive(Debug)]
+pub enum Message {
+ BackgroundColorChanged(Color),
+}
+
+impl Controls {
+ pub fn new() -> Controls {
+ Controls {
+ sliders: Default::default(),
+ }
+ }
+
+ pub fn update(&self, message: Message, scene: &mut Scene) {
+ match message {
+ Message::BackgroundColorChanged(color) => {
+ scene.background_color = color;
+ }
+ }
+ }
+
+ pub fn view<'a>(
+ &'a mut self,
+ scene: &Scene,
+ ) -> Element<'a, Message, Renderer> {
+ let [r, g, b] = &mut self.sliders;
+ let background_color = scene.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| {
+ Message::BackgroundColorChanged(Color {
+ r,
+ ..background_color
+ })
+ },
+ ))
+ .push(Slider::new(
+ g,
+ 0.0..=1.0,
+ scene.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| {
+ Message::BackgroundColorChanged(Color {
+ b,
+ ..background_color
+ })
+ },
+ ));
+
+ 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()
+ }
+}