monomer-1.6.0.1: A GUI library for writing native Haskell applications.
Copyright(c) 2018 Francisco Vallarino
LicenseBSD-3-Clause (see the LICENSE file)
Maintainerfjvallarino@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Monomer.Main.Types

Description

Basic types for Main module.

Synopsis

Documentation

type MonomerM s e m = (Eq s, MonadState (MonomerCtx s e) m, MonadCatch m, MonadIO m) Source #

Main Monomer monad.

data RenderMsg s e Source #

Messages received by the rendering thread.

Constructors

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

Instances details
HasRenderMethod (MonomerCtx s e) (Either Renderer (TChan (RenderMsg s e))) Source # 
Instance details

Defined in Monomer.Main.Lens

data RenderSetupResult Source #

Result from attempting to set up the secondary rendering thread.

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.

Instances

Instances details
Generic RenderSchedule Source # 
Instance details

Defined in Monomer.Main.Types

Associated Types

type Rep RenderSchedule :: Type -> Type #

Show RenderSchedule Source # 
Instance details

Defined in Monomer.Main.Types

Eq RenderSchedule Source # 
Instance details

Defined in Monomer.Main.Types

HasWidgetId RenderSchedule WidgetId Source # 
Instance details

Defined in Monomer.Main.Lens

HasMs RenderSchedule Millisecond Source # 
Instance details

Defined in Monomer.Main.Lens

HasStart RenderSchedule Millisecond Source # 
Instance details

Defined in Monomer.Main.Lens

HasRepeat RenderSchedule (Maybe Int) Source # 
Instance details

Defined in Monomer.Main.Lens

HasRenderSchedule (MonomerCtx s e) (Map WidgetId RenderSchedule) Source # 
Instance details

Defined in Monomer.Main.Lens

type Rep RenderSchedule Source # 
Instance details

Defined in Monomer.Main.Types

data DragAction Source #

Drag action started by WidgetId, with an associated message.

data WidgetTask Source #

Asynchronous 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.

Constructors

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

Instances details
HasWidgetTasks (MonomerCtx s e) (Seq WidgetTask) Source # 
Instance details

Defined in Monomer.Main.Lens

data MonomerCtx s e Source #

Current state of the Monomer runtime.

Constructors

MonomerCtx 

Fields

Instances

Instances details
HasDpr (MonomerCtx s e) Double Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

dpr :: Lens' (MonomerCtx s e) Double Source #

HasInputStatus (MonomerCtx s e) InputStatus Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindowSize (MonomerCtx s e) Size Source # 
Instance details

Defined in Monomer.Main.Lens

HasEpr (MonomerCtx s e) Double Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

epr :: Lens' (MonomerCtx s e) Double Source #

HasExitApplication (MonomerCtx s e) Bool Source # 
Instance details

Defined in Monomer.Main.Lens

HasFocusedWidgetId (MonomerCtx s e) WidgetId Source # 
Instance details

Defined in Monomer.Main.Lens

HasLeaveEnterPair (MonomerCtx s e) Bool Source # 
Instance details

Defined in Monomer.Main.Lens

HasMainModel (MonomerCtx s e) s Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

mainModel :: Lens' (MonomerCtx s e) s Source #

HasRenderRequested (MonomerCtx s e) Bool Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindow (MonomerCtx s e) Window Source # 
Instance details

Defined in Monomer.Main.Lens

HasMainBtnPress (MonomerCtx s e) (Maybe (Path, Point)) Source # 
Instance details

Defined in Monomer.Main.Lens

HasCursorStack (MonomerCtx s e) [(WidgetId, CursorIcon)] Source # 
Instance details

Defined in Monomer.Main.Lens

HasDragAction (MonomerCtx s e) (Maybe DragAction) Source # 
Instance details

Defined in Monomer.Main.Lens

HasHoveredWidgetId (MonomerCtx s e) (Maybe WidgetId) Source # 
Instance details

Defined in Monomer.Main.Lens

HasOverlayWidgetId (MonomerCtx s e) (Maybe WidgetId) Source # 
Instance details

Defined in Monomer.Main.Lens

HasResizeRequests (MonomerCtx s e) (Seq WidgetId) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWidgetTasks (MonomerCtx s e) (Seq WidgetTask) Source # 
Instance details

Defined in Monomer.Main.Lens

HasCursorIcons (MonomerCtx s e) (Map CursorIcon Cursor) Source # 
Instance details

Defined in Monomer.Main.Lens

HasRenderMethod (MonomerCtx s e) (Either Renderer (TChan (RenderMsg s e))) Source # 
Instance details

Defined in Monomer.Main.Lens

HasRenderSchedule (MonomerCtx s e) (Map WidgetId RenderSchedule) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWidgetPaths (MonomerCtx s e) (Map WidgetId Path) Source # 
Instance details

Defined in Monomer.Main.Lens

data MainWindowState Source #

Requests for main window size.

Constructors

MainWindowNormal (Int, Int)

Normal window with a given size.

MainWindowMaximized

Maximized window.

MainWindowFullScreen

Full screen window.

data AppConfig s e Source #

Main application config.

Constructors

AppConfig 

Fields

Instances

Instances details
Monoid (AppConfig s e) Source # 
Instance details

Defined in Monomer.Main.Types

Methods

mempty :: AppConfig s e #

mappend :: AppConfig s e -> AppConfig s e -> AppConfig s e #

mconcat :: [AppConfig s e] -> AppConfig s e #

Semigroup (AppConfig s e) Source # 
Instance details

Defined in Monomer.Main.Types

Methods

(<>) :: AppConfig s e -> AppConfig s e -> AppConfig s e #

sconcat :: NonEmpty (AppConfig s e) -> AppConfig s e #

stimes :: Integral b => b -> AppConfig s e -> AppConfig s e #

Default (AppConfig s e) Source # 
Instance details

Defined in Monomer.Main.Types

Methods

def :: AppConfig s e #

HasContextButton (AppConfig s e) (Maybe Button) Source # 
Instance details

Defined in Monomer.Main.Lens

HasMainButton (AppConfig s e) (Maybe Button) Source # 
Instance details

Defined in Monomer.Main.Lens

HasTheme (AppConfig s e) (Maybe Theme) Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

theme :: Lens' (AppConfig s e) (Maybe Theme) Source #

HasDisableAutoScale (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasDisableCompositing (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasDisableScreensaver (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasDisposeEvent (AppConfig s e) [e] Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

disposeEvent :: Lens' (AppConfig s e) [e] Source #

HasExitEvent (AppConfig s e) [e] Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

exitEvent :: Lens' (AppConfig s e) [e] Source #

HasFonts (AppConfig s e) [FontDef] Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

fonts :: Lens' (AppConfig s e) [FontDef] Source #

HasInitEvent (AppConfig s e) [e] Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

initEvent :: Lens' (AppConfig s e) [e] Source #

HasInvertWheelX (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasInvertWheelY (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasMaxFps (AppConfig s e) (Maybe Int) Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

maxFps :: Lens' (AppConfig s e) (Maybe Int) Source #

HasModelFingerprintFn (AppConfig s e) (Maybe (s -> String)) Source # 
Instance details

Defined in Monomer.Main.Lens

HasResizeEvent (AppConfig s e) [Rect -> e] Source # 
Instance details

Defined in Monomer.Main.Lens

Methods

resizeEvent :: Lens' (AppConfig s e) [Rect -> e] Source #

HasScaleFactor (AppConfig s e) (Maybe Double) Source # 
Instance details

Defined in Monomer.Main.Lens

HasUseRenderThread (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindowBorder (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindowIcon (AppConfig s e) (Maybe Text) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindowResizable (AppConfig s e) (Maybe Bool) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindowState (AppConfig s e) (Maybe MainWindowState) Source # 
Instance details

Defined in Monomer.Main.Lens

HasWindowTitle (AppConfig s e) (Maybe Text) Source # 
Instance details

Defined in Monomer.Main.Lens

appWindowState :: MainWindowState -> AppConfig s e Source #

Initial size of the main window.

appWindowTitle :: Text -> AppConfig s e Source #

Title of the main window.

appWindowResizable :: Bool -> AppConfig s e Source #

Whether the main window is resizable.

appWindowBorder :: Bool -> AppConfig s e Source #

Whether the main window has a border.

appWindowIcon :: Text -> AppConfig s e Source #

Path to an icon file in BMP format.

appRenderOnMainThread :: AppConfig s 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 s 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 s 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 s 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 s e Source #

Available fonts to the application, loaded from the specified path. Specifying no fonts will make it impossible to render text.

appFontDefMem :: Text -> ByteString -> AppConfig s e Source #

Available fonts to the application, loaded from the bytes in memory. Specifying no fonts will make it impossible to render text.

One use case for this function is to embed fonts in the application, without the need to distribute the font files. The file-embed library can be used for this. appFontDefMemory "memoryFont" $(embedFile "dirName/fileName")

appTheme :: Theme -> AppConfig s e Source #

Initial theme.

appInitEvent :: e -> AppConfig s e Source #

Initial event, useful for loading resources.

appDisposeEvent :: e -> AppConfig s e Source #

Dispose event, useful for closing resources.

appExitEvent :: e -> AppConfig s e Source #

Exit event, useful for cancelling an application close event.

appResizeEvent :: (Rect -> e) -> AppConfig s e Source #

Resize event handler.

appMainButton :: Button -> AppConfig s e Source #

Defines which mouse button is considered main.

appContextButton :: Button -> AppConfig s e Source #

Defines which mouse button is considered secondary or context button.

appInvertWheelX :: Bool -> AppConfig s e Source #

Whether the horizontal wheel/trackpad movement should be inverted. In general platform detection should do the right thing.

appInvertWheelY :: Bool -> AppConfig s e Source #

Whether the vertical wheel/trackpad movement should be inverted. In general platform detection should do the right thing.

appDisableCompositing :: Bool -> AppConfig s 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 full-screen applications, disabling compositing may improve performance.

appDisableScreensaver :: Bool -> AppConfig s e Source #

Whether the screensaver should be disabled. Defaults to False.

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.

appModelFingerprint :: (s -> String) -> AppConfig s e Source #

Generates a fingerprint from the application's model. This is used to identify whether the application should attempt to reuse the model between reloads when running in interpreted mode. Since Monomer uses the model to build the UI, reusing the old model allows for quicker iteration as the application will be restored to its previous state before being reloaded. By default, unless a fingerprint function is provided, the model will not be reused and the application will start from scratch.

The fingerprint function is applied to the user provided model on application's startup only, not on subsequent updates during the application's lifetime. When a reload occurs, the original fingerprint of the model is compared against the fingerprint of the newly provided version of the model; if they match, it is assumed that the latest version of the original model can be reused. If the fingerprint changed because its data or data type changed, the new model will be used. The rationale is that, since the model is provided by the developer at startup, if the fingerprints match then only changes to business logic/UI have been made.

A fingerprint function is used because trying to compare two different versions of a data type using its Eq instance will result in ghci crashing. Creating a string based fingerprint as soon as the instance is available is a workaround for this issue. Ideally, the fingerprint would incorporate enough information to detect type and data changes.

A simple approach is using the show function to generate the fingerprint, although in some cases it may not be possible, maybe because the type does not implement it or it does not include enough information.

An alternative to show is <https://hackage.haskell.org/package/recover-rtti recover-rtti>'s anythingToString. This function returns a string representation of the data, although it does not include the name of record fields. In general this is not an issue, but changing a field's type from Int to Long will go undetected and cause a crash.

Ideally, we could use GHC.Fingerprint.Fingerprint to detect changes in the model's type, but unfortunately this is not reliable since this fingerprint is based on the 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.