veloren/voxygen/src/ui/span.rs
Joshua Barretto c16a257ae3 Added server-cli, UI tests
Former-commit-id: 93bf5b39138920aa7a4a773a8247d716866c4a05
2019-01-30 12:11:34 +00:00

48 lines
1.0 KiB
Rust

// Standard
use std::ops::{Add, Sub};
#[derive(Copy, Clone)]
pub struct Span {
pub rel: f32,
pub abs: f32,
}
impl Span {
pub fn rel(rel: f32) -> Self { Self { rel, abs: 0.0 } }
pub fn abs(abs: f32) -> Self { Self { rel: 0.0, abs } }
pub fn full() -> Self { Self { rel: 1.0, abs: 0.0 } }
pub fn half() -> Self { Self { rel: 0.5, abs: 0.0 } }
pub fn none() -> Self { Self { rel: 0.0, abs: 0.0 } }
pub fn to_abs(self, res: f32) -> Self {
Self { rel: 0.0, abs: self.rel * res + self.abs }
}
pub fn to_rel(self, res: f32) -> Self {
Self { rel: self.rel + self.abs / res, abs: 0.0 }
}
}
impl Add for Span {
type Output = Self;
fn add(self, other: Self) -> Self {
Self {
rel: self.rel + other.rel,
abs: self.abs + other.abs,
}
}
}
impl Sub for Span {
type Output = Self;
fn sub(self, other: Self) -> Self {
Self {
rel: self.rel - other.rel,
abs: self.abs - other.abs,
}
}
}