summaryrefslogtreecommitdiffstats
path: root/examples/custom_shader/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/custom_shader/src/main.rs')
-rw-r--r--examples/custom_shader/src/main.rs49
1 files changed, 20 insertions, 29 deletions
diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs
index 9e8da3ba..5ba9a5d4 100644
--- a/examples/custom_shader/src/main.rs
+++ b/examples/custom_shader/src/main.rs
@@ -2,18 +2,17 @@ mod scene;
use scene::Scene;
-use iced::executor;
use iced::time::Instant;
use iced::widget::shader::wgpu;
use iced::widget::{checkbox, column, container, row, shader, slider, text};
use iced::window;
-use iced::{
- Alignment, Application, Color, Command, Element, Length, Subscription,
- Theme,
-};
+use iced::{Alignment, Color, Element, Length, Subscription};
fn main() -> iced::Result {
- IcedCubes::run(iced::Settings::default())
+ iced::sandbox(IcedCubes::update, IcedCubes::view)
+ .subscription(IcedCubes::subscription)
+ .title("Custom Shader - Iced")
+ .run()
}
struct IcedCubes {
@@ -30,27 +29,15 @@ enum Message {
LightColorChanged(Color),
}
-impl Application for IcedCubes {
- type Executor = executor::Default;
- type Message = Message;
- type Theme = Theme;
- type Flags = ();
-
- fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) {
- (
- Self {
- start: Instant::now(),
- scene: Scene::new(),
- },
- Command::none(),
- )
- }
-
- fn title(&self) -> String {
- "Iced Cubes".to_string()
+impl IcedCubes {
+ fn new() -> Self {
+ Self {
+ start: Instant::now(),
+ scene: Scene::new(),
+ }
}
- fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
+ fn update(&mut self, message: Message) {
match message {
Message::CubeAmountChanged(amount) => {
self.scene.change_amount(amount);
@@ -68,11 +55,9 @@ impl Application for IcedCubes {
self.scene.light_color = color;
}
}
-
- Command::none()
}
- fn view(&self) -> Element<'_, Self::Message> {
+ fn view(&self) -> Element<'_, Message> {
let top_controls = row![
control(
"Amount",
@@ -147,11 +132,17 @@ impl Application for IcedCubes {
.into()
}
- fn subscription(&self) -> Subscription<Self::Message> {
+ fn subscription(&self) -> Subscription<Message> {
window::frames().map(Message::Tick)
}
}
+impl Default for IcedCubes {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
fn control<'a>(
label: &'static str,
control: impl Into<Element<'a, Message>>,