monomer-1.4.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.Single

Description

Helper for creating widgets without children elements.

Synopsis

Re-exported modules

Configuration

type SingleGetBaseStyle s e Source #

Arguments

 = GetBaseStyle s e

The base style for a new node.

Returns the base style for this type of widget.

Usually this style comes from the active theme.

type SingleGetCurrentStyle s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> StyleState

The active style for the node.

Returns the current style for this type of widget. It depends on the state of the widget, which can be:

  • Basic
  • Hovered
  • Focused
  • Hovered and Focused
  • Active
  • Disabled

In general there's no needed to override it, except when the widget does not use the full content rect. An example can be found in Monomer.Widgets.Singles.Radio.

type SingleInitHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> WidgetResult s e

The result of the init operation.

Initializes the given node. This could include rebuilding the widget in case internal state needs to use model/environment information, generate user events or make requests to the runtime.

An examples can be found in Monomer.Widgets.Singles.Label and Monomer.Widgets.Singles.Image. On the other hand, Monomer.Widgets.Radio does not need to override init.

type SingleMergeHandler s e a Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> WidgetNode s e

The previous widget node.

-> a

The state of the previous widget node.

-> WidgetResult s e

The result of the merge operation.

Merges the current node with the node it matched with during the merge process. Receives the newly created node (whose *init* function is not called), the previous node and the state extracted from that node. This process is widget dependent, and may use or ignore the previous state depending on newly available information.

In general, you want to at least keep the previous state unless the widget is stateless or only consumes model/environment information.

Examples can be found in Monomer.Widgets.Singles.Label and Monomer.Widgets.Singles.Image. On the other hand, Monomer.Widgets.Singles.Radio does not need to override merge since it's stateless.

type SingleDisposeHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> WidgetResult s e

The result of the dispose operation.

Disposes the current node. Only used by widgets which allocate resources during init or merge, and will usually involve requests to the runtime.

An example can be found Monomer.Widgets.Singles.Image.

type SingleFindNextFocusHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> FocusDirection

The direction in which focus is moving.

-> Path

The start path from which to search.

-> Maybe WidgetNodeInfo

The next focusable node info.

Returns the next focusable node. Since this type of widget does not have children, there is not need to override this function, as there are only two options:

  • The node is focusable and target is valid: the node is returned
  • The node is not focusable: Nothing is returned

type SingleFindByPointHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> Path

The start path from which to search.

-> Point

The point to test for.

-> Maybe WidgetNodeInfo

The hovered node info, if any.

Returns the currently hovered widget, if any. If the widget is rectangular and uses the full content area, there is not need to override this function.

An example can be found Monomer.Widgets.Singles.Radio.

type SingleEventHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> Path

The target path of the event.

-> SystemEvent

The SystemEvent to handle.

-> Maybe (WidgetResult s e)

The result of handling the event, if any.

Receives a System event and, optionally, returns a result. This can include an updated version of the widget (in case it has internal state), user events or requests to the runtime.

Examples can be found in Monomer.Widgets.Singles.Button and Monomer.Widgets.Singles.Slider.

type SingleMessageHandler s e Source #

Arguments

 = forall i. Typeable i 
=> WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> Path

The target path of the message.

-> i

The message to handle.

-> Maybe (WidgetResult s e)

The result of handling the message, if any.

Receives a message and, optionally, returns a result. This can include an updated version of the widget (in case it has internal state), user events or requests to the runtime. There is no validation regarding the message type, and the widget should take care of _casting_ to the correct type using "Data.Typeable.cast"

Examples can be found in Monomer.Widgets.Singles.Button and Monomer.Widgets.Singles.Slider.

type SingleGetSizeReqHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> (SizeReq, SizeReq)

The horizontal and vertical requirements.

Returns the preferred size for the widget. This size should not include border and padding; those are added automatically by Single.

This is called to update WidgetNodeInfo only at specific times.

Examples can be found in Monomer.Widgets.Singles.Checkbox and Monomer.Widgets.Singles.Label.

type SingleResizeHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> Rect

The new viewport.

-> WidgetResult s e

The result of resizing the widget.

Resizes the widget to the provided size. If the widget state does not depend on the viewport size, this function does not need to be overriden.

Examples can be found in Monomer.Widgets.Singles.Label.

type SingleRenderHandler s e Source #

Arguments

 = WidgetEnv s e

The widget environment.

-> WidgetNode s e

The widget node.

-> Renderer

The renderer, providing low level drawing functions.

-> IO ()

The IO action with rendering instructions.

Renders the widget's content using the given Renderer. In general, this method needs to be overriden.

Examples can be found in Monomer.Widgets.Singles.Checkbox and Monomer.Widgets.Singles.Slider.

data Single s e a Source #

Interface for Single widgets.

Constructors

Single 

Fields

Instances

Instances details
Default (Single s e a) Source # 
Instance details

Defined in Monomer.Widgets.Single

Methods

def :: Single s e a #

Constructors

createSingle :: WidgetModel a => a -> Single s e a -> Widget s e Source #

Creates a widget based on the Single infrastructure. An initial state and the Single definition need to be provided. In case internal state is not needed, () can be provided. Using the def instance as a starting point is recommended to focus on overriding only what is needed:

widget = createSingle () def {
  singleRender = ...
}