monomer-1.0.0.0: 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 HaskellNone
LanguageHaskell2010

Monomer.Widgets.Composite

Description

Composite widget. Main glue between all the other widgets, also acts as the main app widget. Composite allows to split an application into reusable partss without the need to implement a lower level widget. It can comunicate with its parent component by reporting events.

Requires two main functions:

  • UI Builder: creates the widget tree based on the provided Widget Environment and model. This widget tree is made of other widgets, in general combinations of containers and singles.
  • Event Handler: processes user defined events which are raised by the widgets created when building the UI.

Configs:

  • mergeRequired: indicates if merging is necessary for this widget. In case the UI build process references information outside the model, it can be used to signal that merging is required even if the model has not changed. It can also be used as a performance tweak if the changes do not require rebuilding the UI.
  • onInit: event to raise when the widget is created. Useful for performing all kinds of initialization.
  • onDispose: event to raise when the widget is disposed. Used to free resources.
  • onResize: event to raise when the size of the widget changes.
  • onChange: event to raise when the size of the model changes.
  • onChangeReq: WidgetRequest to generate when the size of the widget changes.
  • onEnabledChange: event to raise when the enabled status changes.
  • onVisibleChange: event to raise when the visibility changes.
  • compositeMergeReqs: functions to generate WidgetRequests during the merge process. Since merge is already handled by Composite (by merging its tree), this is complementary for the cases when it's required. For example, it is used in Confirm to set the focus on its Accept button when visibility is restored (usually means it was brought to the front in a zstack).
Synopsis

Documentation

data CompositeCfg s e sp ep Source #

Configuration options for composite widget.

Instances

Instances details
Semigroup (CompositeCfg s e sp ep) Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

(<>) :: CompositeCfg s e sp ep -> CompositeCfg s e sp ep -> CompositeCfg s e sp ep #

sconcat :: NonEmpty (CompositeCfg s e sp ep) -> CompositeCfg s e sp ep #

stimes :: Integral b => b -> CompositeCfg s e sp ep -> CompositeCfg s e sp ep #

Monoid (CompositeCfg s e sp ep) Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

mempty :: CompositeCfg s e sp ep #

mappend :: CompositeCfg s e sp ep -> CompositeCfg s e sp ep -> CompositeCfg s e sp ep #

mconcat :: [CompositeCfg s e sp ep] -> CompositeCfg s e sp ep #

Default (CompositeCfg s e sp ep) Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

def :: CompositeCfg s e sp ep #

CmbOnVisibleChange (CompositeCfg s e sp ep) e Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onVisibleChange :: e -> CompositeCfg s e sp ep Source #

CmbOnEnabledChange (CompositeCfg s e sp ep) e Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onEnabledChange :: e -> CompositeCfg s e sp ep Source #

CmbOnDispose (CompositeCfg s e sp ep) e Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onDispose :: e -> CompositeCfg s e sp ep Source #

CmbOnInit (CompositeCfg s e sp ep) e Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onInit :: e -> CompositeCfg s e sp ep Source #

CmbMergeRequired (CompositeCfg s e sp ep) s Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

mergeRequired :: (s -> s -> Bool) -> CompositeCfg s e sp ep Source #

WidgetEvent ep => CmbOnChange (CompositeCfg s e sp ep) s ep Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onChange :: (s -> ep) -> CompositeCfg s e sp ep Source #

CmbOnResize (CompositeCfg s e sp ep) e Rect Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onResize :: (Rect -> e) -> CompositeCfg s e sp ep Source #

CmbOnChangeReq (CompositeCfg s e sp ep) sp ep s Source # 
Instance details

Defined in Monomer.Widgets.Composite

Methods

onChangeReq :: (s -> WidgetRequest sp ep) -> CompositeCfg s e sp ep Source #

data EventResponse s e sp ep Source #

Response options for an event handler.

Constructors

Model s

Modifies the current model, prompting a merge.

Event e

Raises a new event, which will be handled in the same cycle.

Report ep

Raises an event that will be handled by the parent.

Request (WidgetRequest s e)

Generates a WidgetRequest.

RequestParent (WidgetRequest sp ep)

Generates a WidgetRequest matching the parent's types. Useful when receiving requests as configuration from the parent, since the types will not match otherwise.

forall i.Typeable i => Message WidgetKey i

Sends a message to the given key. If the key does not exist, the message will not be delivered.

Task (TaskHandler e)

Runs an asynchronous task that will return a single result. The task is responsible for reporting errors using the expected event type. If the task crashes without returning a value, the composite will not know about it.

Producer (ProducerHandler e)

Runs an asynchronous task that will produce unlimited result. The producer is responsible for reporting errors using the expected event type. If the producer crashes without sending a value, composite will not know about it.

type MergeReqsHandler s e = WidgetEnv s e -> WidgetNode s e -> WidgetNode s e -> s -> [WidgetRequest s e] Source #

Generates requests during the merge process.

type EventHandler s e sp ep = WidgetEnv s e -> WidgetNode s e -> s -> e -> [EventResponse s e sp ep] Source #

Handles a composite event and returns a set of responses.

type UIBuilder s e = WidgetEnv s e -> s -> WidgetNode s e Source #

Creates the widget tree based on the given model.

compositeMergeReqs :: MergeReqsHandler s e -> CompositeCfg s e sp ep Source #

Generate WidgetRequests during the merge process.

composite Source #

Arguments

:: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) 
=> WidgetType

The name of the composite.

-> ALens' sp s

The lens into the parent's model.

-> UIBuilder s e

The UI builder function.

-> EventHandler s e sp ep

The event handler.

-> WidgetNode sp ep

The resulting widget.

Creates a composite taking its model from a lens into the parent model.

composite_ Source #

Arguments

:: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) 
=> WidgetType

The name of the composite.

-> ALens' sp s

The lens into the parent's model.

-> UIBuilder s e

The UI builder function.

-> EventHandler s e sp ep

The event handler.

-> [CompositeCfg s e sp ep]

The config options.

-> WidgetNode sp ep

The resulting widget.

Creates a composite taking its model from a lens into the parent model. Accepts config.

compositeV Source #

Arguments

:: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) 
=> WidgetType

The name of the composite.

-> s

The model.

-> (s -> ep)

The event to report when model changes.

-> UIBuilder s e

The UI builder function.

-> EventHandler s e sp ep

The event handler.

-> WidgetNode sp ep

The resulting widget.

Creates a composite using the given model and onChange event handler.

compositeV_ Source #

Arguments

:: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) 
=> WidgetType

The name of the composite.

-> s

The model.

-> (s -> ep)

The event to report when model changes.

-> UIBuilder s e

The UI builder function.

-> EventHandler s e sp ep

The event handler.

-> [CompositeCfg s e sp ep]

The config options.

-> WidgetNode sp ep

The resulting widget.

Creates a composite using the given model and onChange event handler. Accepts config.

compositeD_ Source #

Arguments

:: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) 
=> WidgetType

The name of the composite.

-> WidgetData sp s

The model.

-> UIBuilder s e

The UI builder function.

-> EventHandler s e sp ep

The event handler.

-> [CompositeCfg s e sp ep]

The config options.

-> WidgetNode sp ep

The resulting widget.

Creates a color picker providing a WidgetData instance and config.