Rename the "resource" type to "image"

This commit is contained in:
Olivier Goffart 2021-03-10 17:05:33 +01:00
parent 44e81a40d6
commit c840b046ae
14 changed files with 21 additions and 19 deletions

View file

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- `Rectangle::color` was deprecated and replaced by `Rectangle::background`, same for `Window::color`
- `Path::fill-color` was renamed to `fill`, and `Path::stroke-color` was renamed to `stroke`, which are now brushes instead of color
- Many other color property became brush in order to support gradients
- the `resource` type was renamed to `image`
### Added
- `@linear-gradient` can be used to have gradients on rectangle and paths

View file

@ -209,7 +209,7 @@ fn to_eval_value<'cx>(
Ok(Value::Model(sixtyfps_interpreter::ModelPtr(m)))
}
},
Type::Resource => {
Type::Image => {
Ok(Value::Resource(Resource::AbsoluteFilePath(val.to_string(cx)?.value().into())))
}
Type::Bool => Ok(Value::Bool(val.downcast_or_throw::<JsBoolean, _>(cx)?.value())),

View file

@ -198,6 +198,7 @@ All properties in elements have a type. The following types are supported:
| `angle` | Angle mesurement, corresponds to a literal like `90deg`, `1.2rad`, `0.25turn` |
| `easing` | Property animation allow specifying an easing curve. Valid values are `linear` (values are interpolated linearly) and the [four common cubiz-bezier functions known from CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function#Keywords_for_common_cubic-bezier_easing_functions): `ease`, `ease_in`, `ease_in_out`, `ease_out`. |
| `percent` | Signed, 32-bit floating point number that is interpreted as percentage. Literal number assigned to properties of this type must have a `%` suffix. |
| `image` | A reference to an image, can be initialized with the `@image-url("...")` construct |
Please see the language specific API references how these types are mapped to the APIs of the different programming languages.

View file

@ -9,7 +9,7 @@
LICENSE END */
struct TileData := {
image: resource,
image: image,
image_visible: bool,
solved: bool,
}
@ -19,7 +19,7 @@ MemoryTile := Rectangle {
callback clicked;
property <bool> open_curtain;
property <bool> solved;
property <resource> icon;
property <image> icon;
background: solved ? #34CE57 : #3960D5;
animate background { duration: 800ms; }

View file

@ -115,7 +115,7 @@ export Label := Text {
SquareButton := Rectangle {
callback clicked;
property<resource> img;
property<image> img;
border-radius: 3px;
border-width: 2px;
border-color: DemoPalette.control_outline_color;
@ -231,7 +231,7 @@ export CheckBox := Rectangle {
export PushButton := Rectangle {
callback clicked;
property <string> text <=> label.text;
property <resource> icon <=> img.source;
property <image> icon <=> img.source;
property <bool> primary: true;
property <bool> pressed: touch_area.pressed;

View file

@ -17,7 +17,7 @@ import { UsbPage } from "./usb_page.60";
ActionButton := Rectangle {
property <resource> icon <=> img.source;
property <image> icon <=> img.source;
property <string> text <=> label.text;
callback clicked;

View file

@ -37,7 +37,7 @@ BorderRectangle := Rectangle {
export { BorderRectangle as Rectangle }
Image := _ {
property <resource> source;
property <image> source;
property <length> x;
property <length> y;
property <length> width;

View file

@ -493,7 +493,7 @@ impl Expression {
_ => Type::Invalid,
},
Expression::SelfAssignment { .. } => Type::Void,
Expression::ResourceReference { .. } => Type::Resource,
Expression::ResourceReference { .. } => Type::Image,
Expression::Condition { condition: _, true_expr, false_expr } => {
let true_type = true_expr.ty();
let false_type = false_expr.ty();
@ -959,7 +959,7 @@ impl Expression {
Type::LogicalLength => Expression::NumberLiteral(0., Unit::Px),
Type::Percent => Expression::NumberLiteral(100., Unit::Percent),
// FIXME: Is that correct?
Type::Resource => {
Type::Image => {
Expression::ResourceReference(ResourceReference::AbsolutePath(String::new()))
}
Type::Bool => Expression::BoolLiteral(false),

View file

@ -252,7 +252,7 @@ impl CppType for Type {
}
}
Type::Array(i) => Some(format!("std::shared_ptr<sixtyfps::Model<{}>>", i.cpp_type()?)),
Type::Resource => Some("sixtyfps::Resource".to_owned()),
Type::Image => Some("sixtyfps::Resource".to_owned()),
Type::Builtin(elem) => elem.native_class.cpp_type.clone(),
Type::Enumeration(enumeration) => Some(format!("sixtyfps::{}", enumeration.name)),
Type::Brush => Some("sixtyfps::Brush".to_owned()),

View file

@ -39,7 +39,7 @@ fn rust_type(
Type::LogicalLength => Ok(quote!(f32)),
Type::Percent => Ok(quote!(f32)),
Type::Bool => Ok(quote!(bool)),
Type::Resource => Ok(quote!(sixtyfps::re_exports::Resource)),
Type::Image => Ok(quote!(sixtyfps::re_exports::Resource)),
Type::Object { fields, name: None } => {
let elem =
fields.values().map(|v| rust_type(v, span)).collect::<Result<Vec<_>, _>>()?;

View file

@ -47,7 +47,7 @@ pub enum Type {
LogicalLength,
Angle,
Percent,
Resource,
Image,
Bool,
Model,
PathElements,
@ -92,7 +92,7 @@ impl core::cmp::PartialEq for Type {
Type::Length => matches!(other, Type::Length),
Type::LogicalLength => matches!(other, Type::LogicalLength),
Type::Percent => matches!(other, Type::Percent),
Type::Resource => matches!(other, Type::Resource),
Type::Image => matches!(other, Type::Image),
Type::Bool => matches!(other, Type::Bool),
Type::Model => matches!(other, Type::Model),
Type::PathElements => matches!(other, Type::PathElements),
@ -153,7 +153,7 @@ impl Display for Type {
Type::LogicalLength => write!(f, "logical_length"),
Type::Percent => write!(f, "percent"),
Type::Color => write!(f, "color"),
Type::Resource => write!(f, "resource"),
Type::Image => write!(f, "image"),
Type::Bool => write!(f, "bool"),
Type::Model => write!(f, "model"),
Type::Array(t) => write!(f, "[{}]", t),
@ -209,7 +209,7 @@ impl Type {
| Self::Length
| Self::LogicalLength
| Self::Percent
| Self::Resource
| Self::Image
| Self::Bool
| Self::Model
| Self::Easing
@ -424,7 +424,7 @@ impl Type {
Type::Int32 => None,
Type::String => None,
Type::Color => None,
Type::Resource => None,
Type::Image => None,
Type::Bool => None,
Type::Model => None,
Type::PathElements => None,

View file

@ -116,7 +116,7 @@ impl TypeRegister {
register.insert_type(Type::LogicalLength);
register.insert_type(Type::Color);
register.insert_type(Type::Duration);
register.insert_type(Type::Resource);
register.insert_type(Type::Image);
register.insert_type(Type::Bool);
register.insert_type(Type::Model);
register.insert_type(Type::Percent);

View file

@ -785,7 +785,7 @@ fn generate_component<'id>(
Type::Angle => animated_property_info::<f32>(),
Type::Length => animated_property_info::<f32>(),
Type::LogicalLength => animated_property_info::<f32>(),
Type::Resource => property_info::<Resource>(),
Type::Image => property_info::<Resource>(),
Type::Bool => property_info::<bool>(),
Type::Callback { .. } => {
custom_callbacks.insert(name.clone(), builder.add_field_type::<Callback>());

View file

@ -11,5 +11,5 @@ LICENSE END */
// Test that @image-url("") compiles
TestCase := Rectangle {
property <resource> test: @image-url("");
property <image> test: @image-url("");
}