Skip to content

Commit

Permalink
Implement Display for Val (#10296)
Browse files Browse the repository at this point in the history
# Objective

Implement `Display` for `Val`

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
  • Loading branch information
ickshonpe and alice-i-cecile committed Oct 28, 2023
1 parent c959c1b commit 6d7808d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_reflect::ReflectDeserialize;
use bevy_reflect::ReflectSerialize;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Display;
use std::ops::Neg;
use std::ops::{Div, DivAssign, Mul, MulAssign};
use thiserror::Error;
Expand Down Expand Up @@ -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 {
type Output = Val;

Expand Down

0 comments on commit 6d7808d

Please sign in to comment.