Rename Type::Length -> Type::PhysicalLength

This commit is contained in:
Olivier Goffart 2021-04-20 16:40:11 +02:00
parent aa16f0e65a
commit 7ae850d564
13 changed files with 69 additions and 52 deletions

View file

@ -162,7 +162,7 @@ fn to_eval_value<'cx>(
| Type::Int32 | Type::Int32
| Type::Duration | Type::Duration
| Type::Angle | Type::Angle
| Type::Length | Type::PhysicalLength
| Type::LogicalLength | Type::LogicalLength
| Type::Percent | Type::Percent
| Type::UnitProduct(_) => { | Type::UnitProduct(_) => {

View file

@ -99,8 +99,8 @@ impl BuiltinFunction {
BuiltinFunction::ImplicitItemSize => Type::Function { BuiltinFunction::ImplicitItemSize => Type::Function {
return_type: Box::new(Type::Struct { return_type: Box::new(Type::Struct {
fields: [ fields: [
("width".to_string(), Type::Length), ("width".to_string(), Type::PhysicalLength),
("height".to_string(), Type::Length), ("height".to_string(), Type::PhysicalLength),
] ]
.iter() .iter()
.cloned() .cloned()
@ -200,7 +200,7 @@ declare_units! {
// Lengths or Coord // Lengths or Coord
/// Physical pixels /// Physical pixels
Phx = "phx" -> Length, Phx = "phx" -> PhysicalLength,
/// Logical pixels /// Logical pixels
Px = "px" -> LogicalLength, Px = "px" -> LogicalLength,
/// Centimeters /// Centimeters
@ -768,7 +768,7 @@ impl Expression {
self self
} else if ty.can_convert(&target_type) { } else if ty.can_convert(&target_type) {
let from = match (ty, &target_type) { let from = match (ty, &target_type) {
(Type::Length, Type::LogicalLength) => Expression::BinaryExpression { (Type::PhysicalLength, Type::LogicalLength) => Expression::BinaryExpression {
lhs: Box::new(self), lhs: Box::new(self),
rhs: Box::new(Expression::FunctionCall { rhs: Box::new(Expression::FunctionCall {
function: Box::new(Expression::BuiltinFunctionReference( function: Box::new(Expression::BuiltinFunctionReference(
@ -779,7 +779,7 @@ impl Expression {
}), }),
op: '/', op: '/',
}, },
(Type::LogicalLength, Type::Length) => Expression::BinaryExpression { (Type::LogicalLength, Type::PhysicalLength) => Expression::BinaryExpression {
lhs: Box::new(self), lhs: Box::new(self),
rhs: Box::new(Expression::FunctionCall { rhs: Box::new(Expression::FunctionCall {
function: Box::new(Expression::BuiltinFunctionReference( function: Box::new(Expression::BuiltinFunctionReference(
@ -915,7 +915,7 @@ impl Expression {
}, },
Type::Duration => Expression::NumberLiteral(0., Unit::Ms), Type::Duration => Expression::NumberLiteral(0., Unit::Ms),
Type::Angle => Expression::NumberLiteral(0., Unit::Deg), Type::Angle => Expression::NumberLiteral(0., Unit::Deg),
Type::Length => Expression::NumberLiteral(0., Unit::Phx), Type::PhysicalLength => Expression::NumberLiteral(0., Unit::Phx),
Type::LogicalLength => Expression::NumberLiteral(0., Unit::Px), Type::LogicalLength => Expression::NumberLiteral(0., Unit::Px),
Type::Percent => Expression::NumberLiteral(100., Unit::Percent), Type::Percent => Expression::NumberLiteral(100., Unit::Percent),
// FIXME: Is that correct? // FIXME: Is that correct?

View file

@ -240,7 +240,7 @@ impl CppType for Type {
Type::Color => Some("sixtyfps::Color".to_owned()), Type::Color => Some("sixtyfps::Color".to_owned()),
Type::Duration => Some("std::int64_t".to_owned()), Type::Duration => Some("std::int64_t".to_owned()),
Type::Angle => Some("float".to_owned()), Type::Angle => Some("float".to_owned()),
Type::Length => Some("float".to_owned()), Type::PhysicalLength => Some("float".to_owned()),
Type::LogicalLength => Some("float".to_owned()), Type::LogicalLength => Some("float".to_owned()),
Type::Percent => Some("float".to_owned()), Type::Percent => Some("float".to_owned()),
Type::Bool => Some("bool".to_owned()), Type::Bool => Some("bool".to_owned()),
@ -2121,14 +2121,18 @@ impl<'a> LayoutTreeItem<'a> {
let path_layout_item_data = let path_layout_item_data =
|elem: &ElementRc, elem_cpp: &str, component_cpp: &str| { |elem: &ElementRc, elem_cpp: &str, component_cpp: &str| {
let prop_ref = |n: &str| { let prop_ref = |n: &str| {
if elem.borrow().lookup_property(n).property_type == Type::Length { if elem.borrow().lookup_property(n).property_type
== Type::PhysicalLength
{
format!("&{}.{}", elem_cpp, n) format!("&{}.{}", elem_cpp, n)
} else { } else {
"nullptr".to_owned() "nullptr".to_owned()
} }
}; };
let prop_value = |n: &str| { let prop_value = |n: &str| {
if elem.borrow().lookup_property(n).property_type == Type::Length { if elem.borrow().lookup_property(n).property_type
== Type::PhysicalLength
{
let value_accessor = access_member( let value_accessor = access_member(
&elem, &elem,
n, n,

View file

@ -35,7 +35,7 @@ fn rust_type(ty: &Type) -> Option<proc_macro2::TokenStream> {
Type::Color => Some(quote!(sixtyfps::re_exports::Color)), Type::Color => Some(quote!(sixtyfps::re_exports::Color)),
Type::Duration => Some(quote!(i64)), Type::Duration => Some(quote!(i64)),
Type::Angle => Some(quote!(f32)), Type::Angle => Some(quote!(f32)),
Type::Length => Some(quote!(f32)), Type::PhysicalLength => Some(quote!(f32)),
Type::LogicalLength => Some(quote!(f32)), Type::LogicalLength => Some(quote!(f32)),
Type::Percent => Some(quote!(f32)), Type::Percent => Some(quote!(f32)),
Type::Bool => Some(quote!(bool)), Type::Bool => Some(quote!(bool)),
@ -1306,7 +1306,7 @@ fn compile_expression(expr: &Expression, component: &Rc<Component>) -> TokenStre
Type::Int32 Type::Int32
| Type::Float32 | Type::Float32
| Type::Duration | Type::Duration
| Type::Length | Type::PhysicalLength
| Type::LogicalLength | Type::LogicalLength
| Type::Angle | Type::Angle
) => ) =>
@ -1888,7 +1888,9 @@ impl<'a> LayoutTreeItem<'a> {
let path_layout_item_data = let path_layout_item_data =
|elem: &ElementRc, elem_rs: TokenStream, component_rust: TokenStream| { |elem: &ElementRc, elem_rs: TokenStream, component_rust: TokenStream| {
let prop_ref = |n: &str| { let prop_ref = |n: &str| {
if elem.borrow().lookup_property(n).property_type == Type::Length { if elem.borrow().lookup_property(n).property_type
== Type::PhysicalLength
{
let n = format_ident!("{}", n); let n = format_ident!("{}", n);
quote! {Some(& #elem_rs.#n)} quote! {Some(& #elem_rs.#n)}
} else { } else {
@ -1896,7 +1898,9 @@ impl<'a> LayoutTreeItem<'a> {
} }
}; };
let prop_value = |n: &str| { let prop_value = |n: &str| {
if elem.borrow().lookup_property(n).property_type == Type::Length { if elem.borrow().lookup_property(n).property_type
== Type::PhysicalLength
{
let accessor = access_member( let accessor = access_member(
&elem, &elem,
n, n,

View file

@ -43,7 +43,7 @@ pub enum Type {
String, String,
Color, Color,
Duration, Duration,
Length, PhysicalLength,
LogicalLength, LogicalLength,
Angle, Angle,
Percent, Percent,
@ -89,7 +89,7 @@ impl core::cmp::PartialEq for Type {
Type::Color => matches!(other, Type::Color), Type::Color => matches!(other, Type::Color),
Type::Duration => matches!(other, Type::Duration), Type::Duration => matches!(other, Type::Duration),
Type::Angle => matches!(other, Type::Angle), Type::Angle => matches!(other, Type::Angle),
Type::Length => matches!(other, Type::Length), Type::PhysicalLength => matches!(other, Type::PhysicalLength),
Type::LogicalLength => matches!(other, Type::LogicalLength), Type::LogicalLength => matches!(other, Type::LogicalLength),
Type::Percent => matches!(other, Type::Percent), Type::Percent => matches!(other, Type::Percent),
Type::Image => matches!(other, Type::Image), Type::Image => matches!(other, Type::Image),
@ -149,7 +149,7 @@ impl Display for Type {
Type::String => write!(f, "string"), Type::String => write!(f, "string"),
Type::Duration => write!(f, "duration"), Type::Duration => write!(f, "duration"),
Type::Angle => write!(f, "angle"), Type::Angle => write!(f, "angle"),
Type::Length => write!(f, "length"), Type::PhysicalLength => write!(f, "length"),
Type::LogicalLength => write!(f, "logical_length"), Type::LogicalLength => write!(f, "logical_length"),
Type::Percent => write!(f, "percent"), Type::Percent => write!(f, "percent"),
Type::Color => write!(f, "color"), Type::Color => write!(f, "color"),
@ -206,7 +206,7 @@ impl Type {
| Self::Color | Self::Color
| Self::Duration | Self::Duration
| Self::Angle | Self::Angle
| Self::Length | Self::PhysicalLength
| Self::LogicalLength | Self::LogicalLength
| Self::Percent | Self::Percent
| Self::Image | Self::Image
@ -399,8 +399,8 @@ impl Type {
| (Type::Array(_), Type::Model) | (Type::Array(_), Type::Model)
| (Type::Float32, Type::Model) | (Type::Float32, Type::Model)
| (Type::Int32, Type::Model) | (Type::Int32, Type::Model)
| (Type::Length, Type::LogicalLength) | (Type::PhysicalLength, Type::LogicalLength)
| (Type::LogicalLength, Type::Length) | (Type::LogicalLength, Type::PhysicalLength)
| (Type::Percent, Type::Float32) | (Type::Percent, Type::Float32)
| (Type::Brush, Type::Color) | (Type::Brush, Type::Color)
| (Type::Color, Type::Brush) => true, | (Type::Color, Type::Brush) => true,
@ -436,7 +436,7 @@ impl Type {
pub fn default_unit(&self) -> Option<Unit> { pub fn default_unit(&self) -> Option<Unit> {
match self { match self {
Type::Duration => Some(Unit::Ms), Type::Duration => Some(Unit::Ms),
Type::Length => Some(Unit::Phx), Type::PhysicalLength => Some(Unit::Phx),
Type::LogicalLength => Some(Unit::Px), Type::LogicalLength => Some(Unit::Px),
// Unit::Percent is special that it does not combine with other units like // Unit::Percent is special that it does not combine with other units like
Type::Percent => None, Type::Percent => None,

View file

@ -82,7 +82,7 @@ impl LayoutItem {
let p = |unresolved_name: &str| { let p = |unresolved_name: &str| {
let PropertyLookupResult { resolved_name, property_type } = let PropertyLookupResult { resolved_name, property_type } =
e.borrow().lookup_property(unresolved_name); e.borrow().lookup_property(unresolved_name);
if property_type == Type::Length { if property_type == Type::PhysicalLength {
Some(NamedReference::new(e, resolved_name.as_ref())) Some(NamedReference::new(e, resolved_name.as_ref()))
} else { } else {
None None
@ -123,7 +123,7 @@ impl LayoutRect {
element.borrow_mut().property_declarations.insert( element.borrow_mut().property_declarations.insert(
name.to_string(), name.to_string(),
PropertyDeclaration { PropertyDeclaration {
property_type: Type::Length, property_type: Type::PhysicalLength,
node: None, node: None,
..Default::default() ..Default::default()
}, },

View file

@ -48,7 +48,7 @@ pub fn default_geometry(root_component: &Rc<Component>, diag: &mut BuildDiagnost
debug_assert!({ debug_assert!({
let PropertyLookupResult { resolved_name: _, property_type } = let PropertyLookupResult { resolved_name: _, property_type } =
elem.borrow().lookup_property(property); elem.borrow().lookup_property(property);
property_type == Type::Length property_type == Type::PhysicalLength
}); });
elem.borrow_mut().bindings.contains_key(property) elem.borrow_mut().bindings.contains_key(property)
@ -120,7 +120,10 @@ fn fix_percent_size(
if let Some(parent) = parent { if let Some(parent) = parent {
debug_assert_eq!( debug_assert_eq!(
parent.borrow().lookup_property(property), parent.borrow().lookup_property(property),
PropertyLookupResult { resolved_name: property.into(), property_type: Type::Length } PropertyLookupResult {
resolved_name: property.into(),
property_type: Type::PhysicalLength
}
); );
b.expression = Expression::BinaryExpression { b.expression = Expression::BinaryExpression {
lhs: Box::new(std::mem::take(&mut b.expression).maybe_convert_to( lhs: Box::new(std::mem::take(&mut b.expression).maybe_convert_to(
@ -139,7 +142,7 @@ fn fix_percent_size(
fn make_default_100(elem: &ElementRc, parent_element: &ElementRc, property: &str) { fn make_default_100(elem: &ElementRc, parent_element: &ElementRc, property: &str) {
let PropertyLookupResult { resolved_name, property_type } = let PropertyLookupResult { resolved_name, property_type } =
parent_element.borrow().lookup_property(property); parent_element.borrow().lookup_property(property);
if property_type != Type::Length { if property_type != Type::PhysicalLength {
return; return;
} }
elem.borrow_mut().bindings.entry(resolved_name.to_string()).or_insert_with(|| { elem.borrow_mut().bindings.entry(resolved_name.to_string()).or_insert_with(|| {

View file

@ -138,7 +138,7 @@ fn create_coodiate(
parent_element parent_element
.borrow_mut() .borrow_mut()
.property_declarations .property_declarations
.insert(property_name.clone(), Type::Length.into()); .insert(property_name.clone(), Type::PhysicalLength.into());
parent_element.borrow_mut().bindings.insert(property_name.clone(), expression.into()); parent_element.borrow_mut().bindings.insert(property_name.clone(), expression.into());
NamedReference::new(parent_element, &property_name) NamedReference::new(parent_element, &property_name)
} }

View file

@ -133,7 +133,7 @@ impl Expression {
.map(|c| Self::from_codeblock_node(c.into(), ctx)) .map(|c| Self::from_codeblock_node(c.into(), ctx))
}) })
.unwrap_or(Self::Invalid); .unwrap_or(Self::Invalid);
if ctx.property_type == Type::Length && e.ty() == Type::Percent { if ctx.property_type == Type::PhysicalLength && e.ty() == Type::Percent {
// See if a conversion from percentage to lenght is allowed // See if a conversion from percentage to lenght is allowed
const RELATIVE_TO_PARENT_PROPERTIES: [&str; 2] = ["width", "height"]; const RELATIVE_TO_PARENT_PROPERTIES: [&str; 2] = ["width", "height"];
let property_name = ctx.property_name.unwrap_or_default(); let property_name = ctx.property_name.unwrap_or_default();
@ -932,7 +932,7 @@ fn min_max_macro(
Type::Float32 => Type::Float32, Type::Float32 => Type::Float32,
// In case there are other floats, we don't want to conver tthe result to int // In case there are other floats, we don't want to conver tthe result to int
Type::Int32 => Type::Float32, Type::Int32 => Type::Float32,
Type::Length => Type::Length, Type::PhysicalLength => Type::PhysicalLength,
Type::LogicalLength => Type::LogicalLength, Type::LogicalLength => Type::LogicalLength,
Type::Duration => Type::Duration, Type::Duration => Type::Duration,
Type::Angle => Type::Angle, Type::Angle => Type::Angle,

View file

@ -15,21 +15,25 @@ use crate::expression_tree::{BuiltinFunction, Expression};
use crate::langtype::{Enumeration, Type}; use crate::langtype::{Enumeration, Type};
use crate::object_tree::Component; use crate::object_tree::Component;
pub(crate) const RESERVED_GEOMETRY_PROPERTIES: &'static [(&'static str, Type)] = pub(crate) const RESERVED_GEOMETRY_PROPERTIES: &'static [(&'static str, Type)] = &[
&[("x", Type::Length), ("y", Type::Length), ("width", Type::Length), ("height", Type::Length)]; ("x", Type::PhysicalLength),
("y", Type::PhysicalLength),
("width", Type::PhysicalLength),
("height", Type::PhysicalLength),
];
const RESERVED_LAYOUT_PROPERTIES: &'static [(&'static str, Type)] = &[ const RESERVED_LAYOUT_PROPERTIES: &'static [(&'static str, Type)] = &[
("minimum_width", Type::Length), ("minimum_width", Type::PhysicalLength),
("minimum_height", Type::Length), ("minimum_height", Type::PhysicalLength),
("maximum_width", Type::Length), ("maximum_width", Type::PhysicalLength),
("maximum_height", Type::Length), ("maximum_height", Type::PhysicalLength),
("padding", Type::Length), ("padding", Type::PhysicalLength),
("padding_left", Type::Length), ("padding_left", Type::PhysicalLength),
("padding_right", Type::Length), ("padding_right", Type::PhysicalLength),
("padding_top", Type::Length), ("padding_top", Type::PhysicalLength),
("padding_bottom", Type::Length), ("padding_bottom", Type::PhysicalLength),
("preferred_width", Type::Length), ("preferred_width", Type::PhysicalLength),
("preferred_height", Type::Length), ("preferred_height", Type::PhysicalLength),
("horizontal_stretch", Type::Float32), ("horizontal_stretch", Type::Float32),
("vertical_stretch", Type::Float32), ("vertical_stretch", Type::Float32),
("col", Type::Int32), ("col", Type::Int32),
@ -46,9 +50,9 @@ const RESERVED_OTHER_PROPERTIES: &'static [(&'static str, Type)] = &[
]; ];
pub(crate) const RESERVED_DROP_SHADOW_PROPERTIES: &'static [(&'static str, Type)] = &[ pub(crate) const RESERVED_DROP_SHADOW_PROPERTIES: &'static [(&'static str, Type)] = &[
("drop_shadow_offset_x", Type::Length), ("drop_shadow_offset_x", Type::PhysicalLength),
("drop_shadow_offset_y", Type::Length), ("drop_shadow_offset_y", Type::PhysicalLength),
("drop_shadow_blur", Type::Length), ("drop_shadow_blur", Type::PhysicalLength),
("drop_shadow_color", Type::Color), ("drop_shadow_color", Type::Color),
]; ];
@ -115,7 +119,7 @@ impl TypeRegister {
register.insert_type(Type::Float32); register.insert_type(Type::Float32);
register.insert_type(Type::Int32); register.insert_type(Type::Int32);
register.insert_type(Type::String); register.insert_type(Type::String);
register.insert_type(Type::Length); register.insert_type(Type::PhysicalLength);
register.insert_type(Type::LogicalLength); register.insert_type(Type::LogicalLength);
register.insert_type(Type::Color); register.insert_type(Type::Color);
register.insert_type(Type::Duration); register.insert_type(Type::Duration);
@ -153,7 +157,7 @@ impl TypeRegister {
register.supported_property_animation_types.insert(Type::Float32.to_string()); register.supported_property_animation_types.insert(Type::Float32.to_string());
register.supported_property_animation_types.insert(Type::Int32.to_string()); register.supported_property_animation_types.insert(Type::Int32.to_string());
register.supported_property_animation_types.insert(Type::Color.to_string()); register.supported_property_animation_types.insert(Type::Color.to_string());
register.supported_property_animation_types.insert(Type::Length.to_string()); register.supported_property_animation_types.insert(Type::PhysicalLength.to_string());
register.supported_property_animation_types.insert(Type::LogicalLength.to_string()); register.supported_property_animation_types.insert(Type::LogicalLength.to_string());
register.supported_property_animation_types.insert(Type::Brush.to_string()); register.supported_property_animation_types.insert(Type::Brush.to_string());

View file

@ -51,7 +51,7 @@ impl From<LangType> for ValueType {
| LangType::Int32 | LangType::Int32
| LangType::Duration | LangType::Duration
| LangType::Angle | LangType::Angle
| LangType::Length | LangType::PhysicalLength
| LangType::LogicalLength | LangType::LogicalLength
| LangType::Percent | LangType::Percent
| LangType::UnitProduct(_) => Self::Number, | LangType::UnitProduct(_) => Self::Number,

View file

@ -173,11 +173,11 @@ impl RepeatedComponent for ErasedComponentBox {
let get_prop = |name: &str| { let get_prop = |name: &str| {
let PropertyLookupResult { resolved_name, property_type } = let PropertyLookupResult { resolved_name, property_type } =
root_item.borrow().lookup_property(name); root_item.borrow().lookup_property(name);
if property_type == Type::Length { if property_type == Type::PhysicalLength {
let nr = NamedReference::new(root_item, resolved_name.as_ref()); let nr = NamedReference::new(root_item, resolved_name.as_ref());
let p = get_property_ptr(&nr, s.borrow_instance()); let p = get_property_ptr(&nr, s.borrow_instance());
// Safety: assuming get_property_ptr returned a valid pointer, // Safety: assuming get_property_ptr returned a valid pointer,
// we know that `Type::Length` is a property of type `f32` // we know that `Type::PhysicalLength` is a property of type `f32`
Some(unsafe { &*(p as *const Property<f32>) }) Some(unsafe { &*(p as *const Property<f32>) })
} else { } else {
None None
@ -746,7 +746,7 @@ fn generate_component<'id>(
Type::Brush => animated_property_info::<Brush>(), Type::Brush => animated_property_info::<Brush>(),
Type::Duration => animated_property_info::<i64>(), Type::Duration => animated_property_info::<i64>(),
Type::Angle => animated_property_info::<f32>(), Type::Angle => animated_property_info::<f32>(),
Type::Length => animated_property_info::<f32>(), Type::PhysicalLength => animated_property_info::<f32>(),
Type::LogicalLength => animated_property_info::<f32>(), Type::LogicalLength => animated_property_info::<f32>(),
Type::Image => property_info::<ImageReference>(), Type::Image => property_info::<ImageReference>(),
Type::Bool => property_info::<bool>(), Type::Bool => property_info::<bool>(),

View file

@ -135,7 +135,9 @@ fn default_value_for_type(ty: &Type) -> Value {
Type::Float32 | Type::Int32 => Value::Number(0.), Type::Float32 | Type::Int32 => Value::Number(0.),
Type::String => Value::String(Default::default()), Type::String => Value::String(Default::default()),
Type::Color | Type::Brush => Value::Brush(Default::default()), Type::Color | Type::Brush => Value::Brush(Default::default()),
Type::Duration | Type::Angle | Type::Length | Type::LogicalLength => Value::Number(0.), Type::Duration | Type::Angle | Type::PhysicalLength | Type::LogicalLength => {
Value::Number(0.)
}
Type::Image => Value::Image(Default::default()), Type::Image => Value::Image(Default::default()),
Type::Bool => Value::Bool(false), Type::Bool => Value::Bool(false),
Type::Callback { .. } => Value::Void, Type::Callback { .. } => Value::Void,