GUI not automatically updated after model change
Closed this issue · 3 comments
smarwei commented
I Maybe I've misunderstood something, but it seems like the GUI is sometimes not automatically updated after the model was changed.
Only after I move the mouse over the elements, the interface is updated.
Simplified code:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ConstrainedClassMethods #-}
module Main where
import Control.Lens
import Data.Text (pack, toLower)
import qualified Monomer as M
import Monomer hiding (width)
data Box = Box {
_width :: Int
} deriving (Eq, Show)
newtype BoxRow = BoxRow {
_boxRowContent :: [Box]
} deriving (Eq, Show)
data Resolution = XL | LG | MD
deriving (Eq, Show)
resolutionSize :: Num p => Resolution -> p
resolutionSize XL = 190
resolutionSize LG = 126
resolutionSize MD = 50
data AppModel = AppModel {
_selectedResolution :: Resolution,
_boxes :: [Box]
} deriving (Eq, Show)
data ElementLocation = ElementLocation BoxRowIdx BoxIdx RowIdx ElementIdx deriving (Eq, Show)
type BoxRowIdx = Int
type BoxIdx = Int
type RowIdx = Int
type ElementIdx = Int
data AppEvent
= AppInit
deriving (Eq, Show)
makeLenses 'AppModel
makeLenses 'Box
buildUI
:: WidgetEnv AppModel AppEvent
-> AppModel
-> WidgetNode AppModel AppEvent
buildUI wenv model = widgetTree where
widgetTree = vstack [
hstack [
label "Resolution: ",
dropdown selectedResolution [XL, LG, MD] (label . toLower . pack . show) (label . toLower . pack . show)
],
spacer,
box ( hstack_ [childSpacing] $
fmap (buildBox model) (model ^. boxes) )
`styleBasic` [padding 8, border 2 red]
] `styleBasic` [padding 10]
buildBox :: AppModel -> Box -> WidgetNode AppModel AppEvent
buildBox model b =
box ( label "Some content" )
`styleBasic` [M.width boxWidth, padding 8, border 2 blueViolet, borderL 12 blueViolet]
where
resWidth = resolutionSize $ model ^. selectedResolution
boxWidth = fromIntegral (b ^. width) * resWidth / 12
handleEvent
:: WidgetEnv AppModel AppEvent
-> WidgetNode AppModel AppEvent
-> AppModel
-> AppEvent
-> [AppEventResponse AppModel AppEvent]
handleEvent wenv node model evt = case evt of
AppInit -> []
main :: IO ()
main = do
startApp model handleEvent buildUI config
where
config = [
appTheme darkTheme,
appFontDef "Regular" "./assets/fonts/Roboto-Regular.ttf",
appInitEvent AppInit
]
model = AppModel LG
[ Box 12
, Box 10
, Box 3
]
fjvallarino commented
This is indeed a bug! You can test the fix by modifying your stack.yaml
to point to:
- git: https://github.com/fjvallarino/monomer.git
commit: 20332c4aca0e5d362ad5209e95040dd786df2c97
This commit hash will only be valid until the fix is merged to main.
Thanks for reporting!
smarwei commented
that fixes the problem, thank you very much!
fjvallarino commented
Nice! I just merged the fix to main, so the previous commit hash is no longer valid. The new one, which will not be removed, is: 908de6f48eb91d3a7a0405737de30b1ddc3338a2
.
I'll close the issue now. Thanks for reporting!