{-|
Module      : Monomer.Widgets.Single
Copyright   : (c) 2018 Francisco Vallarino
License     : BSD-3-Clause (see the LICENSE file)
Maintainer  : fjvallarino@gmail.com
Stability   : experimental
Portability : non-portable

Helper for creating widgets without children elements.
-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}

module Monomer.Widgets.Single (
  -- * Re-exported modules
  module Monomer.Core,
  module Monomer.Core.Combinators,
  module Monomer.Event,
  module Monomer.Graphics,
  module Monomer.Widgets.Util,

  -- * Configuration
  SingleGetBaseStyle,
  SingleGetCurrentStyle,
  SingleInitHandler,
  SingleMergeHandler,
  SingleDisposeHandler,
  SingleFindNextFocusHandler,
  SingleFindByPointHandler,
  SingleEventHandler,
  SingleMessageHandler,
  SingleGetSizeReqHandler,
  SingleResizeHandler,
  SingleRenderHandler,
  Single(..),

  -- * Constructors
  createSingle
) where

import Control.Exception (AssertionFailed(..), throw)
import Control.Lens ((&), (^.), (^?), (.~), (%~), _Just)
import Data.Default
import Data.Maybe
import Data.Sequence (Seq(..), (|>))
import Data.Typeable (Typeable, cast)

import qualified Data.Sequence as Seq

import Monomer.Core
import Monomer.Core.Combinators
import Monomer.Event
import Monomer.Graphics
import Monomer.Helper
import Monomer.Widgets.Util

import qualified Monomer.Core.Lens as L

{-|
Returns the base style for this type of widget.

Usually this style comes from the active theme.
-}
type SingleGetBaseStyle s e
  = GetBaseStyle s e  -- ^ The base style for a new 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 SingleGetCurrentStyle s e
  = WidgetEnv s e      -- ^ The widget environment.
  -> WidgetNode s e    -- ^ The widget node.
  -> StyleState        -- ^ The active style for the node.

{-|
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 SingleInitHandler s e
  = WidgetEnv s e        -- ^ The widget environment.
  -> WidgetNode s e      -- ^ The widget node.
  -> WidgetResult s e    -- ^ The result of the init 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 SingleMergeHandler s e a
  = 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.

{-|
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 SingleDisposeHandler s e
  = WidgetEnv s e        -- ^ The widget environment.
  -> WidgetNode s e      -- ^ The widget node.
  -> WidgetResult s e    -- ^ The result of the dispose operation.

{-|
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 SingleFindNextFocusHandler s e
  = 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 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 SingleFindByPointHandler s e
  = 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.

{-|
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 SingleEventHandler s e
  = 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 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 SingleMessageHandler s e
  = 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.

{-|
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 SingleGetSizeReqHandler s e
  = WidgetEnv s e          -- ^ The widget environment.
  -> WidgetNode s e        -- ^ The widget node.
  -> (SizeReq, SizeReq)    -- ^ The horizontal and vertical requirements.

{-|
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 SingleResizeHandler s e
  = 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.

{-|
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".
-}
type SingleRenderHandler s e
  = 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.

-- | Interface for Single widgets.
data Single s e a = Single {
  -- | True if border and padding should be added to size requirement. Defaults
  --   to True.
  Single s e a -> Bool
singleAddStyleReq :: Bool,
  -- | True if focus should be requested when mouse button is pressed (before
  --   click). Defaults to True.
  Single s e a -> Bool
singleFocusOnBtnPressed :: Bool,
  -- | True if style cursor should be ignored. If it's False, cursor changes need
  --   to be handled in custom code. Defaults to False.
  Single s e a -> Bool
singleUseCustomCursor :: Bool,
  -- | If true, it will ignore extra space assigned by the parent container, but
  --   it will not use more space than assigned. Defaults to False.
  Single s e a -> Bool
singleUseCustomSize :: Bool,
  -- | True if automatic scissoring needs to be applied. Defaults to False.
  Single s e a -> Bool
singleUseScissor :: Bool,
  -- | Returns the base style for this type of widget.
  Single s e a -> SingleGetBaseStyle s e
singleGetBaseStyle :: SingleGetBaseStyle s e,
  -- | Returns the active style, depending on the status of the widget.
  Single s e a -> SingleGetCurrentStyle s e
singleGetCurrentStyle :: SingleGetCurrentStyle s e,
  -- | Initializes the given node.
  Single s e a -> SingleInitHandler s e
singleInit :: SingleInitHandler s e,
  -- | Merges the node with the node it matched with during the merge process.
  Single s e a -> SingleMergeHandler s e a
singleMerge :: SingleMergeHandler s e a,
  -- | Disposes the current node.
  Single s e a -> SingleDisposeHandler s e
singleDispose :: SingleDisposeHandler s e,
  -- | Returns the next focusable node.
  Single s e a -> SingleFindNextFocusHandler s e
singleFindNextFocus :: SingleFindNextFocusHandler s e,
  -- | Returns the currently hovered widget, if any.
  Single s e a -> SingleFindByPointHandler s e
singleFindByPoint :: SingleFindByPointHandler s e,
  -- | Receives a System event and, optionally, returns a result.
  Single s e a -> SingleEventHandler s e
singleHandleEvent :: SingleEventHandler s e,
  -- | Receives a message and, optionally, returns a result.
  Single s e a
-> forall i.
   Typeable i =>
   WidgetEnv s e
   -> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
singleHandleMessage :: SingleMessageHandler s e,
  -- | Returns the preferred size for the widget.
  Single s e a -> SingleGetSizeReqHandler s e
singleGetSizeReq :: SingleGetSizeReqHandler s e,
  -- | Resizes the widget to the provided size.
  Single s e a -> SingleResizeHandler s e
singleResize :: SingleResizeHandler s e,
  -- | Renders the widget's content.
  Single s e a -> SingleRenderHandler s e
singleRender :: SingleRenderHandler s e
}

instance Default (Single s e a) where
  def :: Single s e a
def = Single :: forall s e a.
Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> SingleGetBaseStyle s e
-> SingleGetCurrentStyle s e
-> SingleInitHandler s e
-> SingleMergeHandler s e a
-> SingleInitHandler s e
-> SingleFindNextFocusHandler s e
-> SingleFindByPointHandler s e
-> SingleEventHandler s e
-> SingleMessageHandler s e
-> SingleGetSizeReqHandler s e
-> SingleResizeHandler s e
-> SingleRenderHandler s e
-> Single s e a
Single {
    singleAddStyleReq :: Bool
singleAddStyleReq = Bool
True,
    singleFocusOnBtnPressed :: Bool
singleFocusOnBtnPressed = Bool
True,
    singleUseCustomCursor :: Bool
singleUseCustomCursor = Bool
False,
    singleUseCustomSize :: Bool
singleUseCustomSize = Bool
False,
    singleUseScissor :: Bool
singleUseScissor = Bool
False,
    singleGetBaseStyle :: SingleGetBaseStyle s e
singleGetBaseStyle = SingleGetBaseStyle s e
forall s e. SingleGetBaseStyle s e
defaultGetBaseStyle,
    singleGetCurrentStyle :: SingleGetCurrentStyle s e
singleGetCurrentStyle = SingleGetCurrentStyle s e
forall s e. SingleGetCurrentStyle s e
defaultGetCurrentStyle,
    singleInit :: SingleInitHandler s e
singleInit = SingleInitHandler s e
forall s e. SingleInitHandler s e
defaultInit,
    singleMerge :: SingleMergeHandler s e a
singleMerge = SingleMergeHandler s e a
forall s e a. SingleMergeHandler s e a
defaultMerge,
    singleDispose :: SingleInitHandler s e
singleDispose = SingleInitHandler s e
forall s e. SingleInitHandler s e
defaultDispose,
    singleFindNextFocus :: SingleFindNextFocusHandler s e
singleFindNextFocus = SingleFindNextFocusHandler s e
forall s e. SingleFindNextFocusHandler s e
defaultFindNextFocus,
    singleFindByPoint :: SingleFindByPointHandler s e
singleFindByPoint = SingleFindByPointHandler s e
forall s e. SingleFindByPointHandler s e
defaultFindByPoint,
    singleHandleEvent :: SingleEventHandler s e
singleHandleEvent = SingleEventHandler s e
forall s e. SingleEventHandler s e
defaultHandleEvent,
    singleHandleMessage :: SingleMessageHandler s e
singleHandleMessage = SingleMessageHandler s e
forall s e. SingleMessageHandler s e
defaultHandleMessage,
    singleGetSizeReq :: SingleGetSizeReqHandler s e
singleGetSizeReq = SingleGetSizeReqHandler s e
forall s e. SingleGetSizeReqHandler s e
defaultGetSizeReq,
    singleResize :: SingleResizeHandler s e
singleResize = SingleResizeHandler s e
forall s e. SingleResizeHandler s e
defaultResize,
    singleRender :: SingleRenderHandler s e
singleRender = SingleRenderHandler s e
forall s e. SingleRenderHandler s e
defaultRender
  }

{-|
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 = ...
}
@
-}
createSingle :: WidgetModel a => a -> Single s e a -> Widget s e
createSingle :: a -> Single s e a -> Widget s e
createSingle a
state Single s e a
single = Widget :: forall s e.
(WidgetEnv s e -> WidgetNode s e -> WidgetResult s e)
-> (WidgetEnv s e
    -> WidgetNode s e -> WidgetNode s e -> WidgetResult s e)
-> (WidgetEnv s e -> WidgetNode s e -> WidgetResult s e)
-> (WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState)
-> (WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode)
-> (WidgetEnv s e
    -> WidgetNode s e
    -> FocusDirection
    -> Path
    -> Maybe WidgetNodeInfo)
-> (WidgetEnv s e
    -> WidgetNode s e -> Path -> Point -> Maybe WidgetNodeInfo)
-> (WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo)
-> (WidgetEnv s e
    -> WidgetNode s e
    -> Path
    -> SystemEvent
    -> Maybe (WidgetResult s e))
-> (forall i.
    Typeable i =>
    WidgetEnv s e
    -> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e))
-> (WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq))
-> (WidgetEnv s e
    -> WidgetNode s e -> Rect -> (Path -> Bool) -> WidgetResult s e)
-> (WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ())
-> Widget s e
Widget {
  widgetInit :: WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
widgetInit = Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall a s e.
WidgetModel a =>
Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
initWrapper Single s e a
single,
  widgetMerge :: WidgetEnv s e
-> WidgetNode s e -> WidgetNode s e -> WidgetResult s e
widgetMerge = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
mergeWrapper Single s e a
single,
  widgetDispose :: WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
widgetDispose = Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall s e a.
Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
disposeWrapper Single s e a
single,
  widgetGetState :: WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
widgetGetState = a -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
forall i s e.
WidgetModel i =>
i -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
makeState a
state,
  widgetGetInstanceTree :: WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
widgetGetInstanceTree = Single s e a
-> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
getInstanceTreeWrapper Single s e a
single,
  widgetFindNextFocus :: WidgetEnv s e
-> WidgetNode s e -> FocusDirection -> Path -> Maybe WidgetNodeInfo
widgetFindNextFocus = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
forall s e a. Single s e a -> SingleFindNextFocusHandler s e
singleFindNextFocus Single s e a
single,
  widgetFindByPoint :: WidgetEnv s e
-> WidgetNode s e -> Path -> Point -> Maybe WidgetNodeInfo
widgetFindByPoint = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> Point
-> Maybe WidgetNodeInfo
forall s e a. Single s e a -> SingleFindByPointHandler s e
singleFindByPoint Single s e a
single,
  widgetFindBranchByPath :: WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo
widgetFindBranchByPath = WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo
forall s e.
WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo
singleFindBranchByPath,
  widgetHandleEvent :: WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
widgetHandleEvent = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
handleEventWrapper Single s e a
single,
  widgetHandleMessage :: forall i.
Typeable i =>
WidgetEnv s e
-> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
widgetHandleMessage = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> i
-> Maybe (WidgetResult s e)
forall s e a i.
(WidgetModel a, Typeable i) =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> i
-> Maybe (WidgetResult s e)
handleMessageWrapper Single s e a
single,
  widgetGetSizeReq :: WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
widgetGetSizeReq = Single s e a
-> WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
getSizeReqWrapper Single s e a
single,
  widgetResize :: WidgetEnv s e
-> WidgetNode s e -> Rect -> (Path -> Bool) -> WidgetResult s e
widgetResize = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Rect
-> (Path -> Bool)
-> WidgetResult s e
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Rect
-> (Path -> Bool)
-> WidgetResult s e
resizeHandlerWrapper Single s e a
single,
  widgetRender :: WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
widgetRender = Single s e a
-> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
forall s e a.
Single s e a
-> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
renderWrapper Single s e a
single
}

defaultGetBaseStyle :: SingleGetBaseStyle s e
defaultGetBaseStyle :: SingleGetBaseStyle s e
defaultGetBaseStyle WidgetEnv s e
wenv WidgetNode s e
node = Maybe Style
forall a. Maybe a
Nothing

defaultGetCurrentStyle :: SingleGetCurrentStyle s e
defaultGetCurrentStyle :: SingleGetCurrentStyle s e
defaultGetCurrentStyle WidgetEnv s e
wenv WidgetNode s e
node = SingleGetCurrentStyle s e
forall s e. SingleGetCurrentStyle s e
currentStyle WidgetEnv s e
wenv WidgetNode s e
node

defaultInit :: SingleInitHandler s e
defaultInit :: SingleInitHandler s e
defaultInit WidgetEnv s e
wenv WidgetNode s e
node = WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
node

initWrapper
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> WidgetResult s e
initWrapper :: Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
initWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node = WidgetResult s e
newResult where
  initHandler :: WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
initHandler = Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall s e a.
Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
singleInit Single s e a
single
  getBaseStyle :: SingleGetBaseStyle s e
getBaseStyle = Single s e a -> SingleGetBaseStyle s e
forall s e a. Single s e a -> SingleGetBaseStyle s e
singleGetBaseStyle Single s e a
single
  styledNode :: WidgetNode s e
styledNode = SingleGetBaseStyle s e
-> WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
forall s e.
GetBaseStyle s e
-> WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
initNodeStyle SingleGetBaseStyle s e
getBaseStyle WidgetEnv s e
wenv WidgetNode s e
node
  tmpResult :: WidgetResult s e
tmpResult = WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
initHandler WidgetEnv s e
wenv WidgetNode s e
styledNode
  newResult :: WidgetResult s e
newResult = WidgetResult s e
tmpResult
    WidgetResult s e
-> (WidgetResult s e -> WidgetResult s e) -> WidgetResult s e
forall a b. a -> (a -> b) -> b
& (WidgetNode s e -> Identity (WidgetNode s e))
-> WidgetResult s e -> Identity (WidgetResult s e)
forall s a. HasNode s a => Lens' s a
L.node ((WidgetNode s e -> Identity (WidgetNode s e))
 -> WidgetResult s e -> Identity (WidgetResult s e))
-> WidgetNode s e -> WidgetResult s e -> WidgetResult s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
forall s e. WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
updateSizeReq WidgetEnv s e
wenv (WidgetResult s e
tmpResult WidgetResult s e
-> Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
-> WidgetNode s e
forall s a. s -> Getting a s a -> a
^. Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
forall s a. HasNode s a => Lens' s a
L.node)

defaultMerge :: SingleMergeHandler s e a
defaultMerge :: SingleMergeHandler s e a
defaultMerge WidgetEnv s e
wenv WidgetNode s e
newNode WidgetNode s e
oldState a
oldNode = WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
newNode

mergeWrapper
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> WidgetNode s e
  -> WidgetResult s e
mergeWrapper :: Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
mergeWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
newNode WidgetNode s e
oldNode = WidgetResult s e
newResult where
  mergeHandler :: SingleMergeHandler s e a
mergeHandler = Single s e a -> SingleMergeHandler s e a
forall s e a. Single s e a -> SingleMergeHandler s e a
singleMerge Single s e a
single
  oldState :: Maybe WidgetState
oldState = Widget s e -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
widgetGetState (WidgetNode s e
oldNode WidgetNode s e
-> Getting (Widget s e) (WidgetNode s e) (Widget s e) -> Widget s e
forall s a. s -> Getting a s a -> a
^. Getting (Widget s e) (WidgetNode s e) (Widget s e)
forall s a. HasWidget s a => Lens' s a
L.widget) WidgetEnv s e
wenv WidgetNode s e
oldNode
  oldInfo :: WidgetNodeInfo
oldInfo = WidgetNode s e
oldNode WidgetNode s e
-> Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info

  nodeHandler :: WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
nodeHandler WidgetEnv s e
wenv WidgetNode s e
styledNode = case Maybe WidgetState -> Maybe a
forall i. WidgetModel i => Maybe WidgetState -> Maybe i
useState Maybe WidgetState
oldState of
    Just a
state -> SingleMergeHandler s e a
mergeHandler WidgetEnv s e
wenv WidgetNode s e
styledNode WidgetNode s e
oldNode a
state
    Maybe a
_ -> WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
styledNode
  tmpResult :: WidgetResult s e
tmpResult = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNodeInfo
-> (WidgetEnv s e -> WidgetNode s e -> WidgetResult s e)
-> WidgetResult s e
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNodeInfo
-> (WidgetEnv s e -> WidgetNode s e -> WidgetResult s e)
-> WidgetResult s e
runNodeHandler Single s e a
single WidgetEnv s e
wenv WidgetNode s e
newNode WidgetNodeInfo
oldInfo WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
nodeHandler
  newResult :: WidgetResult s e
newResult = WidgetNode s e -> WidgetResult s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e -> WidgetResult s e
handleWidgetIdChange WidgetNode s e
oldNode WidgetResult s e
tmpResult

runNodeHandler
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> WidgetNodeInfo
  -> (WidgetEnv s e -> WidgetNode s e -> WidgetResult s e)
  -> WidgetResult s e
runNodeHandler :: Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNodeInfo
-> (WidgetEnv s e -> WidgetNode s e -> WidgetResult s e)
-> WidgetResult s e
runNodeHandler Single s e a
single WidgetEnv s e
wenv WidgetNode s e
newNode WidgetNodeInfo
oldInfo WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
nodeHandler = WidgetResult s e
newResult where
  getBaseStyle :: SingleGetBaseStyle s e
getBaseStyle = Single s e a -> SingleGetBaseStyle s e
forall s e a. Single s e a -> SingleGetBaseStyle s e
singleGetBaseStyle Single s e a
single
  tempNode :: WidgetNode s e
tempNode = WidgetNode s e
newNode
    WidgetNode s e
-> (WidgetNode s e -> WidgetNode s e) -> WidgetNode s e
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((WidgetId -> Identity WidgetId)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (WidgetId -> Identity WidgetId)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Identity WidgetId)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasWidgetId s a => Lens' s a
L.widgetId ((WidgetId -> Identity WidgetId)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> WidgetId -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNodeInfo
oldInfo WidgetNodeInfo
-> Getting WidgetId WidgetNodeInfo WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. Getting WidgetId WidgetNodeInfo WidgetId
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
    WidgetNode s e
-> (WidgetNode s e -> WidgetNode s e) -> WidgetNode s e
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((Rect -> Identity Rect)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Rect -> Identity Rect)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect -> Identity Rect)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasViewport s a => Lens' s a
L.viewport ((Rect -> Identity Rect)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> Rect -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNodeInfo
oldInfo WidgetNodeInfo -> Getting Rect WidgetNodeInfo Rect -> Rect
forall s a. s -> Getting a s a -> a
^. Getting Rect WidgetNodeInfo Rect
forall s a. HasViewport s a => Lens' s a
L.viewport
    WidgetNode s e
-> (WidgetNode s e -> WidgetNode s e) -> WidgetNode s e
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Identity SizeReq)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasSizeReqW s a => Lens' s a
L.sizeReqW ((SizeReq -> Identity SizeReq)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> SizeReq -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNodeInfo
oldInfo WidgetNodeInfo -> Getting SizeReq WidgetNodeInfo SizeReq -> SizeReq
forall s a. s -> Getting a s a -> a
^. Getting SizeReq WidgetNodeInfo SizeReq
forall s a. HasSizeReqW s a => Lens' s a
L.sizeReqW
    WidgetNode s e
-> (WidgetNode s e -> WidgetNode s e) -> WidgetNode s e
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Identity SizeReq)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasSizeReqH s a => Lens' s a
L.sizeReqH ((SizeReq -> Identity SizeReq)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> SizeReq -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNodeInfo
oldInfo WidgetNodeInfo -> Getting SizeReq WidgetNodeInfo SizeReq -> SizeReq
forall s a. s -> Getting a s a -> a
^. Getting SizeReq WidgetNodeInfo SizeReq
forall s a. HasSizeReqH s a => Lens' s a
L.sizeReqH
  styledNode :: WidgetNode s e
styledNode = SingleGetBaseStyle s e
-> WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
forall s e.
GetBaseStyle s e
-> WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
initNodeStyle SingleGetBaseStyle s e
getBaseStyle WidgetEnv s e
wenv WidgetNode s e
tempNode

  tmpResult :: WidgetResult s e
tmpResult = WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
nodeHandler WidgetEnv s e
wenv WidgetNode s e
styledNode
  newResult :: WidgetResult s e
newResult
    | Maybe (WidgetResult s e) -> Bool
forall s e. Maybe (WidgetResult s e) -> Bool
isResizeAnyResult (WidgetResult s e -> Maybe (WidgetResult s e)
forall a. a -> Maybe a
Just WidgetResult s e
tmpResult) = WidgetResult s e
tmpResult
        WidgetResult s e
-> (WidgetResult s e -> WidgetResult s e) -> WidgetResult s e
forall a b. a -> (a -> b) -> b
& (WidgetNode s e -> Identity (WidgetNode s e))
-> WidgetResult s e -> Identity (WidgetResult s e)
forall s a. HasNode s a => Lens' s a
L.node ((WidgetNode s e -> Identity (WidgetNode s e))
 -> WidgetResult s e -> Identity (WidgetResult s e))
-> WidgetNode s e -> WidgetResult s e -> WidgetResult s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
forall s e. WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
updateSizeReq WidgetEnv s e
wenv (WidgetResult s e
tmpResult WidgetResult s e
-> Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
-> WidgetNode s e
forall s a. s -> Getting a s a -> a
^. Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
forall s a. HasNode s a => Lens' s a
L.node)
    | Bool
otherwise = WidgetResult s e
tmpResult

getInstanceTreeWrapper
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> WidgetInstanceNode
getInstanceTreeWrapper :: Single s e a
-> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
getInstanceTreeWrapper Single s e a
container WidgetEnv s e
wenv WidgetNode s e
node = WidgetInstanceNode
instNode where
  instNode :: WidgetInstanceNode
instNode = WidgetInstanceNode :: WidgetNodeInfo
-> Maybe WidgetState
-> Seq WidgetInstanceNode
-> WidgetInstanceNode
WidgetInstanceNode {
    _winInfo :: WidgetNodeInfo
_winInfo = WidgetNode s e
node WidgetNode s e
-> Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info,
    _winState :: Maybe WidgetState
_winState = Widget s e -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
widgetGetState (WidgetNode s e
node WidgetNode s e
-> Getting (Widget s e) (WidgetNode s e) (Widget s e) -> Widget s e
forall s a. s -> Getting a s a -> a
^. Getting (Widget s e) (WidgetNode s e) (Widget s e)
forall s a. HasWidget s a => Lens' s a
L.widget) WidgetEnv s e
wenv WidgetNode s e
node,
    _winChildren :: Seq WidgetInstanceNode
_winChildren = (WidgetNode s e -> WidgetInstanceNode)
-> Seq (WidgetNode s e) -> Seq WidgetInstanceNode
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
forall s e. WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
getChildTree WidgetEnv s e
wenv) (WidgetNode s e
node WidgetNode s e
-> Getting
     (Seq (WidgetNode s e)) (WidgetNode s e) (Seq (WidgetNode s e))
-> Seq (WidgetNode s e)
forall s a. s -> Getting a s a -> a
^. Getting
  (Seq (WidgetNode s e)) (WidgetNode s e) (Seq (WidgetNode s e))
forall s a. HasChildren s a => Lens' s a
L.children)
  }
  getChildTree :: WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
getChildTree WidgetEnv s e
wenv WidgetNode s e
child = Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
widgetGetInstanceTree (WidgetNode s e
child WidgetNode s e
-> Getting (Widget s e) (WidgetNode s e) (Widget s e) -> Widget s e
forall s a. s -> Getting a s a -> a
^. Getting (Widget s e) (WidgetNode s e) (Widget s e)
forall s a. HasWidget s a => Lens' s a
L.widget) WidgetEnv s e
wenv WidgetNode s e
child

defaultDispose :: SingleDisposeHandler s e
defaultDispose :: SingleDisposeHandler s e
defaultDispose WidgetEnv s e
wenv WidgetNode s e
node = WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
node

disposeWrapper
  :: Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> WidgetResult s e
disposeWrapper :: Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
disposeWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node = WidgetResult s e
result where
  disposeHandler :: WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
disposeHandler = Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall s e a.
Single s e a -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
singleDispose Single s e a
single
  WidgetResult WidgetNode s e
newNode Seq (WidgetRequest s e)
reqs = WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
disposeHandler WidgetEnv s e
wenv WidgetNode s e
node
  widgetId :: WidgetId
widgetId = WidgetNode s e
node WidgetNode s e
-> Getting WidgetId (WidgetNode s e) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode s e -> Const WidgetId (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
 -> WidgetNode s e -> Const WidgetId (WidgetNode s e))
-> Getting WidgetId WidgetNodeInfo WidgetId
-> Getting WidgetId (WidgetNode s e) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting WidgetId WidgetNodeInfo WidgetId
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
  newReqs :: Seq (WidgetRequest s e)
newReqs = Seq (WidgetRequest s e)
reqs Seq (WidgetRequest s e)
-> WidgetRequest s e -> Seq (WidgetRequest s e)
forall a. Seq a -> a -> Seq a
|> WidgetId -> WidgetRequest s e
forall s e. WidgetId -> WidgetRequest s e
ResetWidgetPath WidgetId
widgetId
  result :: WidgetResult s e
result = WidgetNode s e -> Seq (WidgetRequest s e) -> WidgetResult s e
forall s e.
WidgetNode s e -> Seq (WidgetRequest s e) -> WidgetResult s e
WidgetResult WidgetNode s e
newNode Seq (WidgetRequest s e)
newReqs

defaultFindNextFocus :: SingleFindNextFocusHandler s e
defaultFindNextFocus :: SingleFindNextFocusHandler s e
defaultFindNextFocus WidgetEnv s e
wenv WidgetNode s e
node FocusDirection
direction Path
startFrom
  | WidgetNode s e -> Path -> FocusDirection -> Bool
forall s e. WidgetNode s e -> Path -> FocusDirection -> Bool
isFocusCandidate WidgetNode s e
node Path
startFrom FocusDirection
direction = WidgetNodeInfo -> Maybe WidgetNodeInfo
forall a. a -> Maybe a
Just (WidgetNode s e
node WidgetNode s e
-> Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info)
  | Bool
otherwise = Maybe WidgetNodeInfo
forall a. Maybe a
Nothing

defaultFindByPoint :: SingleFindByPointHandler s e
defaultFindByPoint :: SingleFindByPointHandler s e
defaultFindByPoint WidgetEnv s e
wenv WidgetNode s e
node Path
start Point
point
  | Bool
visible Bool -> Bool -> Bool
&& Bool
validPath Bool -> Bool -> Bool
&& WidgetNode s e -> Point -> Bool
forall s e. WidgetNode s e -> Point -> Bool
isPointInNodeVp WidgetNode s e
node Point
point = WidgetNodeInfo -> Maybe WidgetNodeInfo
forall a. a -> Maybe a
Just WidgetNodeInfo
info
  | Bool
otherwise = Maybe WidgetNodeInfo
forall a. Maybe a
Nothing
  where
    info :: WidgetNodeInfo
info = WidgetNode s e
node WidgetNode s e
-> Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info
    visible :: Bool
visible = WidgetNodeInfo
info WidgetNodeInfo -> Getting Bool WidgetNodeInfo Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool WidgetNodeInfo Bool
forall s a. HasVisible s a => Lens' s a
L.visible
    path :: Path
path = WidgetNode s e
node WidgetNode s e -> Getting Path (WidgetNode s e) Path -> Path
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Path WidgetNodeInfo)
-> WidgetNode s e -> Const Path (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Path WidgetNodeInfo)
 -> WidgetNode s e -> Const Path (WidgetNode s e))
-> ((Path -> Const Path Path)
    -> WidgetNodeInfo -> Const Path WidgetNodeInfo)
-> Getting Path (WidgetNode s e) Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Path -> Const Path Path)
-> WidgetNodeInfo -> Const Path WidgetNodeInfo
forall s a. HasPath s a => Lens' s a
L.path
    validPath :: Bool
validPath = Path -> Path -> Bool
forall a. Eq a => Seq a -> Seq a -> Bool
seqStartsWith Path
start Path
path

singleFindBranchByPath
  :: WidgetEnv s e
  -> WidgetNode s e
  -> Path
  -> Seq WidgetNodeInfo
singleFindBranchByPath :: WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo
singleFindBranchByPath WidgetEnv s e
wenv WidgetNode s e
node Path
path
  | WidgetNodeInfo
info WidgetNodeInfo
-> ((Path -> Const Path Path)
    -> WidgetNodeInfo -> Const Path WidgetNodeInfo)
-> Path
forall s a. s -> Getting a s a -> a
^. (Path -> Const Path Path)
-> WidgetNodeInfo -> Const Path WidgetNodeInfo
forall s a. HasPath s a => Lens' s a
L.path Path -> Path -> Bool
forall a. Eq a => a -> a -> Bool
== Path
path = WidgetNodeInfo -> Seq WidgetNodeInfo
forall a. a -> Seq a
Seq.singleton WidgetNodeInfo
info
  | Bool
otherwise = Seq WidgetNodeInfo
forall a. Seq a
Seq.empty
  where
    info :: WidgetNodeInfo
info = WidgetNode s e
node WidgetNode s e
-> Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode s e) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info

defaultHandleEvent :: SingleEventHandler s e
defaultHandleEvent :: SingleEventHandler s e
defaultHandleEvent WidgetEnv s e
wenv WidgetNode s e
node Path
target SystemEvent
evt = Maybe (WidgetResult s e)
forall a. Maybe a
Nothing

handleEventWrapper
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> Path
  -> SystemEvent
  -> Maybe (WidgetResult s e)
handleEventWrapper :: Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
handleEventWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node Path
target SystemEvent
evt
  | Bool -> Bool
not (WidgetNode s e
node WidgetNode s e -> Getting Bool (WidgetNode s e) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode s e -> Const Bool (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode s e -> Const Bool (WidgetNode s e))
-> Getting Bool WidgetNodeInfo Bool
-> Getting Bool (WidgetNode s e) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Bool WidgetNodeInfo Bool
forall s a. HasVisible s a => Lens' s a
L.visible) = Maybe (WidgetResult s e)
forall a. Maybe a
Nothing
  | Bool
otherwise = WidgetEnv s e
-> Path
-> StyleState
-> Bool
-> WidgetNode s e
-> SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
forall s e.
WidgetEnv s e
-> Path
-> StyleState
-> Bool
-> WidgetNode s e
-> SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleStyleChange WidgetEnv s e
wenv Path
target StyleState
style Bool
handleCursor WidgetNode s e
node SystemEvent
evt Maybe (WidgetResult s e)
result
  where
    style :: StyleState
style = Single s e a -> SingleGetCurrentStyle s e
forall s e a. Single s e a -> SingleGetCurrentStyle s e
singleGetCurrentStyle Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node
    handleCursor :: Bool
handleCursor = Bool -> Bool
not (Single s e a -> Bool
forall s e a. Single s e a -> Bool
singleUseCustomCursor Single s e a
single)
    focusOnPressed :: Bool
focusOnPressed = Single s e a -> Bool
forall s e a. Single s e a -> Bool
singleFocusOnBtnPressed Single s e a
single
    handler :: WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
handler = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
forall s e a. Single s e a -> SingleEventHandler s e
singleHandleEvent Single s e a
single
    handlerRes :: Maybe (WidgetResult s e)
handlerRes = WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
handler WidgetEnv s e
wenv WidgetNode s e
node Path
target SystemEvent
evt
    sizeResult :: Maybe (WidgetResult s e)
sizeResult = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleSizeReqChange Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node (SystemEvent -> Maybe SystemEvent
forall a. a -> Maybe a
Just SystemEvent
evt) Maybe (WidgetResult s e)
handlerRes
    result :: Maybe (WidgetResult s e)
result
      | Bool
focusOnPressed = WidgetEnv s e
-> WidgetNode s e
-> SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
forall s e.
WidgetEnv s e
-> WidgetNode s e
-> SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleFocusRequest WidgetEnv s e
wenv WidgetNode s e
node SystemEvent
evt Maybe (WidgetResult s e)
sizeResult
      | Bool
otherwise = Maybe (WidgetResult s e)
sizeResult

handleFocusRequest
  :: WidgetEnv s e
  -> WidgetNode s e
  -> SystemEvent
  -> Maybe (WidgetResult s e)
  -> Maybe (WidgetResult s e)
handleFocusRequest :: WidgetEnv s e
-> WidgetNode s e
-> SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleFocusRequest WidgetEnv s e
wenv WidgetNode s e
oldNode SystemEvent
evt Maybe (WidgetResult s e)
mResult = Maybe (WidgetResult s e)
newResult where
  node :: WidgetNode s e
node = WidgetNode s e
-> (WidgetResult s e -> WidgetNode s e)
-> Maybe (WidgetResult s e)
-> WidgetNode s e
forall b a. b -> (a -> b) -> Maybe a -> b
maybe WidgetNode s e
oldNode (WidgetResult s e
-> Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
-> WidgetNode s e
forall s a. s -> Getting a s a -> a
^. Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
forall s a. HasNode s a => Lens' s a
L.node) Maybe (WidgetResult s e)
mResult
  prevReqs :: Seq (WidgetRequest s e)
prevReqs = Seq (WidgetRequest s e)
-> (WidgetResult s e -> Seq (WidgetRequest s e))
-> Maybe (WidgetResult s e)
-> Seq (WidgetRequest s e)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Seq (WidgetRequest s e)
forall a. Seq a
Empty (WidgetResult s e
-> Getting
     (Seq (WidgetRequest s e))
     (WidgetResult s e)
     (Seq (WidgetRequest s e))
-> Seq (WidgetRequest s e)
forall s a. s -> Getting a s a -> a
^. Getting
  (Seq (WidgetRequest s e))
  (WidgetResult s e)
  (Seq (WidgetRequest s e))
forall s a. HasRequests s a => Lens' s a
L.requests) Maybe (WidgetResult s e)
mResult
  isFocusable :: Bool
isFocusable = WidgetNode s e
node WidgetNode s e -> Getting Bool (WidgetNode s e) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode s e -> Const Bool (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode s e -> Const Bool (WidgetNode s e))
-> Getting Bool WidgetNodeInfo Bool
-> Getting Bool (WidgetNode s e) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Bool WidgetNodeInfo Bool
forall s a. HasFocusable s a => Lens' s a
L.focusable
  btnPressed :: Maybe Button
btnPressed = case SystemEvent
evt of
    ButtonAction Point
_ Button
btn ButtonState
BtnPressed Int
_ -> Button -> Maybe Button
forall a. a -> Maybe a
Just Button
btn
    SystemEvent
_ -> Maybe Button
forall a. Maybe a
Nothing
  isFocusReq :: Bool
isFocusReq = Maybe Button
btnPressed Maybe Button -> Maybe Button -> Bool
forall a. Eq a => a -> a -> Bool
== Button -> Maybe Button
forall a. a -> Maybe a
Just (WidgetEnv s e
wenv WidgetEnv s e -> Getting Button (WidgetEnv s e) Button -> Button
forall s a. s -> Getting a s a -> a
^. Getting Button (WidgetEnv s e) Button
forall s a. HasMainButton s a => Lens' s a
L.mainButton)
    Bool -> Bool -> Bool
&& Bool
isFocusable
    Bool -> Bool -> Bool
&& Bool -> Bool
not (WidgetEnv s e -> WidgetNode s e -> Bool
forall s e. WidgetEnv s e -> WidgetNode s e -> Bool
isNodeFocused WidgetEnv s e
wenv WidgetNode s e
node)
    Bool -> Bool -> Bool
&& WidgetEnv s e -> WidgetNode s e -> Bool
forall s e. WidgetEnv s e -> WidgetNode s e -> Bool
isNodeTopLevel WidgetEnv s e
wenv WidgetNode s e
node
    Bool -> Bool -> Bool
&& Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing ((WidgetRequest s e -> Bool) -> Seq (WidgetRequest s e) -> Maybe Int
forall a. (a -> Bool) -> Seq a -> Maybe Int
Seq.findIndexL WidgetRequest s e -> Bool
forall s e. WidgetRequest s e -> Bool
isFocusRequest Seq (WidgetRequest s e)
prevReqs)

  newReq :: WidgetRequest s e
newReq = WidgetId -> WidgetRequest s e
forall s e. WidgetId -> WidgetRequest s e
SetFocus (WidgetNode s e
node WidgetNode s e
-> Getting WidgetId (WidgetNode s e) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode s e -> Const WidgetId (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
 -> WidgetNode s e -> Const WidgetId (WidgetNode s e))
-> Getting WidgetId WidgetNodeInfo WidgetId
-> Getting WidgetId (WidgetNode s e) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting WidgetId WidgetNodeInfo WidgetId
forall s a. HasWidgetId s a => Lens' s a
L.widgetId)
  newResult :: Maybe (WidgetResult s e)
newResult
    | Bool
isFocusReq Bool -> Bool -> Bool
&& Maybe (WidgetResult s e) -> Bool
forall a. Maybe a -> Bool
isJust Maybe (WidgetResult s e)
mResult = (WidgetResult s e
-> (WidgetResult s e -> WidgetResult s e) -> WidgetResult s e
forall a b. a -> (a -> b) -> b
& (Seq (WidgetRequest s e) -> Identity (Seq (WidgetRequest s e)))
-> WidgetResult s e -> Identity (WidgetResult s e)
forall s a. HasRequests s a => Lens' s a
L.requests ((Seq (WidgetRequest s e) -> Identity (Seq (WidgetRequest s e)))
 -> WidgetResult s e -> Identity (WidgetResult s e))
-> (Seq (WidgetRequest s e) -> Seq (WidgetRequest s e))
-> WidgetResult s e
-> WidgetResult s e
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Seq (WidgetRequest s e)
-> WidgetRequest s e -> Seq (WidgetRequest s e)
forall a. Seq a -> a -> Seq a
|> WidgetRequest s e
forall s e. WidgetRequest s e
newReq)) (WidgetResult s e -> WidgetResult s e)
-> Maybe (WidgetResult s e) -> Maybe (WidgetResult s e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (WidgetResult s e)
mResult
    | Bool
isFocusReq = WidgetResult s e -> Maybe (WidgetResult s e)
forall a. a -> Maybe a
Just (WidgetResult s e -> Maybe (WidgetResult s e))
-> WidgetResult s e -> Maybe (WidgetResult s e)
forall a b. (a -> b) -> a -> b
$ WidgetNode s e -> [WidgetRequest s e] -> WidgetResult s e
forall s e.
WidgetNode s e -> [WidgetRequest s e] -> WidgetResult s e
resultReqs WidgetNode s e
node [WidgetRequest s e
forall s e. WidgetRequest s e
newReq]
    | Bool
otherwise = Maybe (WidgetResult s e)
mResult

defaultHandleMessage :: SingleMessageHandler s e
defaultHandleMessage :: WidgetEnv s e
-> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
defaultHandleMessage WidgetEnv s e
wenv WidgetNode s e
node Path
target i
message = Maybe (WidgetResult s e)
forall a. Maybe a
Nothing

handleMessageWrapper :: forall s e a i . (WidgetModel a, Typeable i)
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> Path
  -> i
  -> Maybe (WidgetResult s e)
handleMessageWrapper :: Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> i
-> Maybe (WidgetResult s e)
handleMessageWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node Path
target i
msg = Maybe (WidgetResult s e)
result where
  handler :: WidgetEnv s e
-> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
handler = Single s e a
-> forall i.
   Typeable i =>
   WidgetEnv s e
   -> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
forall s e a. Single s e a -> SingleMessageHandler s e
singleHandleMessage Single s e a
single
  result :: Maybe (WidgetResult s e)
result = Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleSizeReqChange Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node Maybe SystemEvent
forall a. Maybe a
Nothing
    (Maybe (WidgetResult s e) -> Maybe (WidgetResult s e))
-> Maybe (WidgetResult s e) -> Maybe (WidgetResult s e)
forall a b. (a -> b) -> a -> b
$ WidgetEnv s e
-> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
handler WidgetEnv s e
wenv WidgetNode s e
node Path
target i
msg

defaultGetSizeReq :: SingleGetSizeReqHandler s e
defaultGetSizeReq :: SingleGetSizeReqHandler s e
defaultGetSizeReq WidgetEnv s e
wenv WidgetNode s e
node = (SizeReq, SizeReq)
forall a. Default a => a
def

getSizeReqWrapper
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> (SizeReq, SizeReq)
getSizeReqWrapper :: Single s e a
-> WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
getSizeReqWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node = (SizeReq
newReqW, SizeReq
newReqH) where
  addStyleReq :: Bool
addStyleReq = Single s e a -> Bool
forall s e a. Single s e a -> Bool
singleAddStyleReq Single s e a
single
  handler :: WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
handler = Single s e a
-> WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
forall s e a. Single s e a -> SingleGetSizeReqHandler s e
singleGetSizeReq Single s e a
single
  style :: StyleState
style = Single s e a -> SingleGetCurrentStyle s e
forall s e a. Single s e a -> SingleGetCurrentStyle s e
singleGetCurrentStyle Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node

  reqs :: (SizeReq, SizeReq)
reqs = WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
handler WidgetEnv s e
wenv WidgetNode s e
node
  (SizeReq
tmpReqW, SizeReq
tmpReqH)
    | Bool
addStyleReq = StyleState -> (SizeReq, SizeReq) -> (SizeReq, SizeReq)
sizeReqAddStyle StyleState
style (SizeReq, SizeReq)
reqs
    | Bool
otherwise = (SizeReq, SizeReq)
reqs
  -- User settings take precedence
  newReqW :: SizeReq
newReqW = SizeReq -> Maybe SizeReq -> SizeReq
forall a. a -> Maybe a -> a
fromMaybe SizeReq
tmpReqW (StyleState
style StyleState
-> Getting (Maybe SizeReq) StyleState (Maybe SizeReq)
-> Maybe SizeReq
forall s a. s -> Getting a s a -> a
^. Getting (Maybe SizeReq) StyleState (Maybe SizeReq)
forall s a. HasSizeReqW s a => Lens' s a
L.sizeReqW)
  newReqH :: SizeReq
newReqH = SizeReq -> Maybe SizeReq -> SizeReq
forall a. a -> Maybe a -> a
fromMaybe SizeReq
tmpReqH (StyleState
style StyleState
-> Getting (Maybe SizeReq) StyleState (Maybe SizeReq)
-> Maybe SizeReq
forall s a. s -> Getting a s a -> a
^. Getting (Maybe SizeReq) StyleState (Maybe SizeReq)
forall s a. HasSizeReqH s a => Lens' s a
L.sizeReqH)

updateSizeReq
  :: WidgetEnv s e
  -> WidgetNode s e
  -> WidgetNode s e
updateSizeReq :: WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
updateSizeReq WidgetEnv s e
wenv WidgetNode s e
node = WidgetNode s e
newNode where
  (SizeReq
newReqW, SizeReq
newReqH) = Widget s e -> WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> (SizeReq, SizeReq)
widgetGetSizeReq (WidgetNode s e
node WidgetNode s e
-> Getting (Widget s e) (WidgetNode s e) (Widget s e) -> Widget s e
forall s a. s -> Getting a s a -> a
^. Getting (Widget s e) (WidgetNode s e) (Widget s e)
forall s a. HasWidget s a => Lens' s a
L.widget) WidgetEnv s e
wenv WidgetNode s e
node
  newNode :: WidgetNode s e
newNode = WidgetNode s e
node
    WidgetNode s e
-> (WidgetNode s e -> WidgetNode s e) -> WidgetNode s e
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Identity SizeReq)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasSizeReqW s a => Lens' s a
L.sizeReqW ((SizeReq -> Identity SizeReq)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> SizeReq -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ SizeReq
newReqW
    WidgetNode s e
-> (WidgetNode s e -> WidgetNode s e) -> WidgetNode s e
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Identity SizeReq)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasSizeReqH s a => Lens' s a
L.sizeReqH ((SizeReq -> Identity SizeReq)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> SizeReq -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ SizeReq
newReqH

handleSizeReqChange
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> Maybe SystemEvent
  -> Maybe (WidgetResult s e)
  -> Maybe (WidgetResult s e)
handleSizeReqChange :: Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleSizeReqChange Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node Maybe SystemEvent
evt Maybe (WidgetResult s e)
mResult = Maybe (WidgetResult s e)
result where
  baseResult :: WidgetResult s e
baseResult = WidgetResult s e -> Maybe (WidgetResult s e) -> WidgetResult s e
forall a. a -> Maybe a -> a
fromMaybe (WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
node) Maybe (WidgetResult s e)
mResult
  newNode :: WidgetNode s e
newNode = WidgetResult s e
baseResult WidgetResult s e
-> Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
-> WidgetNode s e
forall s a. s -> Getting a s a -> a
^. Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
forall s a. HasNode s a => Lens' s a
L.node
  resizeReq :: Bool
resizeReq = Maybe (WidgetResult s e) -> Bool
forall s e. Maybe (WidgetResult s e) -> Bool
isResizeAnyResult Maybe (WidgetResult s e)
mResult
  styleChanged :: Bool
styleChanged = Maybe SystemEvent -> Bool
forall a. Maybe a -> Bool
isJust Maybe SystemEvent
evt Bool -> Bool -> Bool
&& WidgetEnv s e -> WidgetNode s e -> SystemEvent -> Bool
forall s e. WidgetEnv s e -> WidgetNode s e -> SystemEvent -> Bool
styleStateChanged WidgetEnv s e
wenv WidgetNode s e
newNode (Maybe SystemEvent -> SystemEvent
forall a. HasCallStack => Maybe a -> a
fromJust Maybe SystemEvent
evt)
  result :: Maybe (WidgetResult s e)
result
    | Bool
styleChanged Bool -> Bool -> Bool
|| Bool
resizeReq = WidgetResult s e -> Maybe (WidgetResult s e)
forall a. a -> Maybe a
Just (WidgetResult s e -> Maybe (WidgetResult s e))
-> WidgetResult s e -> Maybe (WidgetResult s e)
forall a b. (a -> b) -> a -> b
$ WidgetResult s e
baseResult
      WidgetResult s e
-> (WidgetResult s e -> WidgetResult s e) -> WidgetResult s e
forall a b. a -> (a -> b) -> b
& (WidgetNode s e -> Identity (WidgetNode s e))
-> WidgetResult s e -> Identity (WidgetResult s e)
forall s a. HasNode s a => Lens' s a
L.node ((WidgetNode s e -> Identity (WidgetNode s e))
 -> WidgetResult s e -> Identity (WidgetResult s e))
-> WidgetNode s e -> WidgetResult s e -> WidgetResult s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
forall s e. WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
updateSizeReq WidgetEnv s e
wenv WidgetNode s e
newNode
    | Bool
otherwise = Maybe (WidgetResult s e)
mResult

defaultResize :: SingleResizeHandler s e
defaultResize :: SingleResizeHandler s e
defaultResize WidgetEnv s e
wenv WidgetNode s e
node Rect
viewport = WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
node

resizeHandlerWrapper
  :: WidgetModel a
  => Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> Rect
  -> (Path -> Bool)
  -> WidgetResult s e
resizeHandlerWrapper :: Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Rect
-> (Path -> Bool)
-> WidgetResult s e
resizeHandlerWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node Rect
viewport Path -> Bool
resizeReq = WidgetResult s e
result where
  useCustomSize :: Bool
useCustomSize = Single s e a -> Bool
forall s e a. Single s e a -> Bool
singleUseCustomSize Single s e a
single
  handler :: SingleResizeHandler s e
handler = Single s e a -> SingleResizeHandler s e
forall s e a. Single s e a -> SingleResizeHandler s e
singleResize Single s e a
single

  tmpRes :: WidgetResult s e
tmpRes = SingleResizeHandler s e
handler WidgetEnv s e
wenv WidgetNode s e
node Rect
viewport
  lensVp :: (Rect -> Const Rect Rect)
-> WidgetNode s e -> Const Rect (WidgetNode s e)
lensVp = (WidgetNodeInfo -> Const Rect WidgetNodeInfo)
-> WidgetNode s e -> Const Rect (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Rect WidgetNodeInfo)
 -> WidgetNode s e -> Const Rect (WidgetNode s e))
-> Getting Rect WidgetNodeInfo Rect
-> (Rect -> Const Rect Rect)
-> WidgetNode s e
-> Const Rect (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Rect WidgetNodeInfo Rect
forall s a. HasViewport s a => Lens' s a
L.viewport
  newVp :: Rect
newVp
    | Bool
useCustomSize = WidgetResult s e
tmpRes WidgetResult s e -> Getting Rect (WidgetResult s e) Rect -> Rect
forall s a. s -> Getting a s a -> a
^. (WidgetNode s e -> Const Rect (WidgetNode s e))
-> WidgetResult s e -> Const Rect (WidgetResult s e)
forall s a. HasNode s a => Lens' s a
L.node ((WidgetNode s e -> Const Rect (WidgetNode s e))
 -> WidgetResult s e -> Const Rect (WidgetResult s e))
-> ((Rect -> Const Rect Rect)
    -> WidgetNode s e -> Const Rect (WidgetNode s e))
-> Getting Rect (WidgetResult s e) Rect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect -> Const Rect Rect)
-> WidgetNode s e -> Const Rect (WidgetNode s e)
lensVp
    | Bool
otherwise = Rect
viewport
  tmpResult :: Maybe (WidgetResult s e)
tmpResult = WidgetResult s e -> Maybe (WidgetResult s e)
forall a. a -> Maybe a
Just (WidgetResult s e -> Maybe (WidgetResult s e))
-> WidgetResult s e -> Maybe (WidgetResult s e)
forall a b. (a -> b) -> a -> b
$ WidgetResult s e
tmpRes
    WidgetResult s e
-> (WidgetResult s e -> WidgetResult s e) -> WidgetResult s e
forall a b. a -> (a -> b) -> b
& (WidgetNode s e -> Identity (WidgetNode s e))
-> WidgetResult s e -> Identity (WidgetResult s e)
forall s a. HasNode s a => Lens' s a
L.node ((WidgetNode s e -> Identity (WidgetNode s e))
 -> WidgetResult s e -> Identity (WidgetResult s e))
-> ((Rect -> Identity Rect)
    -> WidgetNode s e -> Identity (WidgetNode s e))
-> (Rect -> Identity Rect)
-> WidgetResult s e
-> Identity (WidgetResult s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s e -> Identity (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> ((Rect -> Identity Rect)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Rect -> Identity Rect)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect -> Identity Rect)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasViewport s a => Lens' s a
L.viewport ((Rect -> Identity Rect)
 -> WidgetResult s e -> Identity (WidgetResult s e))
-> Rect -> WidgetResult s e -> WidgetResult s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Rect
newVp

  newNode :: WidgetNode s e
newNode = WidgetResult s e
tmpRes WidgetResult s e
-> Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
-> WidgetNode s e
forall s a. s -> Getting a s a -> a
^. Getting (WidgetNode s e) (WidgetResult s e) (WidgetNode s e)
forall s a. HasNode s a => Lens' s a
L.node
  result :: WidgetResult s e
result = Maybe (WidgetResult s e) -> WidgetResult s e
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (WidgetResult s e) -> WidgetResult s e)
-> Maybe (WidgetResult s e) -> WidgetResult s e
forall a b. (a -> b) -> a -> b
$ Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
forall a s e.
WidgetModel a =>
Single s e a
-> WidgetEnv s e
-> WidgetNode s e
-> Maybe SystemEvent
-> Maybe (WidgetResult s e)
-> Maybe (WidgetResult s e)
handleSizeReqChange Single s e a
single WidgetEnv s e
wenv WidgetNode s e
newNode Maybe SystemEvent
forall a. Maybe a
Nothing Maybe (WidgetResult s e)
tmpResult

defaultRender :: SingleRenderHandler s e
defaultRender :: SingleRenderHandler s e
defaultRender WidgetEnv s e
wenv WidgetNode s e
node Renderer
renderer = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

renderWrapper
  :: Single s e a
  -> WidgetEnv s e
  -> WidgetNode s e
  -> Renderer
  -> IO ()
renderWrapper :: Single s e a
-> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
renderWrapper Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node Renderer
renderer =
  Renderer -> Bool -> Rect -> IO () -> IO ()
drawInScissor Renderer
renderer Bool
useScissor Rect
viewport (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    Renderer -> Rect -> StyleState -> (Rect -> IO ()) -> IO ()
drawStyledAction Renderer
renderer Rect
viewport StyleState
style ((Rect -> IO ()) -> IO ()) -> (Rect -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Rect
_ ->
      WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
handler WidgetEnv s e
wenv WidgetNode s e
node Renderer
renderer
  where
    handler :: WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
handler = Single s e a
-> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
forall s e a.
Single s e a
-> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
singleRender Single s e a
single
    useScissor :: Bool
useScissor = Single s e a -> Bool
forall s e a. Single s e a -> Bool
singleUseScissor Single s e a
single
    style :: StyleState
style = Single s e a -> SingleGetCurrentStyle s e
forall s e a. Single s e a -> SingleGetCurrentStyle s e
singleGetCurrentStyle Single s e a
single WidgetEnv s e
wenv WidgetNode s e
node
    viewport :: Rect
viewport = WidgetNode s e
node WidgetNode s e -> Getting Rect (WidgetNode s e) Rect -> Rect
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Rect WidgetNodeInfo)
-> WidgetNode s e -> Const Rect (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Rect WidgetNodeInfo)
 -> WidgetNode s e -> Const Rect (WidgetNode s e))
-> Getting Rect WidgetNodeInfo Rect
-> Getting Rect (WidgetNode s e) Rect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Rect WidgetNodeInfo Rect
forall s a. HasViewport s a => Lens' s a
L.viewport