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 |
Helper for creating widgets without children elements.
Synopsis
- module Monomer.Core
- module Monomer.Core.Combinators
- module Monomer.Event
- module Monomer.Graphics
- module Monomer.Widgets.Util
- type SingleGetBaseStyle s e = GetBaseStyle s e
- type SingleGetCurrentStyle s e = WidgetEnv s e -> WidgetNode s e -> StyleState
- type SingleInitHandler s e = WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
- type SingleMergeHandler s e a = WidgetEnv s e -> WidgetNode s e -> WidgetNode s e -> a -> WidgetResult s e
- type SingleDisposeHandler s e = WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
- type SingleFindNextFocusHandler s e = WidgetEnv s e -> WidgetNode s e -> FocusDirection -> Path -> Maybe WidgetNodeInfo
- type SingleFindByPointHandler s e = WidgetEnv s e -> WidgetNode s e -> Path -> Point -> Maybe WidgetNodeInfo
- type SingleEventHandler s e = WidgetEnv s e -> WidgetNode s e -> Path -> SystemEvent -> Maybe (WidgetResult s e)
- type SingleMessageHandler s e = forall i. Typeable i => WidgetEnv s e -> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
- type SingleGetSizeReqHandler s e = WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
- type SingleResizeHandler s e = WidgetEnv s e -> WidgetNode s e -> Rect -> WidgetResult s e
- type SingleRenderHandler s e = WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
- data Single s e a = Single {
- singleAddStyleReq :: Bool
- singleDrawDecorations :: Bool
- singleFocusOnBtnPressed :: Bool
- singleUseCustomCursor :: Bool
- singleUseCustomSize :: Bool
- singleUseScissor :: Bool
- singleGetBaseStyle :: SingleGetBaseStyle s e
- singleGetCurrentStyle :: SingleGetCurrentStyle s e
- singleInit :: SingleInitHandler s e
- singleMerge :: SingleMergeHandler s e a
- singleDispose :: SingleDisposeHandler s e
- singleFindNextFocus :: SingleFindNextFocusHandler s e
- singleFindByPoint :: SingleFindByPointHandler s e
- singleHandleEvent :: SingleEventHandler s e
- singleHandleMessage :: SingleMessageHandler s e
- singleGetSizeReq :: SingleGetSizeReqHandler s e
- singleResize :: SingleResizeHandler s e
- singleRender :: SingleRenderHandler s e
- createSingle :: WidgetModel a => a -> Single s e a -> Widget s e
Re-exported modules
module Monomer.Core
module Monomer.Core.Combinators
module Monomer.Event
module Monomer.Graphics
module Monomer.Widgets.Util
Configuration
type SingleGetBaseStyle s e Source #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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 #
= 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.
Interface for Single widgets.
Single | |
|
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 = ... }