simple-ui 0.2.0 → 0.3.0
raw patch · 3 files changed
+25/−4 lines, 3 files
Files
- simple-ui.cabal +2/−1
- src/Simple/UI/Widgets/TextListView.hs +1/−1
- src/Simple/UI/Widgets/Widget.hs +22/−2
simple-ui.cabal view
@@ -1,5 +1,5 @@ name: simple-ui-version: 0.2.0+version: 0.3.0 cabal-version: 1.22 build-type: Simple author: Piotr Borek <piotrborek@op.pl>@@ -9,6 +9,7 @@ synopsis: UI library for terminal. description: UI library for terminal. category: Graphics+homepage: https://github.com/piotrborek/mp data-files: stack.yaml
src/Simple/UI/Widgets/TextListView.hs view
@@ -235,7 +235,7 @@ Vty.KHome -> goHome textListView- + Vty.KEnd -> goEnd textListView
src/Simple/UI/Widgets/Widget.hs view
@@ -33,6 +33,7 @@ widgetNew, connectColorsTo, keyPressed,+ widgetInitialized, draw, colorForeground, colorBackground,@@ -54,6 +55,7 @@ import Control.Lens (Lens', makeLenses, (&), (.~), (^.))+import Control.Monad (unless) import Control.Monad.State.Strict (State, execState) import Simple.UI.Core.Attribute import Simple.UI.Core.Draw@@ -63,6 +65,7 @@ data Widget = Widget { _widgetKeyPressed :: ListenerList (Vty.Key -> [Vty.Modifier]-> UIApp' ()) , _widgetDraw :: ListenerList (Drawing -> Int -> Int -> UIApp' ())+ , _widgetInitialized :: ListenerList (UIApp' ()) , _widgetColorForeground :: Attribute Vty.Color , _widgetColorBackground :: Attribute Vty.Color , _widgetColorStyle :: Attribute DrawStyle@@ -71,6 +74,7 @@ , _widgetColorStyleSelected :: Attribute DrawStyle , _widgetEnabled :: Attribute Bool , _widgetVisible :: Attribute Bool+ , _widgetInitializedFlag :: Attribute Bool -- , _widgetName :: String , _widgetComputeSize :: UIApp' (Int, Int)@@ -91,6 +95,9 @@ keyPressed :: w -> ListenerList (Vty.Key -> [Vty.Modifier]-> UIApp' ()) keyPressed = _widgetKeyPressed . castToWidget + widgetInitialized :: w -> ListenerList (UIApp' ())+ widgetInitialized = _widgetInitialized . castToWidget+ draw :: w -> ListenerList (Drawing -> Int -> Int -> UIApp' ()) draw = _widgetDraw . castToWidget @@ -141,6 +148,7 @@ widgetNew = do p <- listenerNew d <- listenerNew+ i <- listenerNew fgColor <- attributeNew Vty.white bgColor <- attributeNew Vty.black style <- attributeNew DrawStyleNormal@@ -149,9 +157,12 @@ selStyle <- attributeNew DrawStyleNormal en <- attributeNew True v <- attributeNew True- return Widget+ inited <- attributeNew False++ let widget = Widget { _widgetKeyPressed = p , _widgetDraw = d+ , _widgetInitialized = i , _widgetColorForeground = fgColor , _widgetColorBackground = bgColor , _widgetColorStyle = style@@ -162,8 +173,17 @@ , _widgetVisible = v , _widgetName = "widget" , _widgetComputeSize = return (1, 1)+ , _widgetInitializedFlag = inited } + on_ widget draw $ \_ _ _ -> do+ initedFlag <- get widget _widgetInitializedFlag+ unless initedFlag $ do+ set widget _widgetInitializedFlag True+ fire widget _widgetInitialized ()++ return widget+ overrideHelper :: WidgetClass p => (p -> State s () -> p) -> Lens' w p -> w -> State s () -> w overrideHelper overrideFunc parentLens widget f = widget & parentLens .~ overrideFunc parent f where@@ -185,7 +205,7 @@ setColors widget (foreground, background, style, selForeground, selBackground, selStyle) = do set widget colorForeground foreground set widget colorBackground background- set widget colorStyle style+ set widget colorStyle style set widget colorForegroundSelected selForeground set widget colorBackgroundSelected selBackground set widget colorStyleSelected selStyle