~alcinnz/Mondrian

4c875d8e41b4080451418b8c2f967964ddf9f91a — Adrian Cochrane 1 year, 4 months ago 77f2d28
Integrate backgrounds parsing.
2 files changed, 13 insertions(+), 8 deletions(-)

M lib/Graphics/Rendering/Rect/CSS.hs
M lib/Graphics/Rendering/Rect/CSS/Background.hs
M lib/Graphics/Rendering/Rect/CSS.hs => lib/Graphics/Rendering/Rect/CSS.hs +10 -5
@@ 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

M lib/Graphics/Rendering/Rect/CSS/Background.hs => lib/Graphics/Rendering/Rect/CSS/Background.hs +3 -3
@@ 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 [