New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window does not expose setter for the size. #121

nikita-leonov opened this Issue Sep 27, 2017 · 0 comments


None yet
1 participant

nikita-leonov commented Sep 27, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment