{-# LANGUAGE TemplateHaskell #-}
module Simple.UI.Widgets.StatusBar (
StatusBar,
castToStatusBar,
statusBarNew,
textLeft,
textCenter,
textRight
) where
import Control.Lens (makeLensesFor, (.=))
import qualified Graphics.Vty as Vty
import Simple.UI.Core.Internal.UIApp
import Simple.UI.Core.Attribute
import Simple.UI.Layouts.FillLayout
import Simple.UI.Widgets.Container
import Simple.UI.Widgets.Label
import Simple.UI.Widgets.Text
import Simple.UI.Widgets.Widget
data StatusBar = StatusBar
{ _statusBarParent :: Widget
, _statusBarTextLeft :: Label
, _statusBarTextCenter :: Label
, _statusBarTextRight :: Label
}
makeLensesFor [("_statusBarParent", "statusBarParent")] ''StatusBar
class WidgetClass w => StatusBarClass w where
castToStatusBar :: w -> StatusBar
textLeft :: w -> Attribute (Maybe String)
textLeft = text . _statusBarTextLeft . castToStatusBar
textCenter :: w -> Attribute (Maybe String)
textCenter = text . _statusBarTextCenter . castToStatusBar
textRight :: w -> Attribute (Maybe String)
textRight = text . _statusBarTextRight . castToStatusBar
instance StatusBarClass StatusBar where
castToStatusBar = id
instance WidgetClass StatusBar where
castToWidget = _statusBarParent
overrideWidget = overrideWidgetHelper statusBarParent
statusBarNew :: UIApp u StatusBar
statusBarNew = do
left <- labelNew Nothing
set left align TextAlignLeft
center <- labelNew Nothing
set center align TextAlignCenter
right <- labelNew Nothing
set right align TextAlignRight
_layout <- fillLayoutHorizontalNew
container <- containerNew _layout
addTo container left def
addTo container center def
addTo container right def
let _statusBar = StatusBar
{ _statusBarParent = castToWidget container
, _statusBarTextLeft = left
, _statusBarTextCenter = center
, _statusBarTextRight = right
}
let statusBar = overrideWidget _statusBar $
virtualWidgetName .= "statusbar"
statusBar `connectColorsTo` left
statusBar `connectColorsTo` center
statusBar `connectColorsTo` right
set statusBar colorForeground Vty.black
set statusBar colorBackground Vty.green
return statusBar