/src/Lamdu/Config/Theme.hs

https://github.com/Peaker/lamdu · Haskell · 177 lines · 154 code · 20 blank · 3 comment · 0 complexity · 1427f3612849a3328f06c86a45e26689 MD5 · raw file

  1. {-# OPTIONS -O0 #-}
  2. {-# LANGUAGE TemplateHaskell, MultiParamTypeClasses, TypeFamilies #-}
  3. -- | The themes/ config format
  4. module Lamdu.Config.Theme
  5. ( Help(..)
  6. , helpTextSize, helpTextColor, helpInputDocColor, helpBGColor, helpTint
  7. , helpShownIconTint, helpSrcLocColor
  8. , Eval(..), neighborsScaleFactor, neighborsPadding, staleResultTint
  9. , ToolTip(..), tooltipFgColor, tooltipBgColor
  10. , StatusBar(..), statusBarBGColor, statusBarHSpaces
  11. , Deleted(..), deletedDefTint, deletedDefDiagonalWidth, deletedUseDiagonalWidth
  12. , FontSel(..), fontSelWidth, fontSelStyle, fontSelSlant, fontSelWeight
  13. , fontSel
  14. , Theme(..)
  15. , title, fonts, sprites, baseTextSize, animationTimePeriodSec
  16. , animationRemainInPeriod, help, menu, searchTerm, name, eval, hover, tooltip
  17. , textColors, textEditCursorColor, textEditCursorWidth
  18. , topPadding, statusBar, deleted, maxEvalViewSize, versionControl
  19. , valAnnotation, indent, backgroundColor, invalidCursorOverlayColor
  20. , errorColor, successColor
  21. , letItemPadding, narrowUnderlineWidth
  22. , wideUnderlineWidth, valFrameBGColor, valFramePadding
  23. , typeFrameBGColor, stdSpacing, cursorColor, cursorDecayExponent
  24. , disabledColor, presentationChoiceScaleFactor, evaluatedPathBGColor
  25. ) where
  26. import qualified Control.Lens as Lens
  27. import Data.Aeson.TH (deriveJSON)
  28. import qualified Data.Aeson.TH.Extended as JsonTH
  29. import qualified Data.Aeson.Types as Aeson
  30. import Data.Char (toLower)
  31. import Data.List.Lens (prefixed)
  32. import Data.Vector.Vector2 (Vector2)
  33. import qualified GUI.Momentu.Hover as Hover
  34. import qualified GUI.Momentu.Responsive.Expression as Expression
  35. import qualified GUI.Momentu.Widgets.Menu as Menu
  36. import qualified GUI.Momentu.Widgets.Menu.Search as SearchMenu
  37. import qualified Graphics.DrawingCombinators as Draw
  38. import Lamdu.Config.Folder (HasConfigFolder(..))
  39. import qualified Lamdu.Config.Folder as Folder
  40. import Lamdu.Config.Theme.Fonts (FontSize, Fonts)
  41. import Lamdu.Config.Theme.Name (Name(..))
  42. import Lamdu.Config.Theme.Sprites (Sprites)
  43. import Lamdu.Config.Theme.TextColors (TextColors(..))
  44. import Lamdu.Config.Theme.ValAnnotation (ValAnnotation(..))
  45. import qualified Lamdu.GUI.VersionControl.Config as VersionControl
  46. import qualified Lamdu.I18N.Fonts as I18N.Fonts
  47. import Lamdu.Prelude
  48. data Help = Help
  49. { _helpTextSize :: FontSize
  50. , _helpTextColor :: Draw.Color
  51. , _helpInputDocColor :: Draw.Color
  52. , _helpBGColor :: Draw.Color
  53. , _helpTint :: Draw.Color
  54. , _helpShownIconTint :: Draw.Color
  55. , _helpSrcLocColor :: Maybe Draw.Color
  56. } deriving (Eq, Generic)
  57. JsonTH.derivePrefixed "_help" ''Help
  58. Lens.makeLenses ''Help
  59. data Eval = Eval
  60. { _neighborsScaleFactor :: Vector2 Double
  61. , _neighborsPadding :: Vector2 Double
  62. , _staleResultTint :: Draw.Color
  63. } deriving (Eq, Generic)
  64. JsonTH.derivePrefixed "_" ''Eval
  65. Lens.makeLenses ''Eval
  66. data ToolTip = ToolTip
  67. { _tooltipFgColor :: Draw.Color
  68. , _tooltipBgColor :: Draw.Color
  69. } deriving (Eq, Generic)
  70. JsonTH.derivePrefixed "_tooltip" ''ToolTip
  71. Lens.makeLenses ''ToolTip
  72. data StatusBar = StatusBar
  73. { _statusBarBGColor :: Draw.Color
  74. , _statusBarHSpaces :: Double
  75. } deriving (Eq, Generic)
  76. deriveJSON Aeson.defaultOptions
  77. { Aeson.fieldLabelModifier
  78. = (Lens.taking 2 traverse %~ toLower)
  79. . (^?! prefixed "_statusBar")
  80. }
  81. ''StatusBar
  82. Lens.makeLenses ''StatusBar
  83. data Deleted = Deleted
  84. { _deletedDefTint :: Draw.Color
  85. , _deletedDefDiagonalWidth :: Double
  86. , _deletedUseDiagonalWidth :: Double
  87. } deriving (Eq, Generic)
  88. JsonTH.derivePrefixed "_deleted" ''Deleted
  89. Lens.makeLenses ''Deleted
  90. data FontSel = FontSel
  91. { _fontSelWidth :: I18N.Fonts.ProportionalOrMonospace
  92. , _fontSelStyle :: I18N.Fonts.SansOrSerif
  93. , _fontSelSlant :: I18N.Fonts.RomanOrItalic
  94. , _fontSelWeight :: I18N.Fonts.LightOrBold
  95. } deriving (Eq, Generic)
  96. JsonTH.derivePrefixed "_fontSel" ''FontSel
  97. Lens.makeLenses ''FontSel
  98. fontSel ::
  99. FontSel ->
  100. Lens.ALens'
  101. (I18N.Fonts.ProportionalAndMonospace
  102. (I18N.Fonts.SansAndSerif
  103. (I18N.Fonts.RomanAndItalic
  104. (I18N.Fonts.LightAndBold a)))) a
  105. fontSel sel =
  106. I18N.Fonts.choice (sel ^. fontSelWidth) .
  107. I18N.Fonts.choice (sel ^. fontSelStyle) .
  108. I18N.Fonts.choice (sel ^. fontSelSlant) .
  109. I18N.Fonts.choice (sel ^. fontSelWeight)
  110. data Theme = Theme
  111. { _title :: Map Text Text
  112. , _fonts :: Fonts FontSel
  113. , _sprites :: Sprites FilePath
  114. , _baseTextSize :: FontSize
  115. , _animationTimePeriodSec :: Double
  116. , _animationRemainInPeriod :: Double
  117. , _help :: Help
  118. , _menu :: Menu.Style
  119. , _searchTerm :: SearchMenu.TermStyle
  120. , _name :: Name
  121. , _eval :: Eval
  122. , _hover :: Hover.Style
  123. , _tooltip :: ToolTip
  124. , _textColors :: TextColors
  125. , _textEditCursorColor :: Draw.Color
  126. , _textEditCursorWidth :: Draw.R
  127. , _topPadding :: Draw.R
  128. , _statusBar :: StatusBar
  129. , _deleted :: Deleted
  130. , _maxEvalViewSize :: Int
  131. , _versionControl :: VersionControl.Theme
  132. , _valAnnotation :: ValAnnotation
  133. , _indent :: Expression.Style
  134. , _backgroundColor :: Draw.Color
  135. , _invalidCursorOverlayColor :: Draw.Color
  136. , _errorColor :: Draw.Color
  137. , _successColor :: Draw.Color
  138. , _letItemPadding :: Vector2 Double
  139. , _narrowUnderlineWidth :: Double
  140. , _wideUnderlineWidth :: Double
  141. , _valFrameBGColor :: Draw.Color
  142. , _valFramePadding :: Vector2 Double
  143. , _typeFrameBGColor :: Draw.Color
  144. , _stdSpacing :: Vector2 Double -- as ratio of space character size
  145. , _cursorColor :: Draw.Color
  146. , _cursorDecayExponent :: Draw.R
  147. , _disabledColor :: Draw.Color
  148. , _presentationChoiceScaleFactor :: Vector2 Double
  149. , _evaluatedPathBGColor :: Draw.Color
  150. } deriving (Eq, Generic)
  151. JsonTH.derivePrefixed "_" ''Theme
  152. Lens.makeLenses ''Theme
  153. instance Has Expression.Style Theme where has = indent
  154. instance Has Hover.Style Theme where has = hover
  155. instance HasConfigFolder Theme where
  156. type Folder Theme = Folder.Theme
  157. configFolderName _ = "themes"