diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-19 18:20:09 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-19 18:21:48 +1300 |
commit | 990f2b310bfecf2e04a8a462f6939833080c62bf (patch) | |
tree | bbbbb65a3cfcbaec71935b581e7162a28947f960 /src/render.rs | |
parent | 824483fc95ccbc4627d07371bac8ed4da44c83e7 (diff) | |
download | phosphor-990f2b310bfecf2e04a8a462f6939833080c62bf.zip |
Complete rewrite of Phosphor
The previous version of the library passed events to an implementation
of a WindowController trait by calling the trait method associated with
each event, and received requests by calling different trait methods and
reading the returned values. This had the downside of requiring that any
data received from one event had to be stored in the type so that it
could be passed back to Phosphor when a request method was called.
The new library structure uses a single handle_event method on a trait,
which is passed data representing any single event when it is called.
Data is returned via a passed mutable reference to an EventQueue,
meaning that any number of responses for any event can be immediately
returned to Phosphor without having to wait in storage.
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/src/render.rs b/src/render.rs deleted file mode 100644 index e7ec02d..0000000 --- a/src/render.rs +++ /dev/null @@ -1,67 +0,0 @@ -/// Tells a window controller whether the previous render state is intact and -/// can be updated, or was destroyed and needs to be fully redrawn. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum RenderHint { - /// The buffer content is unchanged, only updates are required. - Update, - /// The buffer content has been destroyed, a full redraw is required. - Redraw, -} - -impl RenderHint { - pub fn is_update(&self) -> bool { *self == RenderHint::Update } - pub fn is_redraw(&self) -> bool { *self == RenderHint::Redraw } -} - -impl std::ops::BitAnd for RenderHint { - type Output = RenderHint; - fn bitand(self, other: RenderHint) -> Self::Output { - if self == RenderHint::Redraw || other == RenderHint::Redraw { - RenderHint::Redraw - } else { - RenderHint::Update - } - } -} - -impl std::ops::BitAndAssign for RenderHint { - fn bitand_assign(&mut self, other: RenderHint) { - *self = *self & other; - } -} - -/// A request to the window manager for a render pass to be run. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum RenderRequest { - None, - Render(RenderHint), -} - -impl RenderRequest { - pub const NONE: RenderRequest = RenderRequest::None; - pub const UPDATE: RenderRequest = RenderRequest::Render(RenderHint::Update); - pub const REDRAW: RenderRequest = RenderRequest::Render(RenderHint::Redraw); - - pub fn is_none(&self) -> bool { *self == RenderRequest::None } - pub fn is_some(&self) -> bool { *self != RenderRequest::None } - pub fn is_update(&self) -> bool { *self == RenderRequest::UPDATE } - pub fn is_redraw(&self) -> bool { *self == RenderRequest::REDRAW } -} - -impl std::ops::BitAnd for RenderRequest { - type Output = RenderRequest; - fn bitand(self, other: RenderRequest) -> Self::Output { - use RenderRequest::*; - match (self, other) { - (None, req) => req, - (req, None) => req, - (Render(a), Render(b)) => Render(a & b), - } - } -} - -impl std::ops::BitAndAssign for RenderRequest { - fn bitand_assign(&mut self, other: RenderRequest) { - *self = *self & other; - } -} |