Skip to content

Commit

Permalink
minor cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-ba committed Sep 27, 2024
1 parent 943d2c1 commit 4cefb2d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions examples/gui/src/Calculator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ window = do

result <- mkLabel displaySig

operators <- mkHStack (const [addBut, subBut, eqBut])
operators <- mkVStack (const [addBut, subBut, eqBut])
row1 <- mkHStack (const [b7, b8, b9])
row2 <- mkHStack (const [b4, b5, b6])
row3 <- mkHStack (const [b1, b2, b3])
row4 <- mkHStack (const [b0])
numbers <- mkVStack (const [row1, row2 , row3, row4])

numbers <- mkVStack (const [enabledWidget row1, enabledWidget row2 , enabledWidget row3, enabledWidget b0])

input <- mkHStack (const [enabledWidget numbers, enabledWidget operators])

Expand Down
16 changes: 8 additions & 8 deletions src/WidgetRattus/Widgets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import System.IO.Unsafe
import Control.Concurrent hiding (Chan)
import Data.IntSet as IntSet

import qualified Monomer
import qualified Monomer as M

-- The identity function.
instance Displayable Text where
Expand Down Expand Up @@ -134,19 +134,19 @@ mkTimerEvent n cb = (threadDelay n >> cb (AppEvent (Chan n) ())) >> return ()
runApplication :: IsWidget a => C a -> IO ()
runApplication (C w) = do
w' <- w
Monomer.startApp (AppModel w' emptyClock) handler builder config
M.startApp (AppModel w' emptyClock) handler builder config
where builder _ (AppModel w _) = mkWidget w
handler _ _ (AppModel w cl) (AppEvent (Chan ch) d) =
let inp = OneInput ch d in unsafePerformIO $ do
progressPromoteStoreAtomic inp
let (w' , cl') = progressAndNext inp w
let activeTimers = if ch > 0 then IntSet.delete ch cl else cl
let newTimers = IntSet.filter (> 0) cl' `IntSet.difference` activeTimers
let timers = Prelude.map (Monomer.Producer . mkTimerEvent) (IntSet.toList newTimers)
return (Monomer.Model (AppModel w' (newTimers `IntSet.union` activeTimers)) : Monomer.Request Monomer.RenderOnce : timers )
let timers = Prelude.map (M.Producer . mkTimerEvent) (IntSet.toList newTimers)
return (M.Model (AppModel w' (newTimers `IntSet.union` activeTimers)) : M.Request M.RenderOnce : timers )
config = [
Monomer.appWindowTitle "GUI Application",
Monomer.appTheme Monomer.lightTheme,
Monomer.appFontDef "Regular" "./assets/fonts/Roboto-Regular.ttf",
Monomer.appInitEvent (AppEvent (Chan 1) ())
M.appWindowTitle "GUI Application",
M.appTheme M.lightTheme,
M.appFontDef "Regular" "./assets/fonts/Roboto-Regular.ttf",
M.appInitEvent (AppEvent (Chan 1) ())
]
25 changes: 13 additions & 12 deletions src/WidgetRattus/Widgets/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import WidgetRattus.InternalPrimitives
import WidgetRattus.Signal
import Data.Text

import qualified Monomer
import qualified Monomer as M
{-# ANN module AllowLazyData #-}

-- The Displayable typeclass is used to define the display function.
Expand All @@ -37,8 +37,9 @@ data AppEvent where

-- The IsWidget typeclass is used to define the mkWidget function.
class Continuous a => IsWidget a where
mkWidget :: a -> Monomer.WidgetNode AppModel AppEvent
-- Coustom data types for widgets.
mkWidget :: a -> M.WidgetNode AppModel AppEvent

-- Custom data types for widgets.
data Widget where
Widget :: IsWidget a => !a -> !(Sig Bool) -> Widget

Expand Down Expand Up @@ -78,33 +79,33 @@ continuous ''Slider
-- Here widgget data types are passed to Monomer constructors.
instance IsWidget Button where
mkWidget Button{btnContent = txt ::: _ , btnClick = click} =
Monomer.button (display txt) (AppEvent click ())
M.button (display txt) (AppEvent click ())

instance IsWidget TextField where
mkWidget TextField{tfContent = txt ::: _, tfInput = inp} =
Monomer.textFieldV txt (AppEvent inp)
M.textFieldV txt (AppEvent inp)

instance IsWidget Label where
mkWidget Label{labText = txt ::: _} = Monomer.label (display txt)
mkWidget Label{labText = txt ::: _} = M.label (display txt)


instance IsWidget HStack where
mkWidget (HStack ws) = Monomer.hstack (fmap mkWidget (current ws))
mkWidget (HStack ws) = M.hstack_ [ M.childSpacing_ 2] (reverse' $ fmap mkWidget (current ws))

instance IsWidget VStack where
mkWidget (VStack ws) = Monomer.vstack (fmap mkWidget (current ws))
mkWidget (VStack ws) = M.vstack_ [ M.childSpacing_ 2] (reverse' $ fmap mkWidget (current ws))

instance IsWidget TextDropdown where
mkWidget TextDropdown{tddList = opts ::: _, tddCurr = curr ::: _, tddEvent = ch}
= Monomer.textDropdownV curr (AppEvent ch) opts
= M.textDropdownV curr (AppEvent ch) opts

instance IsWidget Popup where
mkWidget Popup{popCurr = curr ::: _, popEvent = ch, popChild = child}
= Monomer.popupV curr (AppEvent ch) (mkWidget (current child))
= M.popupV curr (AppEvent ch) (mkWidget (current child))

instance IsWidget Slider where
mkWidget Slider{sldCurr = curr ::: _, sldEvent = ch, sldMin = min ::: _, sldMax = max ::: _}
= Monomer.hsliderV curr (AppEvent ch) min max
= M.hsliderV curr (AppEvent ch) min max

instance IsWidget Widget where
mkWidget (Widget w (e ::: _)) = Monomer.nodeEnabled (mkWidget w) e
mkWidget (Widget w (e ::: _)) = M.nodeEnabled (mkWidget w) e

0 comments on commit 4cefb2d

Please sign in to comment.