Improve Rust geom code

This commit is contained in:
Alex Kotov 2022-09-07 21:09:24 +04:00
parent 2e6bc7ac0c
commit 7a82bfad36
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 30 additions and 0 deletions

View File

@ -28,6 +28,24 @@ pub struct WinGeom {
border_width: c_int,
}
impl From<Sizes> for Position {
fn from(sizes: Sizes) -> Self {
Self::new(sizes.width, sizes.height)
}
}
impl From<Position> for Sizes {
fn from(position: Position) -> Self {
Self::new(position.x, position.y)
}
}
impl From<BasicGeom> for WinGeom {
fn from(basic_geom: BasicGeom) -> Self {
Self::new(basic_geom, 0)
}
}
impl Position {
pub fn new(x: c_int, y: c_int) -> Self {
Self { x, y }
@ -201,6 +219,18 @@ mod tests {
assert_eq!(WinGeom::default(), WinGeom::new(Default::default(), 0));
}
#[test]
fn position_into_sizes() {
let sizes: Sizes = Position::new(123, 456).into();
assert_eq!(sizes, Sizes::new(123, 456));
}
#[test]
fn sizes_into_position() {
let position: Position = Sizes::new(123, 456).into();
assert_eq!(position, Position::new(123, 456));
}
#[test]
fn win_geom_total_position() {
let position = Position::new(34, 56);