1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Geometry types for wxDragon (Point, Size, Rect)
//!
//! This module contains the basic geometry types used throughout
//! the wxDragon library, providing conversions to and from the FFI types.
use wxdragon_sys as ffi;
/// Standard window position type.
///
/// Represents a point in 2D space with x, y coordinates.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Point {
pub x: i32,
pub y: i32,
}
impl Point {
/// Creates a new Point.
pub fn new(x: i32, y: i32) -> Self {
Point { x, y }
}
/// Default position (-1, -1) that lets the system choose the position.
pub const DEFAULT_POSITION: Point = Point { x: -1, y: -1 };
}
impl From<Point> for ffi::wxd_Point {
fn from(p: Point) -> Self {
ffi::wxd_Point { x: p.x, y: p.y }
}
}
impl From<ffi::wxd_Point> for Point {
fn from(p: ffi::wxd_Point) -> Self {
Point { x: p.x, y: p.y }
}
}
/// Standard window size type.
///
/// Represents a size in 2D space with width and height.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Size {
pub width: i32,
pub height: i32,
}
impl Size {
/// Creates a new Size.
pub fn new(width: i32, height: i32) -> Self {
Size { width, height }
}
/// Default size (-1, -1) that lets the system choose the size.
pub const DEFAULT_SIZE: Size = Size { width: -1, height: -1 };
}
impl From<Size> for ffi::wxd_Size {
fn from(s: Size) -> Self {
ffi::wxd_Size {
width: s.width,
height: s.height,
}
}
}
impl From<ffi::wxd_Size> for Size {
fn from(s: ffi::wxd_Size) -> Self {
Size {
width: s.width,
height: s.height,
}
}
}
/// Represents a rectangle with position (x, y) and dimensions (width, height).
///
/// Combines Point and Size to define a rectangular area.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Rect {
pub x: i32,
pub y: i32,
pub width: i32,
pub height: i32,
}
impl Rect {
/// Creates a new rectangle.
pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
Self { x, y, width, height }
}
/// Creates a rectangle from a position and size.
pub fn from_point_and_size(pos: Point, size: Size) -> Self {
Self {
x: pos.x,
y: pos.y,
width: size.width,
height: size.height,
}
}
/// Returns the position component of the rectangle.
pub fn position(&self) -> Point {
Point::new(self.x, self.y)
}
/// Returns the size component of the rectangle.
pub fn size(&self) -> Size {
Size::new(self.width, self.height)
}
}
impl From<Rect> for ffi::wxd_Rect {
fn from(rect: Rect) -> Self {
ffi::wxd_Rect {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
}
}
}
impl From<ffi::wxd_Rect> for Rect {
fn from(wxd_rect: ffi::wxd_Rect) -> Self {
Self {
x: wxd_rect.x,
y: wxd_rect.y,
width: wxd_rect.width,
height: wxd_rect.height,
}
}
}