Implement Display
for Val
(#10296)
# Objective Implement `Display` for `Val` --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
c959c1ba58
commit
6d7808da74
@ -4,6 +4,7 @@ use bevy_reflect::ReflectDeserialize;
|
|||||||
use bevy_reflect::ReflectSerialize;
|
use bevy_reflect::ReflectSerialize;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::fmt::Display;
|
||||||
use std::ops::Neg;
|
use std::ops::Neg;
|
||||||
use std::ops::{Div, DivAssign, Mul, MulAssign};
|
use std::ops::{Div, DivAssign, Mul, MulAssign};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@ -155,6 +156,22 @@ impl DivAssign<f32> for Val {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Val {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let (value, suffix) = match self {
|
||||||
|
Val::Auto => return write!(f, "auto"),
|
||||||
|
Val::Px(value) => (value, "px"),
|
||||||
|
Val::Percent(value) => (value, "%"),
|
||||||
|
Val::Vw(value) => (value, "vw"),
|
||||||
|
Val::Vh(value) => (value, "vh"),
|
||||||
|
Val::VMin(value) => (value, "vmin"),
|
||||||
|
Val::VMax(value) => (value, "vmax"),
|
||||||
|
};
|
||||||
|
value.fmt(f)?;
|
||||||
|
write!(f, "{suffix}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Neg for Val {
|
impl Neg for Val {
|
||||||
type Output = Val;
|
type Output = Val;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user