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 |
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
- module Monomer.Core
- module Monomer.Event
- module Monomer.Widgets.Util
- data CompositeCfg s e sp ep
- data EventResponse s e sp ep
- = Model s
- | Event e
- | Report ep
- | Request (WidgetRequest s e)
- | RequestParent (WidgetRequest sp ep)
- | forall i.Typeable i => Message WidgetKey i
- | Task (TaskHandler e)
- | Producer (ProducerHandler e)
- type MergeReqsHandler s e = WidgetEnv s e -> WidgetNode s e -> WidgetNode s e -> s -> [WidgetRequest s e]
- type EventHandler s e sp ep = WidgetEnv s e -> WidgetNode s e -> s -> e -> [EventResponse s e sp ep]
- type UIBuilder s e = WidgetEnv s e -> s -> WidgetNode s e
- compositeMergeReqs :: MergeReqsHandler s e -> CompositeCfg s e sp ep
- composite :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) => WidgetType -> ALens' sp s -> UIBuilder s e -> EventHandler s e sp ep -> WidgetNode sp ep
- composite_ :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) => WidgetType -> ALens' sp s -> UIBuilder s e -> EventHandler s e sp ep -> [CompositeCfg s e sp ep] -> WidgetNode sp ep
- compositeV :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) => WidgetType -> s -> (s -> ep) -> UIBuilder s e -> EventHandler s e sp ep -> WidgetNode sp ep
- compositeV_ :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) => WidgetType -> s -> (s -> ep) -> UIBuilder s e -> EventHandler s e sp ep -> [CompositeCfg s e sp ep] -> WidgetNode sp ep
- compositeD_ :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, ParentModel sp) => WidgetType -> WidgetData sp s -> UIBuilder s e -> EventHandler s e sp ep -> [CompositeCfg s e sp ep] -> WidgetNode sp ep
Documentation
module Monomer.Core
module Monomer.Event
module Monomer.Widgets.Util
data CompositeCfg s e sp ep Source #
Configuration options for composite widget.
Instances
data EventResponse s e sp ep Source #
Response options for an event handler.
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.
:: (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.
:: (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.
:: (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.
:: (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.
:: (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.