helm
helm copied to clipboard
Window does not expose setter for the size.
Currently to change the window size after the engine initialization develop needs to work directly with SDLEngine
as shown in the following code. It is bad, as we want to ensure that engine replacement is non-breaking change.
module Main where
import Helm
import Helm.Engine.SDL.Engine
import Helm.Graphics2D
import qualified Helm.Cmd as Cmd
import qualified Helm.Window as Window
import qualified Helm.Engine.SDL as SDL
import Data.StateVar (($=))
import Linear.V2 (V2(V2))
import qualified SDL.Video as Video
data Action = Idle | FitWindow Video.Window (V2 Int)
data Model = Model
initial :: (Model, Cmd SDLEngine Action)
initial = (Model, Cmd.none)
fit :: (V2 Int) -> (V2 Int)
fit (V2 width height) = V2 dimension dimension
where dimension = min width height
update :: Model -> Action -> (Model, Cmd SDLEngine Action)
update model Idle = (model, Cmd.none)
update model (FitWindow window size) = (model, resizeCommand)
where resizeCommand = Cmd.execute (Video.windowSize window $= fromIntegral <$> fit size) $ const Idle
subscriptions :: Video.Window -> Sub SDLEngine Action
subscriptions window = Window.resizes $ FitWindow window
view :: Model -> Graphics SDLEngine
view _ = Graphics2D $ collage []
main :: IO ()
main = do
engine@SDLEngine { window } <- SDL.startup
run engine GameConfig
{ initialFn = initial
, updateFn = update
, subscriptionsFn = subscriptions window
, viewFn = view
}
Engine should have its own setter for window size.