{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Strict #-}
module Monomer.Widgets.Util.Theme where
import Control.Lens (Lens', (&), (^.), (^?), (.~), (?~), (<>~), at, non)
import Data.Default
import Data.Maybe
import Monomer.Core.StyleTypes
import Monomer.Core.ThemeTypes
import Monomer.Core.WidgetTypes
import qualified Monomer.Core.Lens as L
collectThemeField_
:: WidgetEnv s e
-> Lens' StyleState (Maybe t)
-> Lens' ThemeState (Maybe t)
-> Style
-> Style
collectThemeField_ :: forall s e t.
WidgetEnv s e
-> Lens' StyleState (Maybe t)
-> Lens' ThemeState (Maybe t)
-> Style
-> Style
collectThemeField_ WidgetEnv s e
wenv Lens' StyleState (Maybe t)
fieldStyle Lens' ThemeState (Maybe t)
fieldTheme Style
target = Style
style where
basic :: Maybe StyleState
basic = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Style
target forall s a. s -> Getting a s a -> a
^. forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> Iso' (Maybe a) a
non forall a. Default a => a
def
forall a b. a -> (a -> b) -> b
& Lens' StyleState (Maybe t)
fieldStyle forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState (Maybe t)
fieldTheme
hover :: Maybe StyleState
hover = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Style
target forall s a. s -> Getting a s a -> a
^. forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> Iso' (Maybe a) a
non forall a. Default a => a
def
forall a b. a -> (a -> b) -> b
& Lens' StyleState (Maybe t)
fieldStyle forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState (Maybe t)
fieldTheme
focus :: Maybe StyleState
focus = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Style
target forall s a. s -> Getting a s a -> a
^. forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> Iso' (Maybe a) a
non forall a. Default a => a
def
forall a b. a -> (a -> b) -> b
& Lens' StyleState (Maybe t)
fieldStyle forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState (Maybe t)
fieldTheme
focusHover :: Maybe StyleState
focusHover = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Style
target forall s a. s -> Getting a s a -> a
^. forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> Iso' (Maybe a) a
non forall a. Default a => a
def
forall a b. a -> (a -> b) -> b
& Lens' StyleState (Maybe t)
fieldStyle forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState (Maybe t)
fieldTheme
active :: Maybe StyleState
active = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Style
target forall s a. s -> Getting a s a -> a
^. forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> Iso' (Maybe a) a
non forall a. Default a => a
def
forall a b. a -> (a -> b) -> b
& Lens' StyleState (Maybe t)
fieldStyle forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState (Maybe t)
fieldTheme
disabled :: Maybe StyleState
disabled = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Style
target forall s a. s -> Getting a s a -> a
^. forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> Iso' (Maybe a) a
non forall a. Default a => a
def
forall a b. a -> (a -> b) -> b
& Lens' StyleState (Maybe t)
fieldStyle forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState (Maybe t)
fieldTheme
style :: Style
style = Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Style
Style Maybe StyleState
basic Maybe StyleState
hover Maybe StyleState
focus Maybe StyleState
focusHover Maybe StyleState
active Maybe StyleState
disabled
collectTheme
:: WidgetEnv s e
-> Lens' ThemeState StyleState
-> Style
collectTheme :: forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s e
wenv Lens' ThemeState StyleState
fieldT = Style
style where
basic :: Maybe StyleState
basic = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
fieldT
hover :: Maybe StyleState
hover = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
fieldT
focus :: Maybe StyleState
focus = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
fieldT
focusHover :: Maybe StyleState
focusHover = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
fieldT
active :: Maybe StyleState
active = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
fieldT
disabled :: Maybe StyleState
disabled = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
fieldT
style :: Style
style = Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Style
Style Maybe StyleState
basic Maybe StyleState
hover Maybe StyleState
focus Maybe StyleState
focusHover Maybe StyleState
active Maybe StyleState
disabled
collectUserTheme
:: WidgetEnv s e
-> String
-> Style
collectUserTheme :: forall s e. WidgetEnv s e -> String -> Style
collectUserTheme WidgetEnv s e
wenv String
name = Style
style where
basic :: Maybe (IxValue (Map String StyleState))
basic = WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
name
hover :: Maybe (IxValue (Map String StyleState))
hover = WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
name
focus :: Maybe (IxValue (Map String StyleState))
focus = WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
name
focusHover :: Maybe (IxValue (Map String StyleState))
focusHover = WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
name
active :: Maybe (IxValue (Map String StyleState))
active = WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
name
disabled :: Maybe (IxValue (Map String StyleState))
disabled = WidgetEnv s e
wenv forall s a. s -> Getting a s a -> a
^. forall s a. HasTheme s a => Lens' s a
L.theme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
name
style :: Style
style = Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Maybe StyleState
-> Style
Style Maybe StyleState
basic Maybe StyleState
hover Maybe StyleState
focus Maybe StyleState
focusHover Maybe StyleState
active Maybe StyleState
disabled
setThemeValue
:: Lens' ThemeState a
-> a
-> Theme
-> Theme
setThemeValue :: forall a. Lens' ThemeState a -> a -> Theme -> Theme
setThemeValue Lens' ThemeState a
field a
value Theme
theme = Theme
newTheme where
newTheme :: Theme
newTheme = Theme
theme
forall a b. a -> (a -> b) -> b
& forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState a
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
value
forall a b. a -> (a -> b) -> b
& forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState a
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
value
forall a b. a -> (a -> b) -> b
& forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState a
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
value
forall a b. a -> (a -> b) -> b
& forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState a
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
value
forall a b. a -> (a -> b) -> b
& forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState a
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
value
forall a b. a -> (a -> b) -> b
& forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState a
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
value
setThemeStyle
:: Lens' ThemeState StyleState
-> [StyleState]
-> Theme
-> Theme
setThemeStyle :: Lens' ThemeState StyleState -> [StyleState] -> Theme -> Theme
setThemeStyle Lens' ThemeState StyleState
field [StyleState]
styles Theme
theme = Theme
newTheme where
!value :: StyleState
value = forall a. Monoid a => [a] -> a
mconcat [StyleState]
styles
newTheme :: Theme
newTheme = Theme
theme
forall a b. a -> (a -> b) -> b
& forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall s t a b. ASetter s t a b -> b -> s -> t
.~ StyleState
value
mergeThemeStyle
:: Lens' ThemeState StyleState
-> [StyleState]
-> Theme
-> Theme
mergeThemeStyle :: Lens' ThemeState StyleState -> [StyleState] -> Theme -> Theme
mergeThemeStyle Lens' ThemeState StyleState
field [StyleState]
styles Theme
theme = Theme
newTheme where
!value :: StyleState
value = forall a. Monoid a => [a] -> a
mconcat [StyleState]
styles
newTheme :: Theme
newTheme = Theme
theme
forall a b. a -> (a -> b) -> b
& forall s a. HasBasic s a => Lens' s a
L.basic forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasHover s a => Lens' s a
L.hover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasFocus s a => Lens' s a
L.focus forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasFocusHover s a => Lens' s a
L.focusHover forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasActive s a => Lens' s a
L.active forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ StyleState
value
forall a b. a -> (a -> b) -> b
& forall s a. HasDisabled s a => Lens' s a
L.disabled forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ThemeState StyleState
field forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ StyleState
value