From 750d220bb080be077cd7ede6d18d485b1c3fb0c9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 27 Dec 2020 19:23:26 +0100 Subject: =?UTF-8?q?Add=20color=20enum=20=F0=9F=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/mod.rs | 3 ++- src/eval/value.rs | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/eval') diff --git a/src/eval/mod.rs b/src/eval/mod.rs index c2b80b68..ed73b07c 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -20,6 +20,7 @@ use fontdock::FontStyle; use crate::diag::Diag; use crate::diag::{Deco, Feedback, Pass}; +use crate::color::Color; use crate::env::SharedEnv; use crate::geom::{BoxAlign, Dir, Flow, Gen, Length, Linear, Relative, Sides, Size}; use crate::layout::{ @@ -436,7 +437,7 @@ impl Eval for Lit { Lit::Float(v) => Value::Float(v), Lit::Length(v, unit) => Value::Length(Length::with_unit(v, unit)), Lit::Percent(v) => Value::Relative(Relative::new(v / 100.0)), - Lit::Color(v) => Value::Color(v), + Lit::Color(v) => Value::Color(Color::Rgba(v)), Lit::Str(ref v) => Value::Str(v.clone()), Lit::Dict(ref v) => Value::Dict(v.eval(ctx)), Lit::Content(ref v) => Value::Content(v.clone()), diff --git a/src/eval/value.rs b/src/eval/value.rs index 8c98257e..a27e9aa9 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use fontdock::{FontStretch, FontStyle, FontWeight}; use super::{Args, Dict, Eval, EvalContext, SpannedEntry}; -use crate::color::RgbaColor; +use crate::color::Color; use crate::diag::Diag; use crate::geom::{Dir, Length, Linear, Relative}; use crate::paper::Paper; @@ -32,8 +32,8 @@ pub enum Value { Relative(Relative), /// A combination of an absolute length and a relative value: `20% + 5cm`. Linear(Linear), - /// A color value with alpha channel: `#f79143ff`. - Color(RgbaColor), + /// A color value: `#f79143ff`. + Color(Color), /// A string: `"string"`. Str(String), /// A dictionary value: `(false, 12cm, greeting="hi")`. @@ -285,6 +285,7 @@ try_from_match!(Linear["linear"]: Value::Length(v) => v.into(), Value::Relative(v) => v.into(), ); +try_from_match!(Color["color"]: Value::Color(v) => v); try_from_match!(String["string"]: Value::Str(v) => v); try_from_match!(SynTree["tree"]: Value::Content(v) => v); try_from_match!(ValueDict["dictionary"]: Value::Dict(v) => v); -- cgit v1.2.3