{-|
Module      : Monomer.Widgets.Util.Theme
Copyright   : (c) 2018 Francisco Vallarino
License     : BSD-3-Clause (see the LICENSE file)
Maintainer  : fjvallarino@gmail.com
Stability   : experimental
Portability : non-portable

Helper functions for loading theme values.
-}
{-# LANGUAGE RankNTypes #-}

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

-- | Updates a the field of style with the field value from the active theme.
collectThemeField_
  :: WidgetEnv s e               -- ^ The widget environment (to get the theme).
  -> Lens' StyleState (Maybe t)  -- ^ The target field of the style.
  -> Lens' ThemeState (Maybe t)  -- ^ The source field of the theme.
  -> Style                       -- ^ The target style.
  -> Style                       -- ^ The updated style.
collectThemeField_ :: 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 = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ Style
target Style -> Getting StyleState Style StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Style -> Const StyleState Style
forall s a. HasBasic s a => Lens' s a
L.basic ((Maybe StyleState -> Const StyleState (Maybe StyleState))
 -> Style -> Const StyleState Style)
-> ((StyleState -> Const StyleState StyleState)
    -> Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Getting StyleState Style StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleState -> Iso' (Maybe StyleState) StyleState
forall a. Eq a => a -> Iso' (Maybe a) a
non StyleState
forall a. Default a => a
def
    StyleState -> (StyleState -> StyleState) -> StyleState
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t))
-> StyleState -> Identity StyleState
Lens' StyleState (Maybe t)
fieldStyle ((Maybe t -> Identity (Maybe t))
 -> StyleState -> Identity StyleState)
-> Maybe t -> StyleState -> StyleState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t) -> Maybe t
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe t) Theme)
-> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe t) Theme)
 -> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e))
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> Theme -> Const (Maybe t) Theme)
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe t) ThemeState)
-> Theme -> Const (Maybe t) Theme
forall s a. HasBasic s a => Lens' s a
L.basic ((ThemeState -> Const (Maybe t) ThemeState)
 -> Theme -> Const (Maybe t) Theme)
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> ThemeState -> Const (Maybe t) ThemeState)
-> (Maybe t -> Const (Maybe t) (Maybe t))
-> Theme
-> Const (Maybe t) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe t -> Const (Maybe t) (Maybe t))
-> ThemeState -> Const (Maybe t) ThemeState
Lens' ThemeState (Maybe t)
fieldTheme
  hover :: Maybe StyleState
hover = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ Style
target Style -> Getting StyleState Style StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Style -> Const StyleState Style
forall s a. HasHover s a => Lens' s a
L.hover ((Maybe StyleState -> Const StyleState (Maybe StyleState))
 -> Style -> Const StyleState Style)
-> ((StyleState -> Const StyleState StyleState)
    -> Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Getting StyleState Style StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleState -> Iso' (Maybe StyleState) StyleState
forall a. Eq a => a -> Iso' (Maybe a) a
non StyleState
forall a. Default a => a
def
    StyleState -> (StyleState -> StyleState) -> StyleState
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t))
-> StyleState -> Identity StyleState
Lens' StyleState (Maybe t)
fieldStyle ((Maybe t -> Identity (Maybe t))
 -> StyleState -> Identity StyleState)
-> Maybe t -> StyleState -> StyleState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t) -> Maybe t
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe t) Theme)
-> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe t) Theme)
 -> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e))
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> Theme -> Const (Maybe t) Theme)
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe t) ThemeState)
-> Theme -> Const (Maybe t) Theme
forall s a. HasHover s a => Lens' s a
L.hover ((ThemeState -> Const (Maybe t) ThemeState)
 -> Theme -> Const (Maybe t) Theme)
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> ThemeState -> Const (Maybe t) ThemeState)
-> (Maybe t -> Const (Maybe t) (Maybe t))
-> Theme
-> Const (Maybe t) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe t -> Const (Maybe t) (Maybe t))
-> ThemeState -> Const (Maybe t) ThemeState
Lens' ThemeState (Maybe t)
fieldTheme
  focus :: Maybe StyleState
focus = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ Style
target Style -> Getting StyleState Style StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Style -> Const StyleState Style
forall s a. HasFocus s a => Lens' s a
L.focus ((Maybe StyleState -> Const StyleState (Maybe StyleState))
 -> Style -> Const StyleState Style)
-> ((StyleState -> Const StyleState StyleState)
    -> Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Getting StyleState Style StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleState -> Iso' (Maybe StyleState) StyleState
forall a. Eq a => a -> Iso' (Maybe a) a
non StyleState
forall a. Default a => a
def
    StyleState -> (StyleState -> StyleState) -> StyleState
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t))
-> StyleState -> Identity StyleState
Lens' StyleState (Maybe t)
fieldStyle ((Maybe t -> Identity (Maybe t))
 -> StyleState -> Identity StyleState)
-> Maybe t -> StyleState -> StyleState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t) -> Maybe t
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe t) Theme)
-> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe t) Theme)
 -> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e))
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> Theme -> Const (Maybe t) Theme)
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe t) ThemeState)
-> Theme -> Const (Maybe t) Theme
forall s a. HasFocus s a => Lens' s a
L.focus ((ThemeState -> Const (Maybe t) ThemeState)
 -> Theme -> Const (Maybe t) Theme)
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> ThemeState -> Const (Maybe t) ThemeState)
-> (Maybe t -> Const (Maybe t) (Maybe t))
-> Theme
-> Const (Maybe t) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe t -> Const (Maybe t) (Maybe t))
-> ThemeState -> Const (Maybe t) ThemeState
Lens' ThemeState (Maybe t)
fieldTheme
  focusHover :: Maybe StyleState
focusHover = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ Style
target Style -> Getting StyleState Style StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Style -> Const StyleState Style
forall s a. HasFocusHover s a => Lens' s a
L.focusHover ((Maybe StyleState -> Const StyleState (Maybe StyleState))
 -> Style -> Const StyleState Style)
-> ((StyleState -> Const StyleState StyleState)
    -> Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Getting StyleState Style StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleState -> Iso' (Maybe StyleState) StyleState
forall a. Eq a => a -> Iso' (Maybe a) a
non StyleState
forall a. Default a => a
def
    StyleState -> (StyleState -> StyleState) -> StyleState
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t))
-> StyleState -> Identity StyleState
Lens' StyleState (Maybe t)
fieldStyle ((Maybe t -> Identity (Maybe t))
 -> StyleState -> Identity StyleState)
-> Maybe t -> StyleState -> StyleState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t) -> Maybe t
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe t) Theme)
-> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe t) Theme)
 -> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e))
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> Theme -> Const (Maybe t) Theme)
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe t) ThemeState)
-> Theme -> Const (Maybe t) Theme
forall s a. HasFocusHover s a => Lens' s a
L.focusHover ((ThemeState -> Const (Maybe t) ThemeState)
 -> Theme -> Const (Maybe t) Theme)
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> ThemeState -> Const (Maybe t) ThemeState)
-> (Maybe t -> Const (Maybe t) (Maybe t))
-> Theme
-> Const (Maybe t) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe t -> Const (Maybe t) (Maybe t))
-> ThemeState -> Const (Maybe t) ThemeState
Lens' ThemeState (Maybe t)
fieldTheme
  active :: Maybe StyleState
active = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ Style
target Style -> Getting StyleState Style StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Style -> Const StyleState Style
forall s a. HasActive s a => Lens' s a
L.active ((Maybe StyleState -> Const StyleState (Maybe StyleState))
 -> Style -> Const StyleState Style)
-> ((StyleState -> Const StyleState StyleState)
    -> Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Getting StyleState Style StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleState -> Iso' (Maybe StyleState) StyleState
forall a. Eq a => a -> Iso' (Maybe a) a
non StyleState
forall a. Default a => a
def
    StyleState -> (StyleState -> StyleState) -> StyleState
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t))
-> StyleState -> Identity StyleState
Lens' StyleState (Maybe t)
fieldStyle ((Maybe t -> Identity (Maybe t))
 -> StyleState -> Identity StyleState)
-> Maybe t -> StyleState -> StyleState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t) -> Maybe t
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe t) Theme)
-> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe t) Theme)
 -> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e))
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> Theme -> Const (Maybe t) Theme)
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe t) ThemeState)
-> Theme -> Const (Maybe t) Theme
forall s a. HasActive s a => Lens' s a
L.active ((ThemeState -> Const (Maybe t) ThemeState)
 -> Theme -> Const (Maybe t) Theme)
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> ThemeState -> Const (Maybe t) ThemeState)
-> (Maybe t -> Const (Maybe t) (Maybe t))
-> Theme
-> Const (Maybe t) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe t -> Const (Maybe t) (Maybe t))
-> ThemeState -> Const (Maybe t) ThemeState
Lens' ThemeState (Maybe t)
fieldTheme
  disabled :: Maybe StyleState
disabled = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ Style
target Style -> Getting StyleState Style StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Style -> Const StyleState Style
forall s a. HasDisabled s a => Lens' s a
L.disabled ((Maybe StyleState -> Const StyleState (Maybe StyleState))
 -> Style -> Const StyleState Style)
-> ((StyleState -> Const StyleState StyleState)
    -> Maybe StyleState -> Const StyleState (Maybe StyleState))
-> Getting StyleState Style StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleState -> Iso' (Maybe StyleState) StyleState
forall a. Eq a => a -> Iso' (Maybe a) a
non StyleState
forall a. Default a => a
def
    StyleState -> (StyleState -> StyleState) -> StyleState
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t))
-> StyleState -> Identity StyleState
Lens' StyleState (Maybe t)
fieldStyle ((Maybe t -> Identity (Maybe t))
 -> StyleState -> Identity StyleState)
-> Maybe t -> StyleState -> StyleState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t) -> Maybe t
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe t) Theme)
-> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe t) Theme)
 -> WidgetEnv s e -> Const (Maybe t) (WidgetEnv s e))
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> Theme -> Const (Maybe t) Theme)
-> Getting (Maybe t) (WidgetEnv s e) (Maybe t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe t) ThemeState)
-> Theme -> Const (Maybe t) Theme
forall s a. HasDisabled s a => Lens' s a
L.disabled ((ThemeState -> Const (Maybe t) ThemeState)
 -> Theme -> Const (Maybe t) Theme)
-> ((Maybe t -> Const (Maybe t) (Maybe t))
    -> ThemeState -> Const (Maybe t) ThemeState)
-> (Maybe t -> Const (Maybe t) (Maybe t))
-> Theme
-> Const (Maybe t) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe t -> Const (Maybe t) (Maybe t))
-> ThemeState -> Const (Maybe t) ThemeState
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

-- | Collects all the style states from a given field in the active theme.
collectTheme
  :: WidgetEnv s e               -- ^ The widget environment (to get the theme).
  -> Lens' ThemeState StyleState -- ^ The field into the theme
  -> Style                       -- ^ The collected style.
collectTheme :: WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s e
wenv Lens' ThemeState StyleState
fieldT = Style
style where
  basic :: Maybe StyleState
basic = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv WidgetEnv s e
-> Getting StyleState (WidgetEnv s e) StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const StyleState Theme)
-> WidgetEnv s e -> Const StyleState (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const StyleState Theme)
 -> WidgetEnv s e -> Const StyleState (WidgetEnv s e))
-> ((StyleState -> Const StyleState StyleState)
    -> Theme -> Const StyleState Theme)
-> Getting StyleState (WidgetEnv s e) StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const StyleState ThemeState)
-> Theme -> Const StyleState Theme
forall s a. HasBasic s a => Lens' s a
L.basic ((ThemeState -> Const StyleState ThemeState)
 -> Theme -> Const StyleState Theme)
-> ((StyleState -> Const StyleState StyleState)
    -> ThemeState -> Const StyleState ThemeState)
-> (StyleState -> Const StyleState StyleState)
-> Theme
-> Const StyleState Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StyleState -> Const StyleState StyleState)
-> ThemeState -> Const StyleState ThemeState
Lens' ThemeState StyleState
fieldT
  hover :: Maybe StyleState
hover = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv WidgetEnv s e
-> Getting StyleState (WidgetEnv s e) StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const StyleState Theme)
-> WidgetEnv s e -> Const StyleState (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const StyleState Theme)
 -> WidgetEnv s e -> Const StyleState (WidgetEnv s e))
-> ((StyleState -> Const StyleState StyleState)
    -> Theme -> Const StyleState Theme)
-> Getting StyleState (WidgetEnv s e) StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const StyleState ThemeState)
-> Theme -> Const StyleState Theme
forall s a. HasHover s a => Lens' s a
L.hover ((ThemeState -> Const StyleState ThemeState)
 -> Theme -> Const StyleState Theme)
-> ((StyleState -> Const StyleState StyleState)
    -> ThemeState -> Const StyleState ThemeState)
-> (StyleState -> Const StyleState StyleState)
-> Theme
-> Const StyleState Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StyleState -> Const StyleState StyleState)
-> ThemeState -> Const StyleState ThemeState
Lens' ThemeState StyleState
fieldT
  focus :: Maybe StyleState
focus = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv WidgetEnv s e
-> Getting StyleState (WidgetEnv s e) StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const StyleState Theme)
-> WidgetEnv s e -> Const StyleState (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const StyleState Theme)
 -> WidgetEnv s e -> Const StyleState (WidgetEnv s e))
-> ((StyleState -> Const StyleState StyleState)
    -> Theme -> Const StyleState Theme)
-> Getting StyleState (WidgetEnv s e) StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const StyleState ThemeState)
-> Theme -> Const StyleState Theme
forall s a. HasFocus s a => Lens' s a
L.focus ((ThemeState -> Const StyleState ThemeState)
 -> Theme -> Const StyleState Theme)
-> ((StyleState -> Const StyleState StyleState)
    -> ThemeState -> Const StyleState ThemeState)
-> (StyleState -> Const StyleState StyleState)
-> Theme
-> Const StyleState Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StyleState -> Const StyleState StyleState)
-> ThemeState -> Const StyleState ThemeState
Lens' ThemeState StyleState
fieldT
  focusHover :: Maybe StyleState
focusHover = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv WidgetEnv s e
-> Getting StyleState (WidgetEnv s e) StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const StyleState Theme)
-> WidgetEnv s e -> Const StyleState (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const StyleState Theme)
 -> WidgetEnv s e -> Const StyleState (WidgetEnv s e))
-> ((StyleState -> Const StyleState StyleState)
    -> Theme -> Const StyleState Theme)
-> Getting StyleState (WidgetEnv s e) StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const StyleState ThemeState)
-> Theme -> Const StyleState Theme
forall s a. HasFocusHover s a => Lens' s a
L.focusHover ((ThemeState -> Const StyleState ThemeState)
 -> Theme -> Const StyleState Theme)
-> ((StyleState -> Const StyleState StyleState)
    -> ThemeState -> Const StyleState ThemeState)
-> (StyleState -> Const StyleState StyleState)
-> Theme
-> Const StyleState Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StyleState -> Const StyleState StyleState)
-> ThemeState -> Const StyleState ThemeState
Lens' ThemeState StyleState
fieldT
  active :: Maybe StyleState
active = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv WidgetEnv s e
-> Getting StyleState (WidgetEnv s e) StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const StyleState Theme)
-> WidgetEnv s e -> Const StyleState (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const StyleState Theme)
 -> WidgetEnv s e -> Const StyleState (WidgetEnv s e))
-> ((StyleState -> Const StyleState StyleState)
    -> Theme -> Const StyleState Theme)
-> Getting StyleState (WidgetEnv s e) StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const StyleState ThemeState)
-> Theme -> Const StyleState Theme
forall s a. HasActive s a => Lens' s a
L.active ((ThemeState -> Const StyleState ThemeState)
 -> Theme -> Const StyleState Theme)
-> ((StyleState -> Const StyleState StyleState)
    -> ThemeState -> Const StyleState ThemeState)
-> (StyleState -> Const StyleState StyleState)
-> Theme
-> Const StyleState Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StyleState -> Const StyleState StyleState)
-> ThemeState -> Const StyleState ThemeState
Lens' ThemeState StyleState
fieldT
  disabled :: Maybe StyleState
disabled = StyleState -> Maybe StyleState
forall a. a -> Maybe a
Just (StyleState -> Maybe StyleState) -> StyleState -> Maybe StyleState
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
wenv WidgetEnv s e
-> Getting StyleState (WidgetEnv s e) StyleState -> StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const StyleState Theme)
-> WidgetEnv s e -> Const StyleState (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const StyleState Theme)
 -> WidgetEnv s e -> Const StyleState (WidgetEnv s e))
-> ((StyleState -> Const StyleState StyleState)
    -> Theme -> Const StyleState Theme)
-> Getting StyleState (WidgetEnv s e) StyleState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const StyleState ThemeState)
-> Theme -> Const StyleState Theme
forall s a. HasDisabled s a => Lens' s a
L.disabled ((ThemeState -> Const StyleState ThemeState)
 -> Theme -> Const StyleState Theme)
-> ((StyleState -> Const StyleState StyleState)
    -> ThemeState -> Const StyleState ThemeState)
-> (StyleState -> Const StyleState StyleState)
-> Theme
-> Const StyleState Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StyleState -> Const StyleState StyleState)
-> ThemeState -> Const StyleState ThemeState
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

-- | Collects all the style states from a given entry in the map of user styles
--   in the active theme.
collectUserTheme
  :: WidgetEnv s e  -- ^ The widget environment (to get the theme).
  -> String         -- ^ The key into the user map.
  -> Style          -- ^ The collected style.
collectUserTheme :: WidgetEnv s e -> String -> Style
collectUserTheme WidgetEnv s e
wenv String
name = Style
style where
  basic :: Maybe StyleState
basic = WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
-> Maybe StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe StyleState) Theme)
-> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe StyleState) Theme)
 -> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e))
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Theme -> Const (Maybe StyleState) Theme)
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe StyleState) ThemeState)
-> Theme -> Const (Maybe StyleState) Theme
forall s a. HasBasic s a => Lens' s a
L.basic ((ThemeState -> Const (Maybe StyleState) ThemeState)
 -> Theme -> Const (Maybe StyleState) Theme)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> Theme
-> Const (Maybe StyleState) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map String StyleState
 -> Const (Maybe StyleState) (Map String StyleState))
-> ThemeState -> Const (Maybe StyleState) ThemeState
forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap ((Map String StyleState
  -> Const (Maybe StyleState) (Map String StyleState))
 -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Map String StyleState
    -> Const (Maybe StyleState) (Map String StyleState))
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> ThemeState
-> Const (Maybe StyleState) ThemeState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map String StyleState)
-> Lens'
     (Map String StyleState) (Maybe (IxValue (Map String StyleState)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
Index (Map String StyleState)
name
  hover :: Maybe StyleState
hover = WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
-> Maybe StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe StyleState) Theme)
-> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe StyleState) Theme)
 -> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e))
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Theme -> Const (Maybe StyleState) Theme)
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe StyleState) ThemeState)
-> Theme -> Const (Maybe StyleState) Theme
forall s a. HasHover s a => Lens' s a
L.hover ((ThemeState -> Const (Maybe StyleState) ThemeState)
 -> Theme -> Const (Maybe StyleState) Theme)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> Theme
-> Const (Maybe StyleState) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map String StyleState
 -> Const (Maybe StyleState) (Map String StyleState))
-> ThemeState -> Const (Maybe StyleState) ThemeState
forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap ((Map String StyleState
  -> Const (Maybe StyleState) (Map String StyleState))
 -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Map String StyleState
    -> Const (Maybe StyleState) (Map String StyleState))
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> ThemeState
-> Const (Maybe StyleState) ThemeState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map String StyleState)
-> Lens'
     (Map String StyleState) (Maybe (IxValue (Map String StyleState)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
Index (Map String StyleState)
name
  focus :: Maybe StyleState
focus = WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
-> Maybe StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe StyleState) Theme)
-> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe StyleState) Theme)
 -> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e))
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Theme -> Const (Maybe StyleState) Theme)
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe StyleState) ThemeState)
-> Theme -> Const (Maybe StyleState) Theme
forall s a. HasFocus s a => Lens' s a
L.focus ((ThemeState -> Const (Maybe StyleState) ThemeState)
 -> Theme -> Const (Maybe StyleState) Theme)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> Theme
-> Const (Maybe StyleState) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map String StyleState
 -> Const (Maybe StyleState) (Map String StyleState))
-> ThemeState -> Const (Maybe StyleState) ThemeState
forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap ((Map String StyleState
  -> Const (Maybe StyleState) (Map String StyleState))
 -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Map String StyleState
    -> Const (Maybe StyleState) (Map String StyleState))
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> ThemeState
-> Const (Maybe StyleState) ThemeState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map String StyleState)
-> Lens'
     (Map String StyleState) (Maybe (IxValue (Map String StyleState)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
Index (Map String StyleState)
name
  focusHover :: Maybe StyleState
focusHover = WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
-> Maybe StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe StyleState) Theme)
-> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe StyleState) Theme)
 -> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e))
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Theme -> Const (Maybe StyleState) Theme)
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe StyleState) ThemeState)
-> Theme -> Const (Maybe StyleState) Theme
forall s a. HasFocusHover s a => Lens' s a
L.focusHover ((ThemeState -> Const (Maybe StyleState) ThemeState)
 -> Theme -> Const (Maybe StyleState) Theme)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> Theme
-> Const (Maybe StyleState) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map String StyleState
 -> Const (Maybe StyleState) (Map String StyleState))
-> ThemeState -> Const (Maybe StyleState) ThemeState
forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap ((Map String StyleState
  -> Const (Maybe StyleState) (Map String StyleState))
 -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Map String StyleState
    -> Const (Maybe StyleState) (Map String StyleState))
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> ThemeState
-> Const (Maybe StyleState) ThemeState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map String StyleState)
-> Lens'
     (Map String StyleState) (Maybe (IxValue (Map String StyleState)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
Index (Map String StyleState)
name
  active :: Maybe StyleState
active = WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
-> Maybe StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe StyleState) Theme)
-> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe StyleState) Theme)
 -> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e))
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Theme -> Const (Maybe StyleState) Theme)
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe StyleState) ThemeState)
-> Theme -> Const (Maybe StyleState) Theme
forall s a. HasActive s a => Lens' s a
L.active ((ThemeState -> Const (Maybe StyleState) ThemeState)
 -> Theme -> Const (Maybe StyleState) Theme)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> Theme
-> Const (Maybe StyleState) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map String StyleState
 -> Const (Maybe StyleState) (Map String StyleState))
-> ThemeState -> Const (Maybe StyleState) ThemeState
forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap ((Map String StyleState
  -> Const (Maybe StyleState) (Map String StyleState))
 -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Map String StyleState
    -> Const (Maybe StyleState) (Map String StyleState))
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> ThemeState
-> Const (Maybe StyleState) ThemeState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map String StyleState)
-> Lens'
     (Map String StyleState) (Maybe (IxValue (Map String StyleState)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
Index (Map String StyleState)
name
  disabled :: Maybe StyleState
disabled = WidgetEnv s e
wenv WidgetEnv s e
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
-> Maybe StyleState
forall s a. s -> Getting a s a -> a
^. (Theme -> Const (Maybe StyleState) Theme)
-> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e)
forall s a. HasTheme s a => Lens' s a
L.theme ((Theme -> Const (Maybe StyleState) Theme)
 -> WidgetEnv s e -> Const (Maybe StyleState) (WidgetEnv s e))
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Theme -> Const (Maybe StyleState) Theme)
-> Getting (Maybe StyleState) (WidgetEnv s e) (Maybe StyleState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ThemeState -> Const (Maybe StyleState) ThemeState)
-> Theme -> Const (Maybe StyleState) Theme
forall s a. HasDisabled s a => Lens' s a
L.disabled ((ThemeState -> Const (Maybe StyleState) ThemeState)
 -> Theme -> Const (Maybe StyleState) Theme)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> Theme
-> Const (Maybe StyleState) Theme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map String StyleState
 -> Const (Maybe StyleState) (Map String StyleState))
-> ThemeState -> Const (Maybe StyleState) ThemeState
forall s a. HasUserStyleMap s a => Lens' s a
L.userStyleMap ((Map String StyleState
  -> Const (Maybe StyleState) (Map String StyleState))
 -> ThemeState -> Const (Maybe StyleState) ThemeState)
-> ((Maybe StyleState
     -> Const (Maybe StyleState) (Maybe StyleState))
    -> Map String StyleState
    -> Const (Maybe StyleState) (Map String StyleState))
-> (Maybe StyleState
    -> Const (Maybe StyleState) (Maybe StyleState))
-> ThemeState
-> Const (Maybe StyleState) ThemeState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map String StyleState)
-> Lens'
     (Map String StyleState) (Maybe (IxValue (Map String StyleState)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at String
Index (Map String StyleState)
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