diff options
| author | HampusM <hampus@hampusmat.com> | 2026-07-17 01:23:25 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-07-17 01:23:25 +0200 |
| commit | 7b25df4c4dc3ead44dc02015fcc46c1ccb283b8e (patch) | |
| tree | 4ff162b57ce32e1444851ba685c3e5ac6093c03b /engine/src/windowing | |
| parent | e32c20e5d9693bc0ac5b3e371823a4de978cb4e6 (diff) | |
feat(engine): add Reflection derives to various types
Diffstat (limited to 'engine/src/windowing')
| -rw-r--r-- | engine/src/windowing/dpi.rs | 87 | ||||
| -rw-r--r-- | engine/src/windowing/mouse.rs | 5 | ||||
| -rw-r--r-- | engine/src/windowing/window.rs | 10 |
3 files changed, 60 insertions, 42 deletions
diff --git a/engine/src/windowing/dpi.rs b/engine/src/windowing/dpi.rs index e11fa25..d628709 100644 --- a/engine/src/windowing/dpi.rs +++ b/engine/src/windowing/dpi.rs @@ -1,3 +1,5 @@ +use crate::reflection::Reflection; + macro_rules! gen_struct_from_to_impls { ($struct: ident, fields=($($field: ident),*)) => { impl<Pixel> From<winit::dpi::$struct<Pixel>> for $struct<Pixel> @@ -46,78 +48,88 @@ macro_rules! gen_enum_from_to_impls { }; } -#[derive(Debug, Default, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq, Reflection)] +#[reflection(impl_with_generics(<u32>, <i32>, <f32>, <f64>))] pub struct PhysicalPosition<Pixel> { pub x: Pixel, - pub y: Pixel + pub y: Pixel, } impl<Pixel> PhysicalPosition<Pixel> { - pub fn to_logical<LogicalPixel>(&self, scale_factor: f64) -> LogicalPosition<LogicalPixel> + pub fn to_logical<LogicalPixel>( + &self, + scale_factor: f64, + ) -> LogicalPosition<LogicalPixel> where Pixel: Into<f64> + Clone, - LogicalPixel: From<f64> + LogicalPixel: From<f64>, { let x = self.x.clone().into(); let y = self.y.clone().into(); LogicalPosition { x: (x / scale_factor).into(), - y: (y / scale_factor).into() + y: (y / scale_factor).into(), } } - pub fn try_convert_from<SourcePixel>(source: PhysicalPosition<SourcePixel>) -> Result<Self, Pixel::Error> + pub fn try_convert_from<SourcePixel>( + source: PhysicalPosition<SourcePixel>, + ) -> Result<Self, Pixel::Error> where - Pixel: TryFrom<SourcePixel> + Pixel: TryFrom<SourcePixel>, { Ok(Self { x: source.x.try_into()?, - y: source.y.try_into()? + y: source.y.try_into()?, }) } } -gen_struct_from_to_impls!(PhysicalPosition, fields=(x, y)); +gen_struct_from_to_impls!(PhysicalPosition, fields = (x, y)); -#[derive(Debug, Default, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq, Reflection)] +#[reflection(impl_with_generics(<f64>))] pub struct LogicalPosition<Pixel> { pub x: Pixel, - pub y: Pixel + pub y: Pixel, } impl<Pixel> LogicalPosition<Pixel> { - pub fn try_convert_from<SourcePixel>(source: LogicalPosition<SourcePixel>) -> Result<Self, Pixel::Error> + pub fn try_convert_from<SourcePixel>( + source: LogicalPosition<SourcePixel>, + ) -> Result<Self, Pixel::Error> where - Pixel: TryFrom<SourcePixel> + Pixel: TryFrom<SourcePixel>, { Ok(Self { x: source.x.try_into()?, - y: source.y.try_into()? + y: source.y.try_into()?, }) } } -gen_struct_from_to_impls!(LogicalPosition, fields=(x, y)); +gen_struct_from_to_impls!(LogicalPosition, fields = (x, y)); -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Reflection)] pub enum Position { Physical(PhysicalPosition<i32>), - Logical(LogicalPosition<f64>) + Logical(LogicalPosition<f64>), } -gen_enum_from_to_impls!(Position, variants=(Physical, Logical)); +gen_enum_from_to_impls!(Position, variants = (Physical, Logical)); -#[derive(Debug, Default, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq, Reflection)] +#[reflection(impl_with_generics(<u32>))] pub struct PhysicalSize<Pixel> { pub width: Pixel, - pub height: Pixel + pub height: Pixel, } impl<Pixel> PhysicalSize<Pixel> @@ -125,60 +137,65 @@ impl<Pixel> PhysicalSize<Pixel> pub fn to_logical<LogicalPixel>(&self, scale_factor: f64) -> LogicalSize<LogicalPixel> where Pixel: Into<f64> + Clone, - LogicalPixel: From<f64> + LogicalPixel: From<f64>, { let width = self.width.clone().into(); let height = self.height.clone().into(); LogicalSize { width: (width / scale_factor).into(), - height: (height / scale_factor).into() + height: (height / scale_factor).into(), } } } impl<Pixel> PhysicalSize<Pixel> { - pub fn try_convert_from<SourcePixel>(source: PhysicalSize<SourcePixel>) -> Result<Self, Pixel::Error> + pub fn try_convert_from<SourcePixel>( + source: PhysicalSize<SourcePixel>, + ) -> Result<Self, Pixel::Error> where - Pixel: TryFrom<SourcePixel> + Pixel: TryFrom<SourcePixel>, { Ok(Self { width: source.width.try_into()?, - height: source.height.try_into()? + height: source.height.try_into()?, }) } } -gen_struct_from_to_impls!(PhysicalSize, fields=(width, height)); +gen_struct_from_to_impls!(PhysicalSize, fields = (width, height)); -#[derive(Debug, Default, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq, Reflection)] +#[reflection(impl_with_generics(<f64>))] pub struct LogicalSize<Pixel> { pub width: Pixel, - pub height: Pixel + pub height: Pixel, } impl<Pixel> LogicalSize<Pixel> { - pub fn try_convert_from<SourcePixel>(source: LogicalSize<SourcePixel>) -> Result<Self, Pixel::Error> + pub fn try_convert_from<SourcePixel>( + source: LogicalSize<SourcePixel>, + ) -> Result<Self, Pixel::Error> where - Pixel: TryFrom<SourcePixel> + Pixel: TryFrom<SourcePixel>, { Ok(Self { width: source.width.try_into()?, - height: source.height.try_into()? + height: source.height.try_into()?, }) } } -gen_struct_from_to_impls!(LogicalSize, fields=(width, height)); +gen_struct_from_to_impls!(LogicalSize, fields = (width, height)); -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Reflection)] pub enum Size { Physical(PhysicalSize<u32>), - Logical(LogicalSize<f64>) + Logical(LogicalSize<f64>), } -gen_enum_from_to_impls!(Size, variants=(Physical, Logical)); +gen_enum_from_to_impls!(Size, variants = (Physical, Logical)); diff --git a/engine/src/windowing/mouse.rs b/engine/src/windowing/mouse.rs index 3145a17..93a0d93 100644 --- a/engine/src/windowing/mouse.rs +++ b/engine/src/windowing/mouse.rs @@ -1,10 +1,11 @@ use std::collections::HashMap; use crate::ecs::Sole; +use crate::reflection::Reflection; use crate::vector::Vec2; use crate::windowing::dpi::PhysicalPosition; -#[derive(Debug, Default, Clone, Sole)] +#[derive(Debug, Default, Clone, Sole, Reflection)] #[non_exhaustive] pub struct Mouse { @@ -21,7 +22,7 @@ pub struct Mouse pub curr_tick_scroll_delta: ScrollDelta, } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, Reflection)] pub struct ScrollDelta { pub vert_lines: f32, diff --git a/engine/src/windowing/window.rs b/engine/src/windowing/window.rs index 8f95dc8..54c24ac 100644 --- a/engine/src/windowing/window.rs +++ b/engine/src/windowing/window.rs @@ -21,7 +21,7 @@ impl Id } } -#[derive(Debug, Component, Clone)] +#[derive(Debug, Component, Clone, Reflection)] #[non_exhaustive] pub struct CreationAttributes { @@ -165,7 +165,7 @@ impl Default for CreationAttributes } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Reflection)] #[non_exhaustive] pub enum Fullscreen { @@ -173,7 +173,7 @@ pub enum Fullscreen } /// Window icon -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Reflection)] #[non_exhaustive] pub enum Icon { @@ -183,7 +183,7 @@ pub enum Icon WindowsResource(Cow<'static, str>), } -#[derive(Debug, Component, Clone, Copy)] +#[derive(Debug, Default, Component, Clone, Copy, Reflection)] pub struct CreationReady; #[derive(Debug, Component, Reflection)] @@ -254,7 +254,7 @@ impl Window } } -#[derive(Debug, Component)] +#[derive(Debug, Component, Reflection)] pub struct Closed; #[derive( |
