summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-10-19 18:20:09 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2024-10-19 18:21:48 +1300
commit990f2b310bfecf2e04a8a462f6939833080c62bf (patch)
treebbbbb65a3cfcbaec71935b581e7162a28947f960 /src/lib.rs
parent824483fc95ccbc4627d07371bac8ed4da44c83e7 (diff)
downloadphosphor-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/lib.rs')
-rw-r--r--src/lib.rs63
1 files changed, 13 insertions, 50 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3255b0a..f856775 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,56 +1,19 @@
-mod render;
+mod events;
mod window;
-mod window_controller;
-mod window_manager;
+mod window_builder;
+mod window_program;
+mod phosphor;
-pub use render::*;
-pub use window::*;
-pub use window_controller::*;
-pub use window_manager::*;
+pub use events::{Request, Event, Action, Axis, MouseButton, SizeBounds};
+pub(crate) use window::PhosphorWindow;
+pub use window_builder::WindowBuilder;
+pub use window_program::WindowProgram;
pub use buffer::*;
-pub use winit::{
- event::{ModifiersState, ElementState},
- event::VirtualKeyCode as KeyCode,
- window::CursorIcon,
-};
-pub use std::num::NonZeroU32;
+pub use phosphor::Phosphor;
+pub use event_queue::EventWriter;
-// -----------------------------------------------------------------------------
+pub use winit::keyboard::{KeyCode, ModifiersState};
-#[derive(Copy, Clone)]
-pub struct KeyboardInput {
- pub action: Action,
- pub key: KeyCode,
-}
-
-impl TryFrom<winit::event::KeyboardInput> for KeyboardInput {
- type Error = ();
-
- fn try_from(input: winit::event::KeyboardInput) -> Result<Self, ()> {
- if let Some(key) = input.virtual_keycode {
- Ok( Self { action: input.state.into(), key } )
- } else {
- Err(())
- }
- }
-}
-
-// -----------------------------------------------------------------------------
-
-#[derive(Clone, Copy, PartialEq, Debug)]
-pub enum Action { Pressed, Released }
-
-impl Action {
- pub fn is_pressed(&self) -> bool { *self == Self::Pressed }
- pub fn is_released(&self) -> bool { *self == Self::Released }
-}
-
-impl From<ElementState> for Action {
- fn from(value: ElementState) -> Self {
- match value {
- ElementState::Pressed => Action::Pressed,
- ElementState::Released => Action::Released,
- }
- }
-}
+pub type Position = geometry::Point<i32>;
+pub type Dimensions = geometry::Dimensions<u32>;