diff options
author | 2023-11-14 20:59:49 +0100 | |
---|---|---|
committer | 2023-11-14 20:59:49 +0100 | |
commit | b474a2b7a763dcde6a377cb409001a7b5285ee8d (patch) | |
tree | 6e751607bb103e7011807a45797923d86214d88d /widget/src/shader/program.rs | |
parent | 817f72868746461891ca4e74473c555f3b5c5703 (diff) | |
parent | 0968c5b64a528ff92a5a93f6586eef557546da25 (diff) | |
download | iced-b474a2b7a763dcde6a377cb409001a7b5285ee8d.tar.gz iced-b474a2b7a763dcde6a377cb409001a7b5285ee8d.tar.bz2 iced-b474a2b7a763dcde6a377cb409001a7b5285ee8d.zip |
Merge pull request #2085 from bungoboingo/shader-widget
[Feature] Custom Shader Widget
Diffstat (limited to 'widget/src/shader/program.rs')
-rw-r--r-- | widget/src/shader/program.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/widget/src/shader/program.rs b/widget/src/shader/program.rs new file mode 100644 index 00000000..6dd50404 --- /dev/null +++ b/widget/src/shader/program.rs @@ -0,0 +1,62 @@ +use crate::core::event; +use crate::core::mouse; +use crate::core::{Rectangle, Shell}; +use crate::renderer::wgpu::primitive::pipeline; +use crate::shader; + +/// The state and logic of a [`Shader`] widget. +/// +/// A [`Program`] can mutate the internal state of a [`Shader`] widget +/// and produce messages for an application. +/// +/// [`Shader`]: crate::Shader +pub trait Program<Message> { + /// The internal state of the [`Program`]. + type State: Default + 'static; + + /// The type of primitive this [`Program`] can draw. + type Primitive: pipeline::Primitive + 'static; + + /// Update the internal [`State`] of the [`Program`]. This can be used to reflect state changes + /// based on mouse & other events. You can use the [`Shell`] to publish messages, request a + /// redraw for the window, etc. + /// + /// By default, this method does and returns nothing. + /// + /// [`State`]: Self::State + fn update( + &self, + _state: &mut Self::State, + _event: shader::Event, + _bounds: Rectangle, + _cursor: mouse::Cursor, + _shell: &mut Shell<'_, Message>, + ) -> (event::Status, Option<Message>) { + (event::Status::Ignored, None) + } + + /// Draws the [`Primitive`]. + /// + /// [`Primitive`]: Self::Primitive + fn draw( + &self, + state: &Self::State, + cursor: mouse::Cursor, + bounds: Rectangle, + ) -> Self::Primitive; + + /// Returns the current mouse interaction of the [`Program`]. + /// + /// The interaction returned will be in effect even if the cursor position is out of + /// bounds of the [`Shader`]'s program. + /// + /// [`Shader`]: crate::Shader + fn mouse_interaction( + &self, + _state: &Self::State, + _bounds: Rectangle, + _cursor: mouse::Cursor, + ) -> mouse::Interaction { + mouse::Interaction::default() + } +} |