Skip to content

Commit

Permalink
feat: add special platform event
Browse files Browse the repository at this point in the history
There are many different events in different platform, so they should
not included in any of the events, like touch, window or etc. This maybe
will make the production platform plugin more flexible
  • Loading branch information
Decodetalkers committed Nov 2, 2024
1 parent 50340b4 commit 9bc22d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ pub enum Event {

/// A touch event
Touch(touch::Event),

/// Special platform event
Special(Box<dyn SpecialEvent + Send>),
}

/// Define the trait without Clone and PartialEq
pub trait SpecialEvent: std::fmt::Debug {
/// check if it is equal
fn equal(&self, other: &dyn SpecialEvent) -> bool;

/// We add a `clone_box` method for cloning trait objects
fn clone_box(&self) -> Box<dyn SpecialEvent + Send>;
}

// Implement `CustomInner` for `Clone`
impl Clone for Box<dyn SpecialEvent + Send> {
fn clone(&self) -> Box<dyn SpecialEvent + Send> {
self.clone_box()
}
}

// Example implementation for PartialEq
impl PartialEq for Box<dyn SpecialEvent + Send> {
fn eq(&self, other: &Self) -> bool {
self.equal(&(**other)) // Customize this equality check as needed
}
}

/// The status of an [`Event`] after being processed.
Expand Down
1 change: 1 addition & 0 deletions widget/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ where
Some(Event::Keyboard(keyboard_event))
}
core::Event::Window(_) => None,
core::Event::Special(_) => None,
};

if let Some(canvas_event) = canvas_event {
Expand Down
1 change: 1 addition & 0 deletions widget/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ where
Some(Event::RedrawRequested(instant))
}
core::Event::Window(_) => None,
core::Event::Special(_) => None,
};

if let Some(custom_shader_event) = custom_shader_event {
Expand Down

0 comments on commit 9bc22d2

Please sign in to comment.