summaryrefslogtreecommitdiffstats
path: root/examples/integration/src/controls.rs
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-07-12 12:23:18 -0700
committerLibravatar Bingus <shankern@protonmail.com>2023-07-12 12:23:18 -0700
commit633f405f3f78bc7f82d2b2061491b0e011137451 (patch)
tree5ebfc1f45d216a5c14a90492563599e6969eab4d /examples/integration/src/controls.rs
parent41836dd80d0534608e7aedfbf2319c540a23de1a (diff)
parent21bd51426d900e271206f314e0c915dd41065521 (diff)
downloadiced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.gz
iced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.bz2
iced-633f405f3f78bc7f82d2b2061491b0e011137451.zip
Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts: # Cargo.toml # core/src/window/icon.rs # core/src/window/id.rs # core/src/window/position.rs # core/src/window/settings.rs # examples/integration/src/main.rs # examples/integration_opengl/src/main.rs # glutin/src/application.rs # native/src/subscription.rs # native/src/window.rs # runtime/src/window/action.rs # src/lib.rs # src/window.rs # winit/Cargo.toml # winit/src/application.rs # winit/src/icon.rs # winit/src/settings.rs # winit/src/window.rs
Diffstat (limited to 'examples/integration/src/controls.rs')
-rw-r--r--examples/integration/src/controls.rs113
1 files changed, 113 insertions, 0 deletions
diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs
new file mode 100644
index 00000000..14e53ede
--- /dev/null
+++ b/examples/integration/src/controls.rs
@@ -0,0 +1,113 @@
+use iced_wgpu::Renderer;
+use iced_widget::{slider, text_input, Column, Row, Text};
+use iced_winit::core::{Alignment, Color, Element, Length};
+use iced_winit::runtime::{Command, Program};
+use iced_winit::style::Theme;
+
+pub struct Controls {
+ background_color: Color,
+ text: String,
+}
+
+#[derive(Debug, Clone)]
+pub enum Message {
+ BackgroundColorChanged(Color),
+ TextChanged(String),
+}
+
+impl Controls {
+ pub fn new() -> Controls {
+ Controls {
+ background_color: Color::BLACK,
+ text: Default::default(),
+ }
+ }
+
+ pub fn background_color(&self) -> Color {
+ self.background_color
+ }
+}
+
+impl Program for Controls {
+ type Renderer = Renderer<Theme>;
+ type Message = Message;
+
+ fn update(&mut self, message: Message) -> Command<Message> {
+ match message {
+ Message::BackgroundColorChanged(color) => {
+ self.background_color = color;
+ }
+ Message::TextChanged(text) => {
+ self.text = text;
+ }
+ }
+
+ Command::none()
+ }
+
+ fn view(&self) -> Element<Message, Renderer<Theme>> {
+ let background_color = self.background_color;
+ let text = &self.text;
+
+ let sliders = Row::new()
+ .width(500)
+ .spacing(20)
+ .push(
+ slider(0.0..=1.0, background_color.r, move |r| {
+ Message::BackgroundColorChanged(Color {
+ r,
+ ..background_color
+ })
+ })
+ .step(0.01),
+ )
+ .push(
+ slider(0.0..=1.0, background_color.g, move |g| {
+ Message::BackgroundColorChanged(Color {
+ g,
+ ..background_color
+ })
+ })
+ .step(0.01),
+ )
+ .push(
+ slider(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(Alignment::End)
+ .push(
+ Column::new()
+ .width(Length::Fill)
+ .align_items(Alignment::End)
+ .push(
+ Column::new()
+ .padding(10)
+ .spacing(10)
+ .push(
+ Text::new("Background color")
+ .style(Color::WHITE),
+ )
+ .push(sliders)
+ .push(
+ Text::new(format!("{background_color:?}"))
+ .size(14)
+ .style(Color::WHITE),
+ )
+ .push(
+ text_input("Placeholder", text)
+ .on_input(Message::TextChanged),
+ ),
+ ),
+ )
+ .into()
+ }
+}