1pub use dpi::*;
6use serde::Serialize;
7
8#[derive(Clone, Copy, Debug, Serialize)]
10pub struct Rect {
11 pub position: dpi::Position,
13 pub size: dpi::Size,
15}
16
17impl Rect {
18 pub fn to_physical<P: dpi::Pixel, S: dpi::Pixel>(self, scale: f64) -> PhysicalRect<P, S> {
19 PhysicalRect {
20 position: self.position.to_physical(scale),
21 size: self.size.to_physical(scale),
22 }
23 }
24
25 pub fn to_logical<P: dpi::Pixel, S: dpi::Pixel>(self, scale: f64) -> LogicalRect<P, S> {
26 LogicalRect {
27 position: self.position.to_logical(scale),
28 size: self.size.to_logical(scale),
29 }
30 }
31}
32
33impl Default for Rect {
34 fn default() -> Self {
35 Self {
36 position: Position::Logical((0, 0).into()),
37 size: Size::Logical((0, 0).into()),
38 }
39 }
40}
41
42#[derive(Clone, Copy, Debug, Serialize)]
44pub struct PhysicalRect<P: dpi::Pixel, S: dpi::Pixel> {
45 pub position: dpi::PhysicalPosition<P>,
47 pub size: dpi::PhysicalSize<S>,
49}
50
51impl<P: dpi::Pixel, S: dpi::Pixel> Default for PhysicalRect<P, S> {
52 fn default() -> Self {
53 Self {
54 position: (0, 0).into(),
55 size: (0, 0).into(),
56 }
57 }
58}
59
60impl<P: dpi::Pixel, S: dpi::Pixel> PhysicalRect<P, S> {
61 pub fn to_logical(self, scale: f64) -> LogicalRect<P, S> {
62 LogicalRect {
63 position: self.position.to_logical(scale),
64 size: self.size.to_logical(scale),
65 }
66 }
67}
68
69#[derive(Clone, Copy, Debug, Serialize)]
71pub struct LogicalRect<P: dpi::Pixel, S: dpi::Pixel> {
72 pub position: dpi::LogicalPosition<P>,
74 pub size: dpi::LogicalSize<S>,
76}
77
78impl<P: dpi::Pixel, S: dpi::Pixel> Default for LogicalRect<P, S> {
79 fn default() -> Self {
80 Self {
81 position: (0, 0).into(),
82 size: (0, 0).into(),
83 }
84 }
85}
86
87impl<P: dpi::Pixel, S: dpi::Pixel> LogicalRect<P, S> {
88 pub fn to_physical(self, scale: f64) -> PhysicalRect<P, S> {
89 PhysicalRect {
90 position: self.position.to_physical(scale),
91 size: self.size.to_physical(scale),
92 }
93 }
94}