diff options
author | 2023-09-14 13:58:36 -0700 | |
---|---|---|
committer | 2023-11-14 11:31:44 +0100 | |
commit | 781ef1f94c4859aeeb852f801b72be095b8ff82b (patch) | |
tree | 63e2678eca11dd41c26a40633c04341fd795d733 /renderer/src/widget/shader/program.rs | |
parent | 817f72868746461891ca4e74473c555f3b5c5703 (diff) | |
download | iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.gz iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.bz2 iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.zip |
Added support for custom shader widget for iced_wgpu backend.
Diffstat (limited to 'renderer/src/widget/shader/program.rs')
-rw-r--r-- | renderer/src/widget/shader/program.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/renderer/src/widget/shader/program.rs b/renderer/src/widget/shader/program.rs new file mode 100644 index 00000000..b8871688 --- /dev/null +++ b/renderer/src/widget/shader/program.rs @@ -0,0 +1,60 @@ +use crate::core::{event, mouse, Rectangle, Shell}; +use crate::widget; +use widget::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::widget::shader::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: shader::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::widget::shader::Shader + fn mouse_interaction( + &self, + _state: &Self::State, + _bounds: Rectangle, + _cursor: mouse::Cursor, + ) -> mouse::Interaction { + mouse::Interaction::default() + } +} |