mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Remove Value::Color
This commit is contained in:
parent
34632206e6
commit
41f52f9ad4
2 changed files with 26 additions and 18 deletions
|
@ -185,12 +185,7 @@ fn to_eval_value<'cx>(
|
||||||
.value()
|
.value()
|
||||||
.parse::<css_color_parser2::Color>()
|
.parse::<css_color_parser2::Color>()
|
||||||
.or_else(|e| cx.throw_error(&e.to_string()))?;
|
.or_else(|e| cx.throw_error(&e.to_string()))?;
|
||||||
Ok(Value::Color(sixtyfps_corelib::Color::from_argb_u8(
|
Ok((sixtyfps_corelib::Color::from_argb_u8((c.a * 255.) as u8, c.r, c.g, c.b)).into())
|
||||||
(c.a * 255.) as u8,
|
|
||||||
c.r,
|
|
||||||
c.g,
|
|
||||||
c.b,
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
Type::Array(a) => match val.downcast::<JsArray>() {
|
Type::Array(a) => match val.downcast::<JsArray>() {
|
||||||
Ok(arr) => {
|
Ok(arr) => {
|
||||||
|
@ -281,7 +276,7 @@ fn to_js_value<'cx>(
|
||||||
}
|
}
|
||||||
js_object.as_value(cx)
|
js_object.as_value(cx)
|
||||||
}
|
}
|
||||||
Value::Color(c) | Value::Brush(sixtyfps_corelib::Brush::SolidColor(c)) => JsString::new(
|
Value::Brush(sixtyfps_corelib::Brush::SolidColor(c)) => JsString::new(
|
||||||
cx,
|
cx,
|
||||||
&format!("#{:02x}{:02x}{:02x}{:02x}", c.red(), c.green(), c.blue(), c.alpha()),
|
&format!("#{:02x}{:02x}{:02x}{:02x}", c.red(), c.green(), c.blue(), c.alpha()),
|
||||||
)
|
)
|
||||||
|
|
|
@ -123,9 +123,7 @@ pub enum Value {
|
||||||
Model(ModelPtr),
|
Model(ModelPtr),
|
||||||
/// An object
|
/// An object
|
||||||
Object(HashMap<String, Value>),
|
Object(HashMap<String, Value>),
|
||||||
/// A color
|
/// Corresespond to `brush` or `color` type in .60. For color, this is then a [`Brush::SolidColor`]
|
||||||
Color(Color),
|
|
||||||
/// A brush
|
|
||||||
Brush(Brush),
|
Brush(Brush),
|
||||||
/// The elements of a path
|
/// The elements of a path
|
||||||
PathElements(PathData),
|
PathElements(PathData),
|
||||||
|
@ -179,7 +177,6 @@ declare_value_conversion!(String => [SharedString] );
|
||||||
declare_value_conversion!(Bool => [bool] );
|
declare_value_conversion!(Bool => [bool] );
|
||||||
declare_value_conversion!(Image => [ImageReference] );
|
declare_value_conversion!(Image => [ImageReference] );
|
||||||
declare_value_conversion!(Object => [HashMap<String, Value>] );
|
declare_value_conversion!(Object => [HashMap<String, Value>] );
|
||||||
declare_value_conversion!(Color => [Color] );
|
|
||||||
declare_value_conversion!(Brush => [Brush] );
|
declare_value_conversion!(Brush => [Brush] );
|
||||||
declare_value_conversion!(PathElements => [PathData]);
|
declare_value_conversion!(PathElements => [PathData]);
|
||||||
declare_value_conversion!(EasingCurve => [corelib::animations::EasingCurve]);
|
declare_value_conversion!(EasingCurve => [corelib::animations::EasingCurve]);
|
||||||
|
@ -289,6 +286,23 @@ impl TryInto<()> for Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Color> for Value {
|
||||||
|
#[inline]
|
||||||
|
fn from(c: Color) -> Self {
|
||||||
|
Value::Brush(Brush::SolidColor(c))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryInto<Color> for Value {
|
||||||
|
type Error = Value;
|
||||||
|
#[inline]
|
||||||
|
fn try_into(self) -> Result<Color, Value> {
|
||||||
|
match self {
|
||||||
|
Value::Brush(Brush::SolidColor(c)) => Ok(c),
|
||||||
|
_ => Err(self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
enum ComponentInstance<'a, 'id> {
|
enum ComponentInstance<'a, 'id> {
|
||||||
InstanceRef(InstanceRef<'a, 'id>),
|
InstanceRef(InstanceRef<'a, 'id>),
|
||||||
|
@ -386,9 +400,8 @@ pub fn eval_expression(e: &Expression, local_context: &mut EvalLocalContext) ->
|
||||||
(Value::Number(n), Type::String) => {
|
(Value::Number(n), Type::String) => {
|
||||||
Value::String(SharedString::from(format!("{}", n).as_str()))
|
Value::String(SharedString::from(format!("{}", n).as_str()))
|
||||||
}
|
}
|
||||||
(Value::Number(n), Type::Color) => Value::Color(Color::from_argb_encoded(n as u32)),
|
(Value::Number(n), Type::Color) => Color::from_argb_encoded(n as u32).into(),
|
||||||
(Value::Color(col), Type::Brush) => Value::Brush(Brush::SolidColor(col)),
|
(Value::Brush(brush), Type::Color) => brush.color().into(),
|
||||||
(Value::Brush(brush), Type::Color) => Value::Color(brush.color()),
|
|
||||||
(v, _) => v,
|
(v, _) => v,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -556,9 +569,9 @@ pub fn eval_expression(e: &Expression, local_context: &mut EvalLocalContext) ->
|
||||||
if arguments.len() != 2 {
|
if arguments.len() != 2 {
|
||||||
panic!("internal error: incorrect argument count to ColorBrighter")
|
panic!("internal error: incorrect argument count to ColorBrighter")
|
||||||
}
|
}
|
||||||
if let Value::Color(col) = eval_expression(&arguments[0], local_context) {
|
if let Value::Brush(Brush::SolidColor(col)) = eval_expression(&arguments[0], local_context) {
|
||||||
if let Value::Number(factor) = eval_expression(&arguments[1], local_context) {
|
if let Value::Number(factor) = eval_expression(&arguments[1], local_context) {
|
||||||
Value::Color(col.brighter(factor as _))
|
col.brighter(factor as _).into()
|
||||||
} else {
|
} else {
|
||||||
panic!("Second argument not a number");
|
panic!("Second argument not a number");
|
||||||
}
|
}
|
||||||
|
@ -570,9 +583,9 @@ pub fn eval_expression(e: &Expression, local_context: &mut EvalLocalContext) ->
|
||||||
if arguments.len() != 2 {
|
if arguments.len() != 2 {
|
||||||
panic!("internal error: incorrect argument count to ColorDarker")
|
panic!("internal error: incorrect argument count to ColorDarker")
|
||||||
}
|
}
|
||||||
if let Value::Color(col) = eval_expression(&arguments[0], local_context) {
|
if let Value::Brush(Brush::SolidColor(col)) = eval_expression(&arguments[0], local_context) {
|
||||||
if let Value::Number(factor) = eval_expression(&arguments[1], local_context) {
|
if let Value::Number(factor) = eval_expression(&arguments[1], local_context) {
|
||||||
Value::Color(col.darker(factor as _))
|
col.darker(factor as _).into()
|
||||||
} else {
|
} else {
|
||||||
panic!("Second argument not a number");
|
panic!("Second argument not a number");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue