Improve Rust geom code
This commit is contained in:
parent
2e6bc7ac0c
commit
7a82bfad36
1 changed files with 30 additions and 0 deletions
30
src/geom.rs
30
src/geom.rs
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue