Use `f64` type in layout

This commit is contained in:
Gabriel Majeri 2020-07-15 19:42:37 +03:00 committed by Keavon Chambers
parent e8058513f3
commit 420314d0b3
3 changed files with 9 additions and 9 deletions

View File

@ -108,7 +108,7 @@ impl Attribute {
} }
/// Extracts a percentage from this attribute's value. /// Extracts a percentage from this attribute's value.
fn percent(self) -> f32 { fn percent(self) -> f64 {
match self.dimension() { match self.dimension() {
Dimension::Percent(value) => value, Dimension::Percent(value) => value,
_ => panic!("expected a percentage"), _ => panic!("expected a percentage"),
@ -151,8 +151,8 @@ pub enum AttributeValue {
pub struct LayoutAttributes { pub struct LayoutAttributes {
pub width: Dimension, pub width: Dimension,
pub height: Dimension, pub height: Dimension,
pub x_align: f32, pub x_align: f64,
pub y_align: f32, pub y_align: f64,
pub spacing: BoxDimensions, pub spacing: BoxDimensions,
pub padding: BoxDimensions, pub padding: BoxDimensions,
} }

View File

@ -76,11 +76,11 @@ pub enum TemplateStringSegment {
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum Dimension { pub enum Dimension {
/// Absolute value in pixels. /// Absolute value in pixels.
AbsolutePx(f32), AbsolutePx(f64),
/// Percent of parent container size along the same axis. /// Percent of parent container size along the same axis.
Percent(f32), Percent(f64),
/// Percent of free space remaining in parent container. /// Percent of free space remaining in parent container.
PercentRemainder(f32), PercentRemainder(f64),
/// Minimum size required to fit the children. /// Minimum size required to fit the children.
Inner, Inner,
/// Size relative to the width of this component. /// Size relative to the width of this component.

View File

@ -128,7 +128,7 @@ impl AttributeParser {
// AbsolutePx: px // AbsolutePx: px
Some([value, px]) if px.eq_ignore_ascii_case("px") => { Some([value, px]) if px.eq_ignore_ascii_case("px") => {
let pixels = value let pixels = value
.parse::<f32>() .parse::<f64>()
.expect(&format!("Invalid value `{}` specified in the attribute type`{}` when parsing XML layout", value, attribute_type)[..]); .expect(&format!("Invalid value `{}` specified in the attribute type`{}` when parsing XML layout", value, attribute_type)[..]);
let dimension = Dimension::AbsolutePx(pixels); let dimension = Dimension::AbsolutePx(pixels);
TypeValueOrArgument::TypeValue(TypeValue::Dimension(dimension)) TypeValueOrArgument::TypeValue(TypeValue::Dimension(dimension))
@ -136,7 +136,7 @@ impl AttributeParser {
// Percent: ?% // Percent: ?%
Some([value, "%"]) => { Some([value, "%"]) => {
let percent = value let percent = value
.parse::<f32>() .parse::<f64>()
.expect(&format!("Invalid value `{}` specified in the attribute type `{}` when parsing XML layout", value, attribute_type)[..]); .expect(&format!("Invalid value `{}` specified in the attribute type `{}` when parsing XML layout", value, attribute_type)[..]);
let dimension = Dimension::Percent(percent); let dimension = Dimension::Percent(percent);
TypeValueOrArgument::TypeValue(TypeValue::Dimension(dimension)) TypeValueOrArgument::TypeValue(TypeValue::Dimension(dimension))
@ -144,7 +144,7 @@ impl AttributeParser {
// PercentRemainder: ?@ // PercentRemainder: ?@
Some([value, "@"]) => { Some([value, "@"]) => {
let percent_remainder = value let percent_remainder = value
.parse::<f32>() .parse::<f64>()
.expect(&format!("Invalid value `{}` specified in the attribute type `{}` when parsing XML layout", value, attribute_type)[..]); .expect(&format!("Invalid value `{}` specified in the attribute type `{}` when parsing XML layout", value, attribute_type)[..]);
let dimension = Dimension::PercentRemainder(percent_remainder); let dimension = Dimension::PercentRemainder(percent_remainder);
TypeValueOrArgument::TypeValue(TypeValue::Dimension(dimension)) TypeValueOrArgument::TypeValue(TypeValue::Dimension(dimension))