never executed always true always false
    1 {-|
    2 Module: Flaw.UI.Drawer
    3 Description: UI drawer object.
    4 License: MIT
    5 -}
    6 
    7 {-# LANGUAGE GADTs #-}
    8 
    9 module Flaw.UI.Drawer
   10   ( Drawer(..)
   11   , initDrawer
   12   , setDrawerFrameTime
   13   , DrawerStyles(..)
   14   , StyleVariant(..)
   15   , Style(..)
   16   , DrawerFont(..)
   17   , SomeFontShaper(..)
   18   ) where
   19 
   20 import Control.Concurrent.STM
   21 
   22 import Flaw.Graphics.Canvas
   23 import Flaw.Graphics.Font
   24 import Flaw.Graphics.Font.Render
   25 import Flaw.Math
   26 import Flaw.UI.Metrics
   27 
   28 -- | Drawer data.
   29 data Drawer d = Drawer
   30   {
   31   -- | Canvas.
   32     drawerCanvas :: !(Canvas d)
   33   -- | Glyph renderer for all fonts.
   34   , drawerGlyphRenderer :: !(GlyphRenderer d)
   35   -- | Length of previous frame in seconds.
   36   -- Use wisely in UI controls! As control not always gets rendered it may miss some time.
   37   , drawerFrameTimeVar :: !(TVar Float)
   38   -- | Style information.
   39   , drawerStyles :: DrawerStyles d
   40   }
   41 
   42 -- | Create drawer.
   43 initDrawer :: Canvas d -> GlyphRenderer d -> DrawerStyles d -> STM (Drawer d)
   44 initDrawer canvas glyphRenderer styles = do
   45   frameTimeVar <- newTVar 1
   46   return Drawer
   47     { drawerCanvas = canvas
   48     , drawerGlyphRenderer = glyphRenderer
   49     , drawerFrameTimeVar = frameTimeVar
   50     , drawerStyles = styles
   51     }
   52 
   53 -- | Update drawer with time passed.
   54 setDrawerFrameTime :: Drawer d -> Float -> STM ()
   55 setDrawerFrameTime Drawer
   56   { drawerFrameTimeVar = frameTimeVar
   57   } = writeTVar frameTimeVar
   58 
   59 -- | Style information.
   60 data DrawerStyles d = DrawerStyles
   61   {
   62   -- | Metrics.
   63     drawerMetrics :: !Metrics
   64   -- | Label font for UI.
   65   -- For normal labels, buttons, etc.
   66   , drawerLabelFont :: !(DrawerFont d)
   67   -- | Edit font for UI.
   68   -- For text entered by user.
   69   , drawerEditFont :: !(DrawerFont d)
   70   -- | Title font for UI.
   71   , drawerTitleFont :: !(DrawerFont d)
   72 
   73   -- | "Flat" style variant.
   74   -- Used for things like labels and checkboxes.
   75   , drawerFlatStyleVariant :: !StyleVariant
   76   -- | "Lowered" style variant.
   77   -- Mostly used for text fields, list boxes, etc.
   78   , drawerLoweredStyleVariant :: !StyleVariant
   79   -- | "Raised" style variant.
   80   -- Used for buttons.
   81   , drawerRaisedStyleVariant :: !StyleVariant
   82 
   83   , drawerFrameOuterNormalStyle :: !Style
   84   , drawerFrameOuterFocusedStyle :: !Style
   85   , drawerFrameInnerStyle :: !Style
   86   }
   87 
   88 data StyleVariant = StyleVariant
   89   { styleVariantNormalStyle :: !Style
   90   , styleVariantMousedStyle :: !Style
   91   , styleVariantPressedStyle :: !Style
   92   , styleVariantSelectedFocusedStyle :: !Style
   93   , styleVariantSelectedUnfocusedStyle :: !Style
   94   }
   95 
   96 data Style = Style
   97   { styleTextColor :: !Float4
   98   , styleFillColor :: !Float4
   99   , styleBorderColor :: !Float4
  100   }
  101 
  102 data DrawerFont d = DrawerFont
  103   { drawerFontRenderableFontCache :: !(RenderableFontCache d)
  104   , drawerFontShaper :: !SomeFontShaper
  105   }
  106 
  107 data SomeFontShaper where
  108   SomeFontShaper :: FontShaper s => !s -> SomeFontShaper