Skip to content

Commit

Permalink
Revert to AppConfig only being parameterized by e
Browse files Browse the repository at this point in the history
  • Loading branch information
fjvallarino committed Nov 19, 2022
1 parent ef761ac commit 0a66513
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/Monomer/Main/Core.hs
Expand Up @@ -130,7 +130,7 @@ startApp
=> s -- ^ The initial model.
-> AppEventHandler s e -- ^ The event handler.
-> AppUIBuilder s e -- ^ The UI builder.
-> [AppConfig s e] -- ^ The application config.
-> [AppConfig e] -- ^ The application config.
-> IO () -- ^ The application action.
startApp newModel eventHandler uiBuilder configs = do
isGhci <- isGhciRunning
Expand Down Expand Up @@ -165,7 +165,7 @@ runAppLoop
-> TChan (RenderMsg sp ep)
-> Maybe (WidgetNode sp ep)
-> WidgetNode sp ep
-> AppConfig s e
-> AppConfig e
-> m ()
runAppLoop window glCtx channel moldRoot newRoot config = do
isGhci <- liftIO isGhciRunning
Expand Down Expand Up @@ -301,7 +301,7 @@ mainLoop
:: (MonomerM sp ep m, WidgetEvent e)
=> SDL.Window
-> FontManager
-> AppConfig s e
-> AppConfig e
-> MainLoopArgs sp e ep
-> m ()
mainLoop window fontManager config loopArgs = do
Expand Down Expand Up @@ -683,7 +683,7 @@ When running in GHCi, avoids reinitializing SDL, reuses the existing window and
restores the model and (merged) widget tree when code is reloaded.
-}
retrieveSDLWindow
:: AppConfig s e
:: AppConfig e
-> TChan (RenderMsg s e)
-> s
-> IO (SDL.Window, SDL.GLContext, MonomerCtx s e)
Expand All @@ -703,7 +703,7 @@ retrieveSDLWindow config channel model = do

retrieveModelAndRoot
:: WidgetModel s
=> AppConfig s e
=> AppConfig e
-> s
-> WidgetNode s e
-> IO (s, Maybe (WidgetNode s e))
Expand Down
4 changes: 2 additions & 2 deletions src/Monomer/Main/Platform.hs
Expand Up @@ -57,7 +57,7 @@ defaultWindowSize :: (Int, Int)
defaultWindowSize = (800, 600)

-- | Creates and initializes a window using the provided configuration.
initSDLWindow :: AppConfig s e -> IO (SDL.Window, Double, Double, SDL.GLContext)
initSDLWindow :: AppConfig e -> IO (SDL.Window, Double, Double, SDL.GLContext)
initSDLWindow config = do
SDL.initialize [SDL.InitVideo]

Expand Down Expand Up @@ -156,7 +156,7 @@ initSDLWindow config = do
Just MainWindowMaximized -> True
_ -> False

setWindowIcon :: SDL.Window -> AppConfig s e -> IO ()
setWindowIcon :: SDL.Window -> AppConfig e -> IO ()
setWindowIcon (SIT.Window winPtr) config =
forM_ (_apcWindowIcon config) $ \iconPath ->
flip catchAny handleException $ do
Expand Down
54 changes: 27 additions & 27 deletions src/Monomer/Main/Types.hs
Expand Up @@ -152,7 +152,7 @@ data MainWindowState
deriving (Eq, Show)

-- | Main application config.
data AppConfig s e = AppConfig {
data AppConfig e = AppConfig {
-- | Initial size of the main window.
_apcWindowState :: Maybe MainWindowState,
-- | Title of the main window.
Expand Down Expand Up @@ -212,7 +212,7 @@ data AppConfig s e = AppConfig {
_apcDisableModelReuse :: Maybe Bool
}

instance Default (AppConfig s e) where
instance Default (AppConfig e) where
def = AppConfig {
_apcWindowState = Nothing,
_apcWindowTitle = Nothing,
Expand All @@ -238,7 +238,7 @@ instance Default (AppConfig s e) where
_apcDisableModelReuse = Nothing
}

instance Semigroup (AppConfig s e) where
instance Semigroup (AppConfig e) where
(<>) a1 a2 = AppConfig {
_apcWindowState = _apcWindowState a2 <|> _apcWindowState a1,
_apcWindowTitle = _apcWindowTitle a2 <|> _apcWindowTitle a1,
Expand All @@ -264,35 +264,35 @@ instance Semigroup (AppConfig s e) where
_apcDisableModelReuse = _apcDisableModelReuse a2 <|> _apcDisableModelReuse a1
}

instance Monoid (AppConfig s e) where
instance Monoid (AppConfig e) where
mempty = def

-- | Initial size of the main window.
appWindowState :: MainWindowState -> AppConfig s e
appWindowState :: MainWindowState -> AppConfig e
appWindowState title = def {
_apcWindowState = Just title
}

-- | Title of the main window.
appWindowTitle :: Text -> AppConfig s e
appWindowTitle :: Text -> AppConfig e
appWindowTitle title = def {
_apcWindowTitle = Just title
}

-- | Whether the main window is resizable.
appWindowResizable :: Bool -> AppConfig s e
appWindowResizable :: Bool -> AppConfig e
appWindowResizable resizable = def {
_apcWindowResizable = Just resizable
}

-- | Whether the main window has a border.
appWindowBorder :: Bool -> AppConfig s e
appWindowBorder :: Bool -> AppConfig e
appWindowBorder border = def {
_apcWindowBorder = Just border
}

-- | Path to an icon file in BMP format.
appWindowIcon :: Text -> AppConfig s e
appWindowIcon :: Text -> AppConfig e
appWindowIcon path = def {
_apcWindowIcon = Just path
}
Expand All @@ -317,7 +317,7 @@ This flag is no longer necessary for those cases, since the library will:
-}
{-# DEPRECATED appRenderOnMainThread
"Should no longer be needed. Check appRenderOnMainThread's Haddock page." #-}
appRenderOnMainThread :: AppConfig s e
appRenderOnMainThread :: AppConfig e
appRenderOnMainThread = def {
_apcUseRenderThread = Just False
}
Expand All @@ -327,7 +327,7 @@ Max number of FPS the application will run on. It does not necessarily mean
rendering will happen every frame, but events and schedules will be checked at
this rate and may cause it.
-}
appMaxFps :: Int -> AppConfig s e
appMaxFps :: Int -> AppConfig e
appMaxFps fps = def {
_apcMaxFps = Just fps
}
Expand All @@ -337,7 +337,7 @@ Scale factor to apply to the viewport. This factor only affects the content, not
the size of the window. It is applied in addition to the detected display scale
factor, and can be useful if the detected value is not the desired.
-}
appScaleFactor :: Double -> AppConfig s e
appScaleFactor :: Double -> AppConfig e
appScaleFactor factor = def {
_apcScaleFactor = Just factor
}
Expand Down Expand Up @@ -380,7 +380,7 @@ Considering the above, when SDL_GetDisplayDPI fails, the library assumes that a
screen width larger than 1920 belongs to an HiDPI display and uses a scale
factor of 2. This factor is used to scale the window size and the content.
-}
appDisableAutoScale :: Bool -> AppConfig s e
appDisableAutoScale :: Bool -> AppConfig e
appDisableAutoScale disable = def {
_apcDisableAutoScale = Just disable
}
Expand All @@ -389,7 +389,7 @@ appDisableAutoScale disable = def {
Available fonts to the application, loaded from the specified path.
Specifying no fonts will make it impossible to render text.
-}
appFontDef :: Text -> Text -> AppConfig s e
appFontDef :: Text -> Text -> AppConfig e
appFontDef name path = def {
_apcFonts = [ FontDefFile name path ]
}
Expand All @@ -404,49 +404,49 @@ The [file-embed](https://hackage.haskell.org/package/file-embed-0.0.15.0/docs/Da
appFontDefMemory "memoryFont" $(embedFile "dirName/fileName")
@
-}
appFontDefMem :: Text -> ByteString -> AppConfig s e
appFontDefMem :: Text -> ByteString -> AppConfig e
appFontDefMem name bytes = def {
_apcFonts = [ FontDefMem name bytes ]
}

-- | Initial theme.
appTheme :: Theme -> AppConfig s e
appTheme :: Theme -> AppConfig e
appTheme t = def {
_apcTheme = Just t
}

-- | Initial event, useful for loading resources.
appInitEvent :: e -> AppConfig s e
appInitEvent :: e -> AppConfig e
appInitEvent evt = def {
_apcInitEvent = [evt]
}

-- | Dispose event, useful for closing resources.
appDisposeEvent :: e -> AppConfig s e
appDisposeEvent :: e -> AppConfig e
appDisposeEvent evt = def {
_apcDisposeEvent = [evt]
}

-- | Exit event, useful for cancelling an application close event.
appExitEvent :: e -> AppConfig s e
appExitEvent :: e -> AppConfig e
appExitEvent evt = def {
_apcExitEvent = [evt]
}

-- | Resize event handler.
appResizeEvent :: (Rect -> e) -> AppConfig s e
appResizeEvent :: (Rect -> e) -> AppConfig e
appResizeEvent evt = def {
_apcResizeEvent = [evt]
}

-- | Defines which mouse button is considered main.
appMainButton :: Button -> AppConfig s e
appMainButton :: Button -> AppConfig e
appMainButton btn = def {
_apcMainButton = Just btn
}

-- | Defines which mouse button is considered secondary or context button.
appContextButton :: Button -> AppConfig s e
appContextButton :: Button -> AppConfig e
appContextButton btn = def {
_apcContextButton = Just btn
}
Expand All @@ -455,7 +455,7 @@ appContextButton btn = def {
Whether the horizontal wheel/trackpad movement should be inverted. In general
platform detection should do the right thing.
-}
appInvertWheelX :: Bool -> AppConfig s e
appInvertWheelX :: Bool -> AppConfig e
appInvertWheelX invert = def {
_apcInvertWheelX = Just invert
}
Expand All @@ -464,7 +464,7 @@ appInvertWheelX invert = def {
Whether the vertical wheel/trackpad movement should be inverted. In general
platform detection should do the right thing.
-}
appInvertWheelY :: Bool -> AppConfig s e
appInvertWheelY :: Bool -> AppConfig e
appInvertWheelY invert = def {
_apcInvertWheelY = Just invert
}
Expand All @@ -477,7 +477,7 @@ Desktop applications should leave compositing as is since disabling it may
cause visual glitches in other programs. When creating games or full-screen
applications, disabling compositing may improve performance.
-}
appDisableCompositing :: Bool -> AppConfig s e
appDisableCompositing :: Bool -> AppConfig e
appDisableCompositing disable = def {
_apcDisableCompositing = Just disable
}
Expand All @@ -489,7 +489,7 @@ Desktop applications should leave the screensaver as is since disabling it also
affects power saving features, including turning off the screen. When creating
games or full-screen applications, disabling the screensaver may make sense.
-}
appDisableScreensaver :: Bool -> AppConfig s e
appDisableScreensaver :: Bool -> AppConfig e
appDisableScreensaver disable = def {
_apcDisableScreensaver = Just disable
}
Expand Down Expand Up @@ -527,7 +527,7 @@ type's name only.
GHC issue with more details: https://gitlab.haskell.org/ghc/ghc/-/issues/7897.
Related Hint issue: https://github.com/haskell-hint/hint/issues/31.
-}
appDisableModelReuse :: Bool -> AppConfig s e
appDisableModelReuse :: Bool -> AppConfig e
appDisableModelReuse disabled = def {
_apcDisableModelReuse = Just disabled
}

0 comments on commit 0a66513

Please sign in to comment.