diff options
author | 2024-03-16 17:09:00 +0100 | |
---|---|---|
committer | 2024-03-16 17:09:00 +0100 | |
commit | 503a48e89977437bf8b7bf485f416a15a2e83ed0 (patch) | |
tree | 30306bbaee7a31090ace9d7725d46c2c0027fe6b /examples/custom_shader | |
parent | 0524e9b4571d264018656418f02a1f9e27e268d7 (diff) | |
parent | cfc0383bbfff083786840e3f1fd499e5991fa629 (diff) | |
download | iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.gz iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.bz2 iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.zip |
Merge pull request #2331 from iced-rs/program-api
`Program` API
Diffstat (limited to 'examples/custom_shader')
-rw-r--r-- | examples/custom_shader/src/main.rs | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 9e8da3ba..341b77b6 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -2,18 +2,16 @@ 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("Custom Shader - Iced", IcedCubes::update, IcedCubes::view) + .subscription(IcedCubes::subscription) + .run() } struct IcedCubes { @@ -30,27 +28,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 +54,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 +131,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>>, |