mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11: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()
|
||||
.parse::<css_color_parser2::Color>()
|
||||
.or_else(|e| cx.throw_error(&e.to_string()))?;
|
||||
Ok(Value::Color(sixtyfps_corelib::Color::from_argb_u8(
|
||||
(c.a * 255.) as u8,
|
||||
c.r,
|
||||
c.g,
|
||||
c.b,
|
||||
)))
|
||||
Ok((sixtyfps_corelib::Color::from_argb_u8((c.a * 255.) as u8, c.r, c.g, c.b)).into())
|
||||
}
|
||||
Type::Array(a) => match val.downcast::<JsArray>() {
|
||||
Ok(arr) => {
|
||||
|
@ -281,7 +276,7 @@ fn to_js_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,
|
||||
&format!("#{:02x}{:02x}{:02x}{:02x}", c.red(), c.green(), c.blue(), c.alpha()),
|
||||
)
|
||||
|
|
|
@ -123,9 +123,7 @@ pub enum Value {
|
|||
Model(ModelPtr),
|
||||
/// An object
|
||||
Object(HashMap<String, Value>),
|
||||
/// A color
|
||||
Color(Color),
|
||||
/// A brush
|
||||
/// Corresespond to `brush` or `color` type in .60. For color, this is then a [`Brush::SolidColor`]
|
||||
Brush(Brush),
|
||||
/// The elements of a path
|
||||
PathElements(PathData),
|
||||
|
@ -179,7 +177,6 @@ declare_value_conversion!(String => [SharedString] );
|
|||
declare_value_conversion!(Bool => [bool] );
|
||||
declare_value_conversion!(Image => [ImageReference] );
|
||||
declare_value_conversion!(Object => [HashMap<String, Value>] );
|
||||
declare_value_conversion!(Color => [Color] );
|
||||
declare_value_conversion!(Brush => [Brush] );
|
||||
declare_value_conversion!(PathElements => [PathData]);
|
||||
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)]
|
||||
enum ComponentInstance<'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::String(SharedString::from(format!("{}", n).as_str()))
|
||||
}
|
||||
(Value::Number(n), Type::Color) => Value::Color(Color::from_argb_encoded(n as u32)),
|
||||
(Value::Color(col), Type::Brush) => Value::Brush(Brush::SolidColor(col)),
|
||||
(Value::Brush(brush), Type::Color) => Value::Color(brush.color()),
|
||||
(Value::Number(n), Type::Color) => Color::from_argb_encoded(n as u32).into(),
|
||||
(Value::Brush(brush), Type::Color) => brush.color().into(),
|
||||
(v, _) => v,
|
||||
}
|
||||
}
|
||||
|
@ -556,9 +569,9 @@ pub fn eval_expression(e: &Expression, local_context: &mut EvalLocalContext) ->
|
|||
if arguments.len() != 2 {
|
||||
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) {
|
||||
Value::Color(col.brighter(factor as _))
|
||||
col.brighter(factor as _).into()
|
||||
} else {
|
||||
panic!("Second argument not a number");
|
||||
}
|
||||
|
@ -570,9 +583,9 @@ pub fn eval_expression(e: &Expression, local_context: &mut EvalLocalContext) ->
|
|||
if arguments.len() != 2 {
|
||||
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) {
|
||||
Value::Color(col.darker(factor as _))
|
||||
col.darker(factor as _).into()
|
||||
} else {
|
||||
panic!("Second argument not a number");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue