From 4c875d8e41b4080451418b8c2f967964ddf9f91a Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 4 Jun 2023 16:12:59 +1200 Subject: [PATCH] Integrate backgrounds parsing. --- lib/Graphics/Rendering/Rect/CSS.hs | 15 ++++++++++----- lib/Graphics/Rendering/Rect/CSS/Background.hs | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Graphics/Rendering/Rect/CSS.hs b/lib/Graphics/Rendering/Rect/CSS.hs index 61f5e4b..8fd8252 100644 --- a/lib/Graphics/Rendering/Rect/CSS.hs +++ b/lib/Graphics/Rendering/Rect/CSS.hs @@ -1,21 +1,26 @@ {-# LANGUAGE OverloadedStrings, RecordWildCards #-} -module Graphics.Rendering.Rect.CSS(CSSRect(..)) where +module Graphics.Rendering.Rect.CSS(RectStyle(..), colour) where import Stylist (PropertyParser(..)) import Graphics.Rendering.Rect.CSS.Colour (ColourPallet(foreground)) import Graphics.Rendering.Rect.CSS.Background (Backgrounds(..)) -data CSSRect = CSSRect { colours :: ColourPallet, backgrounds :: Backgrounds } +data RectStyle = RectStyle { colours :: ColourPallet, backgrounds :: Backgrounds } colour = foreground . colours -instance PropertyParser CSSRect where - temp = CSSRect { colours = temp, backgrounds = temp } - inherit CSSRect {..} = CSSRect { colours = inherit colours, backgrounds = temp } +instance PropertyParser RectStyle where + temp = RectStyle { colours = temp, backgrounds = temp } + inherit RectStyle {..} = RectStyle { + colours = inherit colours, backgrounds = temp + } shorthand self key value | Just _ <- longhand self self key value = [(key, value)] | otherwise = [] longhand parent self key value + | Just ret <- longhand (backgrounds parent) { pallet = colours parent } + (backgrounds self) { pallet = colours self } key value = + Just self { backgrounds = ret } | Just ret <- longhand (colours parent) (colours self) key value = Just self { colours = ret } | otherwise = Nothing diff --git a/lib/Graphics/Rendering/Rect/CSS/Background.hs b/lib/Graphics/Rendering/Rect/CSS/Background.hs index 34c5f06..cb65914 100644 --- a/lib/Graphics/Rendering/Rect/CSS/Background.hs +++ b/lib/Graphics/Rendering/Rect/CSS/Background.hs @@ -7,16 +7,16 @@ import Data.Colour (AlphaColour, transparent) data Backgrounds = Backgrounds { pallet :: ColourPallet, - colour :: AlphaColour Double + background :: AlphaColour Double } instance PropertyParser Backgrounds where - temp = Backgrounds { pallet = temp, colour = transparent } + temp = Backgrounds { pallet = temp, background = transparent } inherit _ = temp priority _ = [] longhand _ self@Backgrounds{ pallet = c } "background-color" toks - | Just ([], val) <- parseColour c toks = Just self { colour = val } + | Just ([], val) <- parseColour c toks = Just self { background = val } longhand _ _ _ _ = Nothing shorthand self "background" toks = parseUnorderedShorthand self [ -- 2.30.2