Copyright | (c) 2018 Francisco Vallarino |
---|---|
License | BSD-3-Clause (see the LICENSE file) |
Maintainer | fjvallarino@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Basic types for Main module.
Synopsis
- type MonomerM s e m = (Eq s, MonadState (MonomerCtx s e) m, MonadCatch m, MonadIO m)
- data RenderMsg s e
- = MsgInit (WidgetEnv s e) (WidgetNode s e)
- | MsgRender (WidgetEnv s e) (WidgetNode s e)
- | MsgResize Size
- | MsgRemoveImage Text
- | forall i. MsgRunInRender (TChan i) (IO i)
- data RenderSetupResult
- data RenderSchedule = RenderSchedule {}
- data DragAction = DragAction {}
- data WidgetTask
- = forall i.Typeable i => WidgetTask WidgetId (Async i)
- | forall i.Typeable i => WidgetProducer WidgetId (TChan i) (Async ())
- data MonomerCtx s e = MonomerCtx {
- _mcMainModel :: s
- _mcWindow :: ~Window
- _mcWindowSize :: Size
- _mcDpr :: Double
- _mcEpr :: Double
- _mcRenderMethod :: Either Renderer (TChan (RenderMsg s e))
- _mcInputStatus :: InputStatus
- _mcCursorStack :: [(WidgetId, CursorIcon)]
- _mcFocusedWidgetId :: WidgetId
- _mcHoveredWidgetId :: Maybe WidgetId
- _mcOverlayWidgetId :: Maybe WidgetId
- _mcDragAction :: Maybe DragAction
- _mcMainBtnPress :: Maybe (Path, Point)
- _mcWidgetTasks :: Seq WidgetTask
- _mcWidgetPaths :: Map WidgetId Path
- _mcCursorIcons :: Map CursorIcon Cursor
- _mcLeaveEnterPair :: Bool
- _mcResizeRequests :: Seq WidgetId
- _mcRenderRequested :: Bool
- _mcRenderSchedule :: Map WidgetId RenderSchedule
- _mcExitApplication :: Bool
- data MainWindowState
- data AppConfig e = AppConfig {
- _apcWindowState :: Maybe MainWindowState
- _apcWindowTitle :: Maybe Text
- _apcWindowResizable :: Maybe Bool
- _apcWindowBorder :: Maybe Bool
- _apcWindowIcon :: Maybe Text
- _apcUseRenderThread :: Maybe Bool
- _apcMaxFps :: Maybe Int
- _apcScaleFactor :: Maybe Double
- _apcDisableAutoScale :: Maybe Bool
- _apcFonts :: [FontDef]
- _apcTheme :: Maybe Theme
- _apcInitEvent :: [e]
- _apcDisposeEvent :: [e]
- _apcExitEvent :: [e]
- _apcResizeEvent :: [Rect -> e]
- _apcMainButton :: Maybe Button
- _apcContextButton :: Maybe Button
- _apcInvertWheelX :: Maybe Bool
- _apcInvertWheelY :: Maybe Bool
- _apcDisableCompositing :: Maybe Bool
- appWindowState :: MainWindowState -> AppConfig e
- appWindowTitle :: Text -> AppConfig e
- appWindowResizable :: Bool -> AppConfig e
- appWindowBorder :: Bool -> AppConfig e
- appWindowIcon :: Text -> AppConfig e
- appRenderOnMainThread :: AppConfig e
- appMaxFps :: Int -> AppConfig e
- appScaleFactor :: Double -> AppConfig e
- appDisableAutoScale :: Bool -> AppConfig e
- appFontDef :: Text -> Text -> AppConfig e
- appTheme :: Theme -> AppConfig e
- appInitEvent :: e -> AppConfig e
- appDisposeEvent :: e -> AppConfig e
- appExitEvent :: e -> AppConfig e
- appResizeEvent :: (Rect -> e) -> AppConfig e
- appMainButton :: Button -> AppConfig e
- appContextButton :: Button -> AppConfig e
- appInvertWheelX :: Bool -> AppConfig e
- appInvertWheelY :: Bool -> AppConfig e
- appDisableCompositing :: Bool -> AppConfig e
Documentation
type MonomerM s e m = (Eq s, MonadState (MonomerCtx s e) m, MonadCatch m, MonadIO m) Source #
Main Monomer monad.
Messages received by the rendering thread.
MsgInit (WidgetEnv s e) (WidgetNode s e) | |
MsgRender (WidgetEnv s e) (WidgetNode s e) | |
MsgResize Size | |
MsgRemoveImage Text | |
forall i. MsgRunInRender (TChan i) (IO i) |
Instances
HasRenderMethod (MonomerCtx s e) (Either Renderer (TChan (RenderMsg s e))) Source # | |
Defined in Monomer.Main.Lens renderMethod :: Lens' (MonomerCtx s e) (Either Renderer (TChan (RenderMsg s e))) Source # |
data RenderSetupResult Source #
Result from attempting to set up the secondary rendering thread.
Instances
Eq RenderSetupResult Source # | |
Defined in Monomer.Main.Types (==) :: RenderSetupResult -> RenderSetupResult -> Bool # (/=) :: RenderSetupResult -> RenderSetupResult -> Bool # | |
Show RenderSetupResult Source # | |
Defined in Monomer.Main.Types showsPrec :: Int -> RenderSetupResult -> ShowS # show :: RenderSetupResult -> String # showList :: [RenderSetupResult] -> ShowS # |
data RenderSchedule Source #
Requirements for periodic rendering by a widget. Start time is stored to calculate next frame based on the step ms. A maximum number of repetitions may be provided.
RenderSchedule | |
|
Instances
data DragAction Source #
Drag action started by WidgetId, with an associated message.
Instances
Eq DragAction Source # | |
Defined in Monomer.Main.Types (==) :: DragAction -> DragAction -> Bool # (/=) :: DragAction -> DragAction -> Bool # | |
Show DragAction Source # | |
Defined in Monomer.Main.Types showsPrec :: Int -> DragAction -> ShowS # show :: DragAction -> String # showList :: [DragAction] -> ShowS # | |
HasWidgetId DragAction WidgetId Source # | |
Defined in Monomer.Main.Lens | |
HasDragData DragAction WidgetDragMsg Source # | |
Defined in Monomer.Main.Lens | |
HasDragAction (MonomerCtx s e) (Maybe DragAction) Source # | |
Defined in Monomer.Main.Lens dragAction :: Lens' (MonomerCtx s e) (Maybe DragAction) Source # |
data WidgetTask Source #
Asychronous widget task. Results must be provided as user defined, Typeable, types. Error handling should be done inside the task and reporting handled as part of the user type.
forall i.Typeable i => WidgetTask WidgetId (Async i) | Task generating a single result (for example, an HTTP request). |
forall i.Typeable i => WidgetProducer WidgetId (TChan i) (Async ()) | Task generating a multiple result (for example, a Socket). |
Instances
HasWidgetTasks (MonomerCtx s e) (Seq WidgetTask) Source # | |
Defined in Monomer.Main.Lens widgetTasks :: Lens' (MonomerCtx s e) (Seq WidgetTask) Source # |
data MonomerCtx s e Source #
Current state of the Monomer runtime.
MonomerCtx | |
|
Instances
data MainWindowState Source #
Requests for main window size.
MainWindowNormal (Int, Int) | Normal window with a given size. |
MainWindowMaximized | Maximized window. |
MainWindowFullScreen | Full screen window. |
Instances
Eq MainWindowState Source # | |
Defined in Monomer.Main.Types (==) :: MainWindowState -> MainWindowState -> Bool # (/=) :: MainWindowState -> MainWindowState -> Bool # | |
Show MainWindowState Source # | |
Defined in Monomer.Main.Types showsPrec :: Int -> MainWindowState -> ShowS # show :: MainWindowState -> String # showList :: [MainWindowState] -> ShowS # | |
HasWindowState (AppConfig e) (Maybe MainWindowState) Source # | |
Defined in Monomer.Main.Lens windowState :: Lens' (AppConfig e) (Maybe MainWindowState) Source # |
Main application config.
AppConfig | |
|
Instances
appWindowState :: MainWindowState -> AppConfig e Source #
Initial size of the main window.
appWindowTitle :: Text -> AppConfig e Source #
Title of the main window.
appWindowResizable :: Bool -> AppConfig e Source #
Whether the main window is resizable.
appWindowBorder :: Bool -> AppConfig e Source #
Whether the main window has a border.
appWindowIcon :: Text -> AppConfig e Source #
Path to an icon file in BMP format.
appRenderOnMainThread :: AppConfig e Source #
Deprecated: Should no longer be needed. Check appRenderOnMainThread's Haddock page.
Performs rendering on the main thread. On macOS and Windows this also disables continuous rendering on window resize, but in some Linux configurations it still works.
This configuration option was originally available to handle:
- OpenGL driver issues which prevented normal startup showing the "Unable to make GL context current" error.
- Single threaded applications (without -threaded) which cannot use forkOS.
This flag is no longer necessary for those cases, since the library will:
- Attempt to fall back to rendering on the main thread if setting up a secondary rendering thread fails.
- Will not attempt to set up a secondary rendering thread if the runtime does not support bound threads (i.e. compiled without the -threaded flag).
appMaxFps :: Int -> AppConfig e Source #
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.
appScaleFactor :: Double -> AppConfig e Source #
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.
appDisableAutoScale :: Bool -> AppConfig e Source #
Whether display scaling detection should not be attempted. If set to True, the display scale will be set to 1. This flag does not cause an effect on macOS.
Disabling auto scaling also affects window size on Linux and Windows in the
cases where the library would have applied scaling. This happens because window
and viewport size are the same in those operating systems. Window size can be
adjusted with appWindowState
.
The logic for detecting display scaling varies depending on the platform:
macOS
Scaling can be detected based on the window size and viewport size; the ratio between these two give the scaling factor.
Using window and viewport size for detecting DPI only works on macOS; both Windows and Linux return the same value for window and viewport size.
Windows
SDL_GetDisplayDPI returns the DPI of the screen, and dividing by 96 gives the scaling factor. This factor is used to scale the window size and the content.
Linux
The situation is more complex, since SDL_GetDisplayDPI does not always return valid information. There is not a practical DPI/scale detection solution that works for all combinations of Linux display servers and window managers. Even when using the most popular window managers, the scaling factor may be handled differently by the distribution (GNOME in Ubuntu). For a reference of some of the existing options for DPI scaling detection, check here: https:/wiki.archlinux.orgtitle/HiDPI.
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.
appFontDef :: Text -> Text -> AppConfig e Source #
Available fonts to the application. An empty list will make it impossible to render text.
appInitEvent :: e -> AppConfig e Source #
Initial event, useful for loading resources.
appDisposeEvent :: e -> AppConfig e Source #
Dispose event, useful for closing resources.
appExitEvent :: e -> AppConfig e Source #
Exit event, useful for cancelling an application close event.
appResizeEvent :: (Rect -> e) -> AppConfig e Source #
Resize event handler.
appMainButton :: Button -> AppConfig e Source #
Defines which mouse button is considered main.
appContextButton :: Button -> AppConfig e Source #
Defines which mouse button is considered secondary or context button.
appInvertWheelX :: Bool -> AppConfig e Source #
Whether the horizontal wheel/trackpad movement should be inverted. In general platform detection should do the right thing.
appInvertWheelY :: Bool -> AppConfig e Source #
Whether the vertical wheel/trackpad movement should be inverted. In general platform detection should do the right thing.
appDisableCompositing :: Bool -> AppConfig e Source #
Whether compositing should be disabled. Linux only, ignored in other platforms. Defaults to False.
Desktop applications should leave compositing as is, since disabling it may cause visual glitches in other programs. When creating games or fullscreen applications, disabling compositing may improve performance.