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

Composite widget. Main glue between all the other widgets, also acts as the main
app widget. Composite allows to split an application into reusable parts 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.
-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Monomer.Widgets.Composite (
  -- * Re-exported modules
  module Monomer.Core,
  module Monomer.Event,
  module Monomer.Widgets.Util,

  -- * Configuration
  CompositeCfg,
  EventResponse(..),
  CompParentModel,
  CompositeModel,
  CompositeEvent,
  MergeRequired,
  MergeReqsHandler,
  EventHandler,
  UIBuilder,
  TaskHandler,
  ProducerHandler,
  CompMsgUpdate,
  compositeMergeReqs,

  -- * Constructors
  composite,
  composite_,
  compositeV,
  compositeV_,
  compositeD_
) where

import Debug.Trace

import Control.Applicative ((<|>))
import Control.Exception (AssertionFailed(..), throw)
import Control.Lens (ALens', (&), (^.), (^?), (.~), (%~), (<>~), at, ix, non)
import Data.Default
import Data.Either
import Data.List (foldl')
import Data.Map.Strict (Map)
import Data.Maybe
import Data.Sequence (Seq(..), (|>), (<|), fromList)
import Data.Typeable (Typeable, cast, typeOf)

import qualified Data.ByteString.Lazy as BSL
import qualified Data.Map.Strict as M
import qualified Data.Sequence as Seq

import Monomer.Core
import Monomer.Core.Combinators
import Monomer.Event
import Monomer.Graphics.Types
import Monomer.Helper
import Monomer.Widgets.Singles.Spacer
import Monomer.Widgets.Util

import qualified Monomer.Core.Lens as L

-- | Type of the parent's model
type CompParentModel sp = Typeable sp
-- | Type of the composite's model
type CompositeModel s = (Eq s, WidgetModel s)
-- | Type of the composite's event
type CompositeEvent e = WidgetEvent e

-- | Checks if merging the composite is required.
type MergeRequired s = s -> s -> Bool

-- | Generates requests during the merge process.
type MergeReqsHandler s e
  = WidgetEnv s e
  -> WidgetNode s e
  -> WidgetNode s e
  -> s
  -> [WidgetRequest s e]

-- | Handles a composite event and returns a set of responses.
type EventHandler s e sp ep
  = WidgetEnv s e
  -> WidgetNode s e
  -> s
  -> e
  -> [EventResponse s e sp ep]

-- | Creates the widget tree based on the given model.
type UIBuilder s e = WidgetEnv s e -> s -> WidgetNode s e

-- | Asynchronous task generating a single event.
type TaskHandler e = IO e

-- | Asynchronous task generating multiple events.
type ProducerHandler e = (e -> IO ()) -> IO ()

-- | Model update function wrapped as a message.
data CompMsgUpdate
  = forall s . CompositeModel s => CompMsgUpdate (s -> s)

-- | Response options for an event handler.
data EventResponse s e sp ep
  -- | Modifies the current model, prompting a merge.
  = Model s
  -- | Raises a new event, which will be handled in the same cycle.
  | Event e
  -- | Raises an event that will be handled by the parent.
  | Report ep
  -- | Generates a 'WidgetRequest'.
  | Request (WidgetRequest s e)
  {-|
  Generates a 'WidgetRequest' matching the parent's types. Useful when receiving
  requests as configuration from the parent, since the types will not match
  otherwise.
  -}
  | RequestParent (WidgetRequest sp ep)
  {-|
  Sends a message to the given key. If the key does not exist, the message will
  not be delivered.
  -}
  | forall i . Typeable i => Message WidgetKey i
  {-|
  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.
  -}
  | Task (TaskHandler 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.
  -}
  | Producer (ProducerHandler e)

{-|
Configuration options for composite:

- '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 'Monomer.Widgets.Containers.Confirm' to set the focus on its Accept
  button when visibility is restored (usually means it was brought to the front
  in a zstack).
-}
data CompositeCfg s e sp ep = CompositeCfg {
  CompositeCfg s e sp ep -> Maybe (MergeRequired s)
_cmcMergeRequired :: Maybe (MergeRequired s),
  CompositeCfg s e sp ep -> [MergeReqsHandler s e]
_cmcMergeReqs :: [MergeReqsHandler s e],
  CompositeCfg s e sp ep -> [e]
_cmcOnInit :: [e],
  CompositeCfg s e sp ep -> [e]
_cmcOnDispose :: [e],
  CompositeCfg s e sp ep -> [Rect -> e]
_cmcOnResize :: [Rect -> e],
  CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
_cmcOnChangeReq :: [s -> WidgetRequest sp ep],
  CompositeCfg s e sp ep -> [e]
_cmcOnEnabledChange :: [e],
  CompositeCfg s e sp ep -> [e]
_cmcOnVisibleChange :: [e]
}

instance Default (CompositeCfg s e sp ep) where
  def :: CompositeCfg s e sp ep
def = CompositeCfg :: forall s e sp ep.
Maybe (MergeRequired s)
-> [MergeReqsHandler s e]
-> [e]
-> [e]
-> [Rect -> e]
-> [s -> WidgetRequest sp ep]
-> [e]
-> [e]
-> CompositeCfg s e sp ep
CompositeCfg {
    _cmcMergeRequired :: Maybe (MergeRequired s)
_cmcMergeRequired = Maybe (MergeRequired s)
forall a. Maybe a
Nothing,
    _cmcMergeReqs :: [MergeReqsHandler s e]
_cmcMergeReqs = [],
    _cmcOnInit :: [e]
_cmcOnInit = [],
    _cmcOnDispose :: [e]
_cmcOnDispose = [],
    _cmcOnResize :: [Rect -> e]
_cmcOnResize = [],
    _cmcOnChangeReq :: [s -> WidgetRequest sp ep]
_cmcOnChangeReq = [],
    _cmcOnEnabledChange :: [e]
_cmcOnEnabledChange = [],
    _cmcOnVisibleChange :: [e]
_cmcOnVisibleChange = []
  }

instance Semigroup (CompositeCfg s e sp ep) where
  <> :: CompositeCfg s e sp ep
-> CompositeCfg s e sp ep -> CompositeCfg s e sp ep
(<>) CompositeCfg s e sp ep
c1 CompositeCfg s e sp ep
c2 = CompositeCfg :: forall s e sp ep.
Maybe (MergeRequired s)
-> [MergeReqsHandler s e]
-> [e]
-> [e]
-> [Rect -> e]
-> [s -> WidgetRequest sp ep]
-> [e]
-> [e]
-> CompositeCfg s e sp ep
CompositeCfg {
    _cmcMergeRequired :: Maybe (MergeRequired s)
_cmcMergeRequired = CompositeCfg s e sp ep -> Maybe (MergeRequired s)
forall s e sp ep. CompositeCfg s e sp ep -> Maybe (MergeRequired s)
_cmcMergeRequired CompositeCfg s e sp ep
c2 Maybe (MergeRequired s)
-> Maybe (MergeRequired s) -> Maybe (MergeRequired s)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> CompositeCfg s e sp ep -> Maybe (MergeRequired s)
forall s e sp ep. CompositeCfg s e sp ep -> Maybe (MergeRequired s)
_cmcMergeRequired CompositeCfg s e sp ep
c1,
    _cmcMergeReqs :: [MergeReqsHandler s e]
_cmcMergeReqs = CompositeCfg s e sp ep -> [MergeReqsHandler s e]
forall s e sp ep. CompositeCfg s e sp ep -> [MergeReqsHandler s e]
_cmcMergeReqs CompositeCfg s e sp ep
c1 [MergeReqsHandler s e]
-> [MergeReqsHandler s e] -> [MergeReqsHandler s e]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [MergeReqsHandler s e]
forall s e sp ep. CompositeCfg s e sp ep -> [MergeReqsHandler s e]
_cmcMergeReqs CompositeCfg s e sp ep
c2,
    _cmcOnInit :: [e]
_cmcOnInit = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnInit CompositeCfg s e sp ep
c1 [e] -> [e] -> [e]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnInit CompositeCfg s e sp ep
c2,
    _cmcOnDispose :: [e]
_cmcOnDispose = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnDispose CompositeCfg s e sp ep
c1 [e] -> [e] -> [e]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnDispose CompositeCfg s e sp ep
c2,
    _cmcOnResize :: [Rect -> e]
_cmcOnResize = CompositeCfg s e sp ep -> [Rect -> e]
forall s e sp ep. CompositeCfg s e sp ep -> [Rect -> e]
_cmcOnResize CompositeCfg s e sp ep
c1 [Rect -> e] -> [Rect -> e] -> [Rect -> e]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [Rect -> e]
forall s e sp ep. CompositeCfg s e sp ep -> [Rect -> e]
_cmcOnResize CompositeCfg s e sp ep
c2,
    _cmcOnChangeReq :: [s -> WidgetRequest sp ep]
_cmcOnChangeReq = CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
forall s e sp ep.
CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
_cmcOnChangeReq CompositeCfg s e sp ep
c1 [s -> WidgetRequest sp ep]
-> [s -> WidgetRequest sp ep] -> [s -> WidgetRequest sp ep]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
forall s e sp ep.
CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
_cmcOnChangeReq CompositeCfg s e sp ep
c2,
    _cmcOnEnabledChange :: [e]
_cmcOnEnabledChange = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnEnabledChange CompositeCfg s e sp ep
c1 [e] -> [e] -> [e]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnEnabledChange CompositeCfg s e sp ep
c2,
    _cmcOnVisibleChange :: [e]
_cmcOnVisibleChange = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnVisibleChange CompositeCfg s e sp ep
c1 [e] -> [e] -> [e]
forall a. Semigroup a => a -> a -> a
<> CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnVisibleChange CompositeCfg s e sp ep
c2
  }

instance Monoid (CompositeCfg s e sp ep) where
  mempty :: CompositeCfg s e sp ep
mempty = CompositeCfg s e sp ep
forall a. Default a => a
def

instance CmbMergeRequired (CompositeCfg s e sp ep) s where
  mergeRequired :: (s -> s -> Bool) -> CompositeCfg s e sp ep
mergeRequired s -> s -> Bool
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
    _cmcMergeRequired :: Maybe (s -> s -> Bool)
_cmcMergeRequired = (s -> s -> Bool) -> Maybe (s -> s -> Bool)
forall a. a -> Maybe a
Just s -> s -> Bool
fn
  }

instance CmbOnInit (CompositeCfg s e sp ep) e where
  onInit :: e -> CompositeCfg s e sp ep
onInit e
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
    _cmcOnInit :: [e]
_cmcOnInit = [e
fn]
  }

instance CmbOnDispose (CompositeCfg s e sp ep) e where
  onDispose :: e -> CompositeCfg s e sp ep
onDispose e
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
    _cmcOnDispose :: [e]
_cmcOnDispose = [e
fn]
  }

instance CmbOnResize (CompositeCfg s e sp ep) e Rect where
  onResize :: (Rect -> e) -> CompositeCfg s e sp ep
onResize Rect -> e
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
    _cmcOnResize :: [Rect -> e]
_cmcOnResize = [Rect -> e
fn]
  }

instance WidgetEvent ep => CmbOnChange (CompositeCfg s e sp ep) s ep where
  onChange :: (s -> ep) -> CompositeCfg s e sp ep
onChange s -> ep
fn = CompositeCfg s e Any Any
forall a. Default a => a
def {
    _cmcOnChangeReq :: [s -> WidgetRequest sp ep]
_cmcOnChangeReq = [ep -> WidgetRequest sp ep
forall s e. WidgetEvent e => e -> WidgetRequest s e
RaiseEvent (ep -> WidgetRequest sp ep)
-> (s -> ep) -> s -> WidgetRequest sp ep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> ep
fn]
  }

instance CmbOnChangeReq (CompositeCfg s e sp ep) sp ep s where
  onChangeReq :: (s -> WidgetRequest sp ep) -> CompositeCfg s e sp ep
onChangeReq s -> WidgetRequest sp ep
req = CompositeCfg s e Any Any
forall a. Default a => a
def {
    _cmcOnChangeReq :: [s -> WidgetRequest sp ep]
_cmcOnChangeReq = [s -> WidgetRequest sp ep
req]
  }

instance CmbOnEnabledChange (CompositeCfg s e sp ep) e where
  onEnabledChange :: e -> CompositeCfg s e sp ep
onEnabledChange e
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
    _cmcOnEnabledChange :: [e]
_cmcOnEnabledChange = [e
fn]
  }

instance CmbOnVisibleChange (CompositeCfg s e sp ep) e where
  onVisibleChange :: e -> CompositeCfg s e sp ep
onVisibleChange e
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
    _cmcOnVisibleChange :: [e]
_cmcOnVisibleChange = [e
fn]
  }

-- | Generate WidgetRequests during the merge process.
compositeMergeReqs :: MergeReqsHandler s e -> CompositeCfg s e sp ep
compositeMergeReqs :: MergeReqsHandler s e -> CompositeCfg s e sp ep
compositeMergeReqs MergeReqsHandler s e
fn = CompositeCfg s e sp ep
forall a. Default a => a
def {
  _cmcMergeReqs :: [MergeReqsHandler s e]
_cmcMergeReqs = [MergeReqsHandler s e
fn]
}

data Composite s e sp ep = Composite {
  Composite s e sp ep -> WidgetData sp s
_cmpWidgetData :: WidgetData sp s,
  Composite s e sp ep -> EventHandler s e sp ep
_cmpEventHandler :: EventHandler s e sp ep,
  Composite s e sp ep -> UIBuilder s e
_cmpUiBuilder :: UIBuilder s e,
  Composite s e sp ep -> MergeRequired s
_cmpMergeRequired :: MergeRequired s,
  Composite s e sp ep -> [MergeReqsHandler s e]
_cmpMergeReqs :: [MergeReqsHandler s e],
  Composite s e sp ep -> [e]
_cmpOnInit :: [e],
  Composite s e sp ep -> [e]
_cmpOnDispose :: [e],
  Composite s e sp ep -> [Rect -> e]
_cmpOnResize :: [Rect -> e],
  Composite s e sp ep -> [s -> WidgetRequest sp ep]
_cmpOnChangeReq :: [s -> WidgetRequest sp ep],
  Composite s e sp ep -> [e]
_cmpOnEnabledChange :: [e],
  Composite s e sp ep -> [e]
_cmpOnVisibleChange :: [e]
}

data CompositeState s e = CompositeState {
  CompositeState s e -> Maybe s
_cpsModel :: Maybe s,
  CompositeState s e -> WidgetNode s e
_cpsRoot :: WidgetNode s e,
  CompositeState s e -> WidgetKeyMap s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
}

data ReducedEvents s e sp ep = ReducedEvents {
  ReducedEvents s e sp ep -> s
_reModel :: s,
  ReducedEvents s e sp ep -> Seq e
_reEvents :: Seq e,
  ReducedEvents s e sp ep -> Seq ep
_reReports :: Seq ep,
  ReducedEvents s e sp ep -> Seq (WidgetRequest s e)
_reRequests :: Seq (WidgetRequest s e),
  ReducedEvents s e sp ep -> Seq (WidgetRequest sp ep)
_reMessages :: Seq (WidgetRequest sp ep),
  ReducedEvents s e sp ep -> Seq (TaskHandler e)
_reTasks :: Seq (TaskHandler e),
  ReducedEvents s e sp ep -> Seq (ProducerHandler e)
_reProducers :: Seq (ProducerHandler e)
}

{-|
Creates a composite taking its model from a lens into the parent model.
-}
composite
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel 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.
composite :: WidgetType
-> ALens' sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> WidgetNode sp ep
composite WidgetType
widgetType ALens' sp s
field UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler = WidgetNode sp ep
newNode where
  newNode :: WidgetNode sp ep
newNode = WidgetType
-> ALens' sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
WidgetType
-> ALens' sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
composite_ WidgetType
widgetType ALens' sp s
field UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
forall a. Default a => a
def

{-|
Creates a composite taking its model from a lens into the parent model. Accepts
config.
-}
composite_
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel 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.
composite_ :: WidgetType
-> ALens' sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
composite_ WidgetType
widgetType ALens' sp s
field UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
cfgs = WidgetNode sp ep
newNode where
  widgetData :: WidgetData sp s
widgetData = ALens' sp s -> WidgetData sp s
forall s a. ALens' s a -> WidgetData s a
WidgetLens ALens' sp s
field
  newNode :: WidgetNode sp ep
newNode = WidgetType
-> WidgetData sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
WidgetType
-> WidgetData sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
compositeD_ WidgetType
widgetType WidgetData sp s
widgetData UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
cfgs

-- | Creates a composite using the given model and onChange event handler.
compositeV
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel 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.
compositeV :: WidgetType
-> s
-> (s -> ep)
-> UIBuilder s e
-> EventHandler s e sp ep
-> WidgetNode sp ep
compositeV WidgetType
wType s
val s -> ep
handler UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler = WidgetNode sp ep
newNode where
  newNode :: WidgetNode sp ep
newNode = WidgetType
-> s
-> (s -> ep)
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
WidgetType
-> s
-> (s -> ep)
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
compositeV_ WidgetType
wType s
val s -> ep
handler UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
forall a. Default a => a
def

{-|
Creates a composite using the given model and onChange event handler. Accepts
config.
-}
compositeV_
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel 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.
compositeV_ :: WidgetType
-> s
-> (s -> ep)
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
compositeV_ WidgetType
wType s
val s -> ep
handler UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
cfgs = WidgetNode sp ep
newNode where
  widgetData :: WidgetData s s
widgetData = s -> WidgetData s s
forall s a. a -> WidgetData s a
WidgetValue s
val
  newCfgs :: [CompositeCfg s e sp ep]
newCfgs = (s -> ep) -> CompositeCfg s e sp ep
forall t a e. CmbOnChange t a e => (a -> e) -> t
onChange s -> ep
handler CompositeCfg s e sp ep
-> [CompositeCfg s e sp ep] -> [CompositeCfg s e sp ep]
forall a. a -> [a] -> [a]
: [CompositeCfg s e sp ep]
cfgs
  newNode :: WidgetNode sp ep
newNode = WidgetType
-> WidgetData sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
WidgetType
-> WidgetData sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
compositeD_ WidgetType
wType WidgetData sp s
forall s. WidgetData s s
widgetData UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
newCfgs

-- | Creates a composite providing a WidgetData instance and config.
compositeD_
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel 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.
compositeD_ :: WidgetType
-> WidgetData sp s
-> UIBuilder s e
-> EventHandler s e sp ep
-> [CompositeCfg s e sp ep]
-> WidgetNode sp ep
compositeD_ WidgetType
wType WidgetData sp s
wData UIBuilder s e
uiBuilder EventHandler s e sp ep
evtHandler [CompositeCfg s e sp ep]
configs = WidgetNode sp ep
newNode where
  config :: CompositeCfg s e sp ep
config = [CompositeCfg s e sp ep] -> CompositeCfg s e sp ep
forall a. Monoid a => [a] -> a
mconcat [CompositeCfg s e sp ep]
configs
  mergeReq :: s -> s -> Bool
mergeReq = (s -> s -> Bool) -> Maybe (s -> s -> Bool) -> s -> s -> Bool
forall a. a -> Maybe a -> a
fromMaybe s -> s -> Bool
forall a. Eq a => a -> a -> Bool
(/=) (CompositeCfg s e sp ep -> Maybe (s -> s -> Bool)
forall s e sp ep. CompositeCfg s e sp ep -> Maybe (MergeRequired s)
_cmcMergeRequired CompositeCfg s e sp ep
config)
  widgetRoot :: WidgetNode s e
widgetRoot = WidgetNode s e
forall s e. WidgetNode s e
spacer
  composite :: Composite s e sp ep
composite = Composite :: forall s e sp ep.
WidgetData sp s
-> EventHandler s e sp ep
-> UIBuilder s e
-> MergeRequired s
-> [MergeReqsHandler s e]
-> [e]
-> [e]
-> [Rect -> e]
-> [s -> WidgetRequest sp ep]
-> [e]
-> [e]
-> Composite s e sp ep
Composite {
    _cmpWidgetData :: WidgetData sp s
_cmpWidgetData = WidgetData sp s
wData,
    _cmpEventHandler :: EventHandler s e sp ep
_cmpEventHandler = EventHandler s e sp ep
evtHandler,
    _cmpUiBuilder :: UIBuilder s e
_cmpUiBuilder = UIBuilder s e
uiBuilder,
    _cmpMergeRequired :: s -> s -> Bool
_cmpMergeRequired = s -> s -> Bool
mergeReq,
    _cmpMergeReqs :: [MergeReqsHandler s e]
_cmpMergeReqs = CompositeCfg s e sp ep -> [MergeReqsHandler s e]
forall s e sp ep. CompositeCfg s e sp ep -> [MergeReqsHandler s e]
_cmcMergeReqs CompositeCfg s e sp ep
config,
    _cmpOnInit :: [e]
_cmpOnInit = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnInit CompositeCfg s e sp ep
config,
    _cmpOnDispose :: [e]
_cmpOnDispose = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnDispose CompositeCfg s e sp ep
config,
    _cmpOnResize :: [Rect -> e]
_cmpOnResize = CompositeCfg s e sp ep -> [Rect -> e]
forall s e sp ep. CompositeCfg s e sp ep -> [Rect -> e]
_cmcOnResize CompositeCfg s e sp ep
config,
    _cmpOnChangeReq :: [s -> WidgetRequest sp ep]
_cmpOnChangeReq = CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
forall s e sp ep.
CompositeCfg s e sp ep -> [s -> WidgetRequest sp ep]
_cmcOnChangeReq CompositeCfg s e sp ep
config,
    _cmpOnEnabledChange :: [e]
_cmpOnEnabledChange = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnEnabledChange CompositeCfg s e sp ep
config,
    _cmpOnVisibleChange :: [e]
_cmpOnVisibleChange = CompositeCfg s e sp ep -> [e]
forall s e sp ep. CompositeCfg s e sp ep -> [e]
_cmcOnVisibleChange CompositeCfg s e sp ep
config
  }
  state :: CompositeState s e
state = Maybe s -> WidgetNode s e -> WidgetKeyMap s e -> CompositeState s e
forall s e.
Maybe s -> WidgetNode s e -> WidgetKeyMap s e -> CompositeState s e
CompositeState Maybe s
forall a. Maybe a
Nothing WidgetNode s e
forall s e. WidgetNode s e
widgetRoot WidgetKeyMap s e
forall k a. Map k a
M.empty
  widget :: Widget sp ep
widget = Composite s e sp ep -> CompositeState s e -> Widget sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> CompositeState s e -> Widget sp ep
createComposite Composite s e sp ep
composite CompositeState s e
forall s e. CompositeState s e
state
  newNode :: WidgetNode sp ep
newNode = WidgetType -> Widget sp ep -> WidgetNode sp ep
forall s e. WidgetType -> Widget s e -> WidgetNode s e
defaultWidgetNode WidgetType
wType Widget sp ep
widget

createComposite
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> Widget sp ep
createComposite :: Composite s e sp ep -> CompositeState s e -> Widget sp ep
createComposite Composite s e sp ep
comp CompositeState s e
state = Widget sp ep
widget where
  widget :: Widget sp ep
widget = 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 sp ep -> WidgetNode sp ep -> WidgetResult sp ep
widgetInit = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
compositeInit Composite s e sp ep
comp CompositeState s e
state,
    widgetMerge :: WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode sp ep -> WidgetResult sp ep
widgetMerge = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
compositeMerge Composite s e sp ep
comp CompositeState s e
state,
    widgetDispose :: WidgetEnv sp ep -> WidgetNode sp ep -> WidgetResult sp ep
widgetDispose = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
compositeDispose Composite s e sp ep
comp CompositeState s e
state,
    widgetGetState :: WidgetEnv sp ep -> WidgetNode sp ep -> Maybe WidgetState
widgetGetState = CompositeState s e
-> WidgetEnv sp ep -> WidgetNode sp ep -> Maybe WidgetState
forall i s e.
WidgetModel i =>
i -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
makeState CompositeState s e
state,
    widgetGetInstanceTree :: WidgetEnv sp ep -> WidgetNode sp ep -> WidgetInstanceNode
widgetGetInstanceTree = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetInstanceNode
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetInstanceNode
compositeGetInstanceTree Composite s e sp ep
comp CompositeState s e
state,
    widgetFindNextFocus :: WidgetEnv sp ep
-> WidgetNode sp ep
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
widgetFindNextFocus = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
compositeFindNextFocus Composite s e sp ep
comp CompositeState s e
state,
    widgetFindByPoint :: WidgetEnv sp ep
-> WidgetNode sp ep -> Path -> Point -> Maybe WidgetNodeInfo
widgetFindByPoint = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> Point
-> Maybe WidgetNodeInfo
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> Point
-> Maybe WidgetNodeInfo
compositeFindByPoint Composite s e sp ep
comp CompositeState s e
state,
    widgetFindBranchByPath :: WidgetEnv sp ep -> WidgetNode sp ep -> Path -> Seq WidgetNodeInfo
widgetFindBranchByPath = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> Seq WidgetNodeInfo
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> Seq WidgetNodeInfo
compositeFindBranchByPath Composite s e sp ep
comp CompositeState s e
state,
    widgetHandleEvent :: WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> SystemEvent
-> Maybe (WidgetResult sp ep)
widgetHandleEvent = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> SystemEvent
-> Maybe (WidgetResult sp ep)
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> SystemEvent
-> Maybe (WidgetResult sp ep)
compositeHandleEvent Composite s e sp ep
comp CompositeState s e
state,
    widgetHandleMessage :: forall i.
Typeable i =>
WidgetEnv sp ep
-> WidgetNode sp ep -> Path -> i -> Maybe (WidgetResult sp ep)
widgetHandleMessage = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> i
-> Maybe (WidgetResult sp ep)
forall s e ep sp i.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp, Typeable i) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> i
-> Maybe (WidgetResult sp ep)
compositeHandleMessage Composite s e sp ep
comp CompositeState s e
state,
    widgetGetSizeReq :: WidgetEnv sp ep -> WidgetNode sp ep -> (SizeReq, SizeReq)
widgetGetSizeReq = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (SizeReq, SizeReq)
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (SizeReq, SizeReq)
compositeGetSizeReq Composite s e sp ep
comp CompositeState s e
state,
    widgetResize :: WidgetEnv sp ep
-> WidgetNode sp ep -> Rect -> (Path -> Bool) -> WidgetResult sp ep
widgetResize = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Rect
-> (Path -> Bool)
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Rect
-> (Path -> Bool)
-> WidgetResult sp ep
compositeResize Composite s e sp ep
comp CompositeState s e
state,
    widgetRender :: WidgetEnv sp ep -> WidgetNode sp ep -> Renderer -> IO ()
widgetRender = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Renderer
-> IO ()
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Renderer
-> IO ()
compositeRender Composite s e sp ep
comp CompositeState s e
state
  }

-- | Init
compositeInit
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> WidgetResult sp ep
compositeInit :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
compositeInit Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp = WidgetResult sp ep
newResult where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  -- Creates UI using provided function
  builtRoot :: WidgetNode s e
builtRoot = Composite s e sp ep -> UIBuilder s e
forall s e sp ep. Composite s e sp ep -> UIBuilder s e
_cmpUiBuilder Composite s e sp ep
comp WidgetEnv s e
cwenv s
model
  tempRoot :: WidgetNode s e
tempRoot = WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
forall sp ep s e.
WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
cascadeCtx WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp WidgetNode s e
builtRoot

  WidgetResult WidgetNode s e
root Seq (WidgetRequest s e)
reqs = Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
widgetInit (WidgetNode s e
tempRoot 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
cwenv WidgetNode s e
tempRoot
  newEvts :: Seq (WidgetRequest s e)
newEvts = e -> WidgetRequest s e
forall s e. WidgetEvent e => e -> WidgetRequest s e
RaiseEvent (e -> WidgetRequest s e) -> Seq e -> Seq (WidgetRequest s e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [e] -> Seq e
forall a. [a] -> Seq a
Seq.fromList (Composite s e sp ep -> [e]
forall s e sp ep. Composite s e sp ep -> [e]
_cmpOnInit Composite s e sp ep
comp)
  newState :: CompositeState s e
newState = CompositeState s e
state {
    _cpsModel :: Maybe s
_cpsModel = s -> Maybe s
forall a. a -> Maybe a
Just s
model,
    _cpsRoot :: WidgetNode s e
_cpsRoot = WidgetNode s e
root,
    _cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsWidgetKeyMap = WidgetKeyMap s e -> WidgetNode s e -> WidgetKeyMap s e
forall s e.
Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collectWidgetKeys WidgetKeyMap s e
forall k a. Map k a
M.empty WidgetNode s e
root
  }

  getBaseStyle :: p -> p -> Maybe a
getBaseStyle p
wenv p
node = Maybe a
forall a. Maybe a
Nothing
  styledComp :: WidgetNode sp ep
styledComp = GetBaseStyle sp ep
-> WidgetEnv sp ep -> WidgetNode sp ep -> WidgetNode sp ep
forall s e.
GetBaseStyle s e
-> WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
initNodeStyle GetBaseStyle sp ep
forall p p a. p -> p -> Maybe a
getBaseStyle WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp
  tempResult :: WidgetResult s e
tempResult = 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
root (Seq (WidgetRequest s e)
reqs Seq (WidgetRequest s e)
-> Seq (WidgetRequest s e) -> Seq (WidgetRequest s e)
forall a. Semigroup a => a -> a -> a
<> Seq (WidgetRequest s e)
forall s. Seq (WidgetRequest s e)
newEvts)
  newResult :: WidgetResult sp ep
newResult = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
newState WidgetEnv sp ep
wenv WidgetNode sp ep
styledComp WidgetResult s e
tempResult

-- | Merge
compositeMerge
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> WidgetNode sp ep
  -> WidgetResult sp ep
compositeMerge :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
compositeMerge Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
newComp WidgetNode sp ep
oldComp = WidgetResult sp ep
newResult where
  widgetId :: WidgetId
widgetId = WidgetNode sp ep
oldComp WidgetNode sp ep
-> Getting WidgetId (WidgetNode sp ep) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
 -> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep))
-> ((WidgetId -> Const WidgetId WidgetId)
    -> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> Getting WidgetId (WidgetNode sp ep) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Const WidgetId WidgetId)
-> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
  oldState :: Maybe WidgetState
oldState = Widget sp ep
-> WidgetEnv sp ep -> WidgetNode sp ep -> Maybe WidgetState
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> Maybe WidgetState
widgetGetState (WidgetNode sp ep
oldComp WidgetNode sp ep
-> Getting (Widget sp ep) (WidgetNode sp ep) (Widget sp ep)
-> Widget sp ep
forall s a. s -> Getting a s a -> a
^. Getting (Widget sp ep) (WidgetNode sp ep) (Widget sp ep)
forall s a. HasWidget s a => Lens' s a
L.widget) WidgetEnv sp ep
wenv WidgetNode sp ep
oldComp
  validState :: CompositeState s e
validState = CompositeState s e
-> Maybe (CompositeState s e) -> CompositeState s e
forall a. a -> Maybe a -> a
fromMaybe CompositeState s e
state (Maybe WidgetState -> Maybe (CompositeState s e)
forall i. WidgetModel i => Maybe WidgetState -> Maybe i
useState Maybe WidgetState
oldState)
  CompositeState Maybe s
oldModel WidgetNode s e
oldRoot WidgetKeyMap s e
oldWidgetKeys = CompositeState s e
validState
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  -- Creates new UI using provided function
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
oldWidgetKeys s
model
  tempRoot :: WidgetNode s e
tempRoot = WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
forall sp ep s e.
WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
cascadeCtx WidgetEnv sp ep
wenv WidgetNode sp ep
newComp (Composite s e sp ep -> UIBuilder s e
forall s e sp ep. Composite s e sp ep -> UIBuilder s e
_cmpUiBuilder Composite s e sp ep
comp WidgetEnv s e
cwenv s
model)
  tempWidget :: Widget s e
tempWidget = WidgetNode s e
tempRoot 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
  -- Needed in case the user references something outside model when building UI
  -- The same model is provided as old since nothing else is available, but
  -- mergeRequired may be using data from a closure
  modelChanged :: Bool
modelChanged = Composite s e sp ep -> MergeRequired s
forall s e sp ep. Composite s e sp ep -> MergeRequired s
_cmpMergeRequired Composite s e sp ep
comp (Maybe s -> s
forall a. HasCallStack => Maybe a -> a
fromJust Maybe s
oldModel) s
model
  visibleChg :: Bool
visibleChg = WidgetNode sp ep
oldComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= WidgetNode sp ep
newComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible
  enabledChg :: Bool
enabledChg = WidgetNode sp ep
oldComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= WidgetNode sp ep
newComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled
  flagsChanged :: Bool
flagsChanged = Bool
visibleChg Bool -> Bool -> Bool
|| Bool
enabledChg
  themeChanged :: Bool
themeChanged = WidgetEnv sp ep
wenv WidgetEnv sp ep -> Getting Bool (WidgetEnv sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool (WidgetEnv sp ep) Bool
forall s a. HasThemeChanged s a => Lens' s a
L.themeChanged
  mergeRequired :: Bool
mergeRequired
    | Maybe s -> Bool
forall a. Maybe a -> Bool
isJust Maybe s
oldModel = Bool
modelChanged Bool -> Bool -> Bool
|| Bool
flagsChanged Bool -> Bool -> Bool
|| Bool
themeChanged
    | Bool
otherwise = Bool
True
  initRequired :: Bool
initRequired = Bool -> Bool
not (WidgetNode s e -> WidgetNode s e -> Bool
forall s e. WidgetNode s e -> WidgetNode s e -> Bool
nodeMatches WidgetNode s e
tempRoot WidgetNode s e
oldRoot)

  WidgetResult WidgetNode s e
newRoot Seq (WidgetRequest s e)
tmpReqs
    | Bool
initRequired = Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
widgetInit Widget s e
tempWidget WidgetEnv s e
cwenv WidgetNode s e
tempRoot
    | Bool
mergeRequired = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
forall s e.
Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
widgetMerge Widget s e
tempWidget WidgetEnv s e
cwenv WidgetNode s e
tempRoot WidgetNode s e
oldRoot
    | Bool
otherwise = WidgetNode s e -> WidgetResult s e
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode s e
oldRoot
  newState :: CompositeState s e
newState = CompositeState s e
validState {
    _cpsModel :: Maybe s
_cpsModel = s -> Maybe s
forall a. a -> Maybe a
Just s
model,
    _cpsRoot :: WidgetNode s e
_cpsRoot = WidgetNode s e
newRoot,
    _cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsWidgetKeyMap = WidgetKeyMap s e -> WidgetNode s e -> WidgetKeyMap s e
forall s e.
Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collectWidgetKeys WidgetKeyMap s e
forall k a. Map k a
M.empty WidgetNode s e
newRoot
  }
  getBaseStyle :: p -> p -> Maybe a
getBaseStyle p
wenv p
node = Maybe a
forall a. Maybe a
Nothing
  styledComp :: WidgetNode sp ep
styledComp = GetBaseStyle sp ep
-> WidgetEnv sp ep -> WidgetNode sp ep -> WidgetNode sp ep
forall s e.
GetBaseStyle s e
-> WidgetEnv s e -> WidgetNode s e -> WidgetNode s e
initNodeStyle GetBaseStyle sp ep
forall p p a. p -> p -> Maybe a
getBaseStyle WidgetEnv sp ep
wenv WidgetNode sp ep
newComp
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((WidgetId -> Identity WidgetId)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (WidgetId -> Identity WidgetId)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetNode sp ep))
-> WidgetId -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNode sp ep
oldComp WidgetNode sp ep
-> Getting WidgetId (WidgetNode sp ep) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
 -> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep))
-> ((WidgetId -> Const WidgetId WidgetId)
    -> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> Getting WidgetId (WidgetNode sp ep) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Const WidgetId WidgetId)
-> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((Rect -> Identity Rect)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Rect -> Identity Rect)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetNode sp ep))
-> Rect -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNode sp ep
oldComp WidgetNode sp ep -> Getting Rect (WidgetNode sp ep) Rect -> Rect
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Rect WidgetNodeInfo)
-> WidgetNode sp ep -> Const Rect (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Rect WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Rect (WidgetNode sp ep))
-> ((Rect -> Const Rect Rect)
    -> WidgetNodeInfo -> Const Rect WidgetNodeInfo)
-> Getting Rect (WidgetNode sp ep) Rect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect -> Const Rect Rect)
-> WidgetNodeInfo -> Const Rect WidgetNodeInfo
forall s a. HasViewport s a => Lens' s a
L.viewport
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetNode sp ep))
-> SizeReq -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNode sp ep
oldComp WidgetNode sp ep
-> Getting SizeReq (WidgetNode sp ep) SizeReq -> SizeReq
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> WidgetNode sp ep -> Const SizeReq (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
 -> WidgetNode sp ep -> Const SizeReq (WidgetNode sp ep))
-> ((SizeReq -> Const SizeReq SizeReq)
    -> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> Getting SizeReq (WidgetNode sp ep) SizeReq
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Const SizeReq SizeReq)
-> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo
forall s a. HasSizeReqW s a => Lens' s a
L.sizeReqW
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetNode sp ep))
-> SizeReq -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetNode sp ep
oldComp WidgetNode sp ep
-> Getting SizeReq (WidgetNode sp ep) SizeReq -> SizeReq
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> WidgetNode sp ep -> Const SizeReq (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
 -> WidgetNode sp ep -> Const SizeReq (WidgetNode sp ep))
-> ((SizeReq -> Const SizeReq SizeReq)
    -> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> Getting SizeReq (WidgetNode sp ep) SizeReq
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Const SizeReq SizeReq)
-> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo
forall s a. HasSizeReqH s a => Lens' s a
L.sizeReqH

  visibleEvts :: [e]
visibleEvts = if Bool
visibleChg then Composite s e sp ep -> [e]
forall s e sp ep. Composite s e sp ep -> [e]
_cmpOnVisibleChange Composite s e sp ep
comp else []
  enabledEvts :: [e]
enabledEvts = if Bool
enabledChg then Composite s e sp ep -> [e]
forall s e sp ep. Composite s e sp ep -> [e]
_cmpOnEnabledChange Composite s e sp ep
comp else []
  mergeReqsFns :: [MergeReqsHandler s e]
mergeReqsFns = Composite s e sp ep -> [MergeReqsHandler s e]
forall s e sp ep. Composite s e sp ep -> [MergeReqsHandler s e]
_cmpMergeReqs Composite s e sp ep
comp
  mergeReqs :: [WidgetRequest s e]
mergeReqs = (MergeReqsHandler s e -> [WidgetRequest s e])
-> [MergeReqsHandler s e] -> [WidgetRequest s e]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\MergeReqsHandler s e
fn -> MergeReqsHandler s e
fn WidgetEnv s e
cwenv WidgetNode s e
newRoot WidgetNode s e
oldRoot s
model) [MergeReqsHandler s e]
mergeReqsFns
  extraReqs :: Seq (WidgetRequest s ep)
extraReqs = Seq (Maybe (WidgetRequest s ep)) -> Seq (WidgetRequest s ep)
forall a. Seq (Maybe a) -> Seq a
seqCatMaybes (WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest s ep)
forall s sp e ep.
(CompositeModel s, CompParentModel sp) =>
WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest sp ep)
toParentReq WidgetId
widgetId (WidgetRequest s e -> Maybe (WidgetRequest s ep))
-> Seq (WidgetRequest s e) -> Seq (Maybe (WidgetRequest s ep))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [WidgetRequest s e] -> Seq (WidgetRequest s e)
forall a. [a] -> Seq a
Seq.fromList [WidgetRequest s e]
mergeReqs)
  evts :: Seq (WidgetRequest s e)
evts = e -> WidgetRequest s e
forall s e. WidgetEvent e => e -> WidgetRequest s e
RaiseEvent (e -> WidgetRequest s e) -> Seq e -> Seq (WidgetRequest s e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [e] -> Seq e
forall a. [a] -> Seq a
Seq.fromList ([e]
visibleEvts [e] -> [e] -> [e]
forall a. [a] -> [a] -> [a]
++ [e]
enabledEvts)

  tmpResult :: WidgetResult s e
tmpResult = 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
newRoot (Seq (WidgetRequest s e)
tmpReqs Seq (WidgetRequest s e)
-> Seq (WidgetRequest s e) -> Seq (WidgetRequest s e)
forall a. Semigroup a => a -> a -> a
<> Seq (WidgetRequest s e)
forall ep. Seq (WidgetRequest s ep)
extraReqs Seq (WidgetRequest s e)
-> Seq (WidgetRequest s e) -> Seq (WidgetRequest s e)
forall a. Semigroup a => a -> a -> a
<> Seq (WidgetRequest s e)
forall s. Seq (WidgetRequest s e)
evts)
  reducedResult :: WidgetResult sp ep
reducedResult = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
newState WidgetEnv sp ep
wenv WidgetNode sp ep
styledComp WidgetResult s e
tmpResult
  newResult :: WidgetResult sp ep
newResult = WidgetNode sp ep -> WidgetResult sp ep -> WidgetResult sp ep
forall s e. WidgetNode s e -> WidgetResult s e -> WidgetResult s e
handleWidgetIdChange WidgetNode sp ep
oldComp WidgetResult sp ep
reducedResult

-- | Dispose
compositeDispose
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> WidgetResult sp ep
compositeDispose :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult sp ep
compositeDispose Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp = WidgetResult sp ep
result where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  newEvts :: Seq (WidgetRequest s e)
newEvts = e -> WidgetRequest s e
forall s e. WidgetEvent e => e -> WidgetRequest s e
RaiseEvent (e -> WidgetRequest s e) -> Seq e -> Seq (WidgetRequest s e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [e] -> Seq e
forall a. [a] -> Seq a
Seq.fromList (Composite s e sp ep -> [e]
forall s e sp ep. Composite s e sp ep -> [e]
_cmpOnDispose Composite s e sp ep
comp)

  WidgetResult WidgetNode s e
_ Seq (WidgetRequest s e)
reqs = Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetResult s e
widgetDispose Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot
  tempResult :: WidgetResult s e
tempResult = 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
_cpsRoot (Seq (WidgetRequest s e)
reqs Seq (WidgetRequest s e)
-> Seq (WidgetRequest s e) -> Seq (WidgetRequest s e)
forall a. Semigroup a => a -> a -> a
<> Seq (WidgetRequest s e)
forall s. Seq (WidgetRequest s e)
newEvts)
  result :: WidgetResult sp ep
result = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp WidgetResult s e
tempResult

compositeGetInstanceTree
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> WidgetInstanceNode
compositeGetInstanceTree :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetInstanceNode
compositeGetInstanceTree Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
node = WidgetInstanceNode
instTree where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  cInstTree :: WidgetInstanceNode
cInstTree = Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> WidgetInstanceNode
widgetGetInstanceTree Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot
  instTree :: WidgetInstanceNode
instTree = WidgetInstanceNode :: WidgetNodeInfo
-> Maybe WidgetState
-> Seq WidgetInstanceNode
-> WidgetInstanceNode
WidgetInstanceNode {
    _winInfo :: WidgetNodeInfo
_winInfo = WidgetNode sp ep
node WidgetNode sp ep
-> Getting WidgetNodeInfo (WidgetNode sp ep) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode sp ep) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info,
    _winState :: Maybe WidgetState
_winState = WidgetState -> Maybe WidgetState
forall a. a -> Maybe a
Just (CompositeState s e -> WidgetState
forall i. WidgetModel i => i -> WidgetState
WidgetState CompositeState s e
state),
    _winChildren :: Seq WidgetInstanceNode
_winChildren = WidgetInstanceNode -> Seq WidgetInstanceNode
forall a. a -> Seq a
Seq.singleton WidgetInstanceNode
cInstTree
  }

-- | Next focusable
compositeFindNextFocus
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> FocusDirection
  -> Path
  -> Maybe WidgetNodeInfo
compositeFindNextFocus :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
compositeFindNextFocus Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp FocusDirection
dir Path
start = Maybe WidgetNodeInfo
nextFocus where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  nextFocus :: Maybe WidgetNodeInfo
nextFocus = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
forall s e.
Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> FocusDirection
-> Path
-> Maybe WidgetNodeInfo
widgetFindNextFocus Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot FocusDirection
dir Path
start

-- | Find
compositeFindByPoint
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> Path
  -> Point
  -> Maybe WidgetNodeInfo
compositeFindByPoint :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> Point
-> Maybe WidgetNodeInfo
compositeFindByPoint Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp Path
start Point
point
  | WidgetNode sp ep
widgetComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible Bool -> Bool -> Bool
&& Bool
validStep = Maybe WidgetNodeInfo
resultInfo
  | Bool
otherwise = Maybe WidgetNodeInfo
forall a. Maybe a
Nothing
  where
    CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
    widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
    model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
    cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
    next :: Maybe PathStep
next = WidgetNode sp ep -> Path -> Maybe PathStep
forall s e. WidgetNode s e -> Path -> Maybe PathStep
nextTargetStep WidgetNode sp ep
widgetComp Path
start
    validStep :: Bool
validStep = Maybe PathStep -> Bool
forall a. Maybe a -> Bool
isNothing Maybe PathStep
next Bool -> Bool -> Bool
|| Maybe PathStep
next Maybe PathStep -> Maybe PathStep -> Bool
forall a. Eq a => a -> a -> Bool
== PathStep -> Maybe PathStep
forall a. a -> Maybe a
Just PathStep
0
    resultInfo :: Maybe WidgetNodeInfo
resultInfo = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> Point
-> Maybe WidgetNodeInfo
forall s e.
Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> Point
-> Maybe WidgetNodeInfo
widgetFindByPoint Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot Path
start Point
point

compositeFindBranchByPath
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> Path
  -> Seq WidgetNodeInfo
compositeFindBranchByPath :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> Seq WidgetNodeInfo
compositeFindBranchByPath Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp Path
path
  | WidgetNodeInfo
info WidgetNodeInfo -> Getting Path WidgetNodeInfo Path -> Path
forall s a. s -> Getting a s a -> a
^. Getting Path WidgetNodeInfo Path
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
  | Maybe PathStep
nextStep Maybe PathStep -> Maybe PathStep -> Bool
forall a. Eq a => a -> a -> Bool
== PathStep -> Maybe PathStep
forall a. a -> Maybe a
Just PathStep
0 = WidgetNodeInfo
info WidgetNodeInfo -> Seq WidgetNodeInfo -> Seq WidgetNodeInfo
forall a. a -> Seq a -> Seq a
<| Seq WidgetNodeInfo
childrenInst
  | Bool
otherwise = Seq WidgetNodeInfo
forall a. Seq a
Seq.empty
  where
    CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
    model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
    cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
    info :: WidgetNodeInfo
info = WidgetNode sp ep
widgetComp WidgetNode sp ep
-> Getting WidgetNodeInfo (WidgetNode sp ep) WidgetNodeInfo
-> WidgetNodeInfo
forall s a. s -> Getting a s a -> a
^. Getting WidgetNodeInfo (WidgetNode sp ep) WidgetNodeInfo
forall s a. HasInfo s a => Lens' s a
L.info
    nextStep :: Maybe PathStep
nextStep = WidgetNode sp ep -> Path -> Maybe PathStep
forall s e. WidgetNode s e -> Path -> Maybe PathStep
nextTargetStep WidgetNode sp ep
widgetComp Path
path
    child :: WidgetNode s e
child = WidgetNode s e
_cpsRoot
    childrenInst :: Seq WidgetNodeInfo
childrenInst = Widget s e
-> WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo
forall s e.
Widget s e
-> WidgetEnv s e -> WidgetNode s e -> Path -> Seq WidgetNodeInfo
widgetFindBranchByPath (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
cwenv WidgetNode s e
child Path
path

-- | Event handling
compositeHandleEvent
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> Path
  -> SystemEvent
  -> Maybe (WidgetResult sp ep)
compositeHandleEvent :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> SystemEvent
-> Maybe (WidgetResult sp ep)
compositeHandleEvent Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp Path
target SystemEvent
evt = Maybe (WidgetResult sp ep)
result where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  rootEnabled :: Bool
rootEnabled = WidgetNode s e
_cpsRoot 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))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode s e) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled
  compVisible :: Bool
compVisible = WidgetNode sp ep
widgetComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible
  compEnabled :: Bool
compEnabled = WidgetNode sp ep
widgetComp WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled

  processEvent :: WidgetResult s e -> WidgetResult sp ep
processEvent = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp
  evtResult :: Maybe (WidgetResult s e)
evtResult
    | Bool -> Bool
not (Bool
compVisible Bool -> Bool -> Bool
&& Bool
compEnabled) = Maybe (WidgetResult s e)
forall a. Maybe a
Nothing
    | Bool
rootEnabled = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
forall s e.
Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> SystemEvent
-> Maybe (WidgetResult s e)
widgetHandleEvent Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot Path
target SystemEvent
evt
    | Bool
otherwise = Maybe (WidgetResult s e)
forall a. Maybe a
Nothing
  result :: Maybe (WidgetResult sp ep)
result = (WidgetResult s e -> WidgetResult sp ep)
-> Maybe (WidgetResult s e) -> Maybe (WidgetResult sp ep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WidgetResult s e -> WidgetResult sp ep
processEvent Maybe (WidgetResult s e)
evtResult

-- | Message handling
compositeHandleMessage
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp, Typeable i)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> Path
  -> i
  -> Maybe (WidgetResult sp ep)
compositeHandleMessage :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Path
-> i
-> Maybe (WidgetResult sp ep)
compositeHandleMessage Composite s e sp ep
comp state :: CompositeState s e
state@CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp Path
target i
arg
  | WidgetNode sp ep -> Path -> Bool
forall s e. WidgetNode s e -> Path -> Bool
isTargetReached WidgetNode sp ep
widgetComp Path
target = case i -> Maybe e
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast i
arg of
      Just e
evt -> WidgetResult sp ep -> Maybe (WidgetResult sp ep)
forall a. a -> Maybe a
Just (WidgetResult sp ep -> Maybe (WidgetResult sp ep))
-> WidgetResult sp ep -> Maybe (WidgetResult sp ep)
forall a b. (a -> b) -> a -> b
$ Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> e
-> WidgetResult sp ep
handleMsgEvent Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp e
evt
      Maybe e
Nothing -> case i -> Maybe CompMsgUpdate
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast i
arg of
        Just (CompMsgUpdate s -> s
msg) -> Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (s -> s)
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (s -> s)
-> WidgetResult sp ep
handleMsgUpdate Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp ((s -> s) -> WidgetResult sp ep)
-> Maybe (s -> s) -> Maybe (WidgetResult sp ep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (s -> s) -> Maybe (s -> s)
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast s -> s
msg
        Maybe CompMsgUpdate
_ -> ([Char], TypeRep)
-> Maybe (WidgetResult sp ep) -> Maybe (WidgetResult sp ep)
forall a b. Show a => a -> b -> b
traceShow ([Char]
"Failed match on Composite handleEvent", i -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf i
arg) Maybe (WidgetResult sp ep)
forall a. Maybe a
Nothing
  | Bool
otherwise = (WidgetResult s e -> WidgetResult sp ep)
-> Maybe (WidgetResult s e) -> Maybe (WidgetResult sp ep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WidgetResult s e -> WidgetResult sp ep
processEvent Maybe (WidgetResult s e)
result where
      processEvent :: WidgetResult s e -> WidgetResult sp ep
processEvent = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp
      cmpWidget :: Widget s e
cmpWidget = WidgetNode s e
_cpsRoot 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
      model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
      cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
      result :: Maybe (WidgetResult s e)
result = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Path
-> i
-> Maybe (WidgetResult s e)
forall s e.
Widget s e
-> forall i.
   Typeable i =>
   WidgetEnv s e
   -> WidgetNode s e -> Path -> i -> Maybe (WidgetResult s e)
widgetHandleMessage Widget s e
cmpWidget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot Path
target i
arg

-- Preferred size
compositeGetSizeReq
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> (SizeReq, SizeReq)
compositeGetSizeReq :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (SizeReq, SizeReq)
compositeGetSizeReq Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp = (SizeReq
newReqW, SizeReq
newReqH) where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  style :: StyleState
style = WidgetEnv sp ep -> WidgetNode sp ep -> StyleState
forall s e. WidgetEnv s e -> WidgetNode s e -> StyleState
currentStyle WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  currReqW :: SizeReq
currReqW = WidgetNode s e
_cpsRoot WidgetNode s e
-> Getting SizeReq (WidgetNode s e) SizeReq -> SizeReq
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> WidgetNode s e -> Const SizeReq (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
 -> WidgetNode s e -> Const SizeReq (WidgetNode s e))
-> ((SizeReq -> Const SizeReq SizeReq)
    -> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> Getting SizeReq (WidgetNode s e) SizeReq
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Const SizeReq SizeReq)
-> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo
forall s a. HasSizeReqW s a => Lens' s a
L.sizeReqW
  currReqH :: SizeReq
currReqH = WidgetNode s e
_cpsRoot WidgetNode s e
-> Getting SizeReq (WidgetNode s e) SizeReq -> SizeReq
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> WidgetNode s e -> Const SizeReq (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
 -> WidgetNode s e -> Const SizeReq (WidgetNode s e))
-> ((SizeReq -> Const SizeReq SizeReq)
    -> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo)
-> Getting SizeReq (WidgetNode s e) SizeReq
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SizeReq -> Const SizeReq SizeReq)
-> WidgetNodeInfo -> Const SizeReq WidgetNodeInfo
forall s a. HasSizeReqH s a => Lens' s a
L.sizeReqH
  (SizeReq
tmpReqW, SizeReq
tmpReqH) = StyleState -> (SizeReq, SizeReq) -> (SizeReq, SizeReq)
sizeReqAddStyle StyleState
style (SizeReq
currReqW, SizeReq
currReqH)
  -- 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)

-- Preferred size
updateSizeReq
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> WidgetNode sp ep
updateSizeReq :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetNode sp ep
updateSizeReq Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp = WidgetNode sp ep
newComp where
  (SizeReq
newReqW, SizeReq
newReqH) = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (SizeReq, SizeReq)
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (SizeReq, SizeReq)
compositeGetSizeReq Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp
  newComp :: WidgetNode sp ep
newComp = WidgetNode sp ep
widgetComp
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetNode sp ep))
-> SizeReq -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ SizeReq
newReqW
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((SizeReq -> Identity SizeReq)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (SizeReq -> Identity SizeReq)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetNode sp ep))
-> SizeReq -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ SizeReq
newReqH

-- Resize
compositeResize
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> Rect
  -> (Path -> Bool)
  -> WidgetResult sp ep
compositeResize :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Rect
-> (Path -> Bool)
-> WidgetResult sp ep
compositeResize Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp Rect
viewport Path -> Bool
rszReq = WidgetResult sp ep
resizedRes where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  style :: StyleState
style = WidgetEnv sp ep -> WidgetNode sp ep -> StyleState
forall s e. WidgetEnv s e -> WidgetNode s e -> StyleState
currentStyle WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp
  carea :: Rect
carea = Rect -> Maybe Rect -> Rect
forall a. a -> Maybe a -> a
fromMaybe Rect
forall a. Default a => a
def (StyleState -> Rect -> Maybe Rect
removeOuterBounds StyleState
style Rect
viewport)
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model

  WidgetResult WidgetNode s e
newRoot Seq (WidgetRequest s e)
newReqs = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Rect
-> (Path -> Bool)
-> WidgetResult s e
forall s e.
Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> Rect
-> (Path -> Bool)
-> WidgetResult s e
widgetResize Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot Rect
carea Path -> Bool
rszReq
  oldVp :: Rect
oldVp = WidgetNode sp ep
widgetComp WidgetNode sp ep -> Getting Rect (WidgetNode sp ep) Rect -> Rect
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Rect WidgetNodeInfo)
-> WidgetNode sp ep -> Const Rect (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Rect WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Rect (WidgetNode sp ep))
-> ((Rect -> Const Rect Rect)
    -> WidgetNodeInfo -> Const Rect WidgetNodeInfo)
-> Getting Rect (WidgetNode sp ep) Rect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect -> Const Rect Rect)
-> WidgetNodeInfo -> Const Rect WidgetNodeInfo
forall s a. HasViewport s a => Lens' s a
L.viewport
  sizeChanged :: Bool
sizeChanged = Rect
viewport Rect -> Rect -> Bool
forall a. Eq a => a -> a -> Bool
/= Rect
oldVp
  resizeEvts :: [e]
resizeEvts = ((Rect -> e) -> e) -> [Rect -> e] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Rect -> e) -> Rect -> e
forall a b. (a -> b) -> a -> b
$ Rect
viewport) (Composite s e sp ep -> [Rect -> e]
forall s e sp ep. Composite s e sp ep -> [Rect -> e]
_cmpOnResize Composite s e sp ep
comp)
  resizeReqs :: Seq (WidgetRequest s e)
resizeReqs
    | Bool
sizeChanged = e -> WidgetRequest s e
forall s e. WidgetEvent e => e -> WidgetRequest s e
RaiseEvent (e -> WidgetRequest s e) -> Seq e -> Seq (WidgetRequest s e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [e] -> Seq e
forall a. [a] -> Seq a
Seq.fromList [e]
resizeEvts
    | Bool
otherwise = Seq (WidgetRequest s e)
forall a. Seq a
Empty

  childRes :: WidgetResult s e
childRes = 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
newRoot (Seq (WidgetRequest s e)
newReqs Seq (WidgetRequest s e)
-> Seq (WidgetRequest s e) -> Seq (WidgetRequest s e)
forall a. Semigroup a => a -> a -> a
<> Seq (WidgetRequest s e)
forall s. Seq (WidgetRequest s e)
resizeReqs)
    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
carea
  resizedRes :: WidgetResult sp ep
resizedRes = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp WidgetResult s e
childRes
    WidgetResult sp ep
-> (WidgetResult sp ep -> WidgetResult sp ep) -> WidgetResult sp ep
forall a b. a -> (a -> b) -> b
& (WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> WidgetResult sp ep -> Identity (WidgetResult sp ep)
forall s a. HasNode s a => Lens' s a
L.node ((WidgetNode sp ep -> Identity (WidgetNode sp ep))
 -> WidgetResult sp ep -> Identity (WidgetResult sp ep))
-> ((Rect -> Identity Rect)
    -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> (Rect -> Identity Rect)
-> WidgetResult sp ep
-> Identity (WidgetResult sp ep)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> ((Rect -> Identity Rect)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Rect -> Identity Rect)
-> WidgetNode sp ep
-> Identity (WidgetNode sp ep)
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 sp ep -> Identity (WidgetResult sp ep))
-> Rect -> WidgetResult sp ep -> WidgetResult sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Rect
viewport

-- Render
compositeRender
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> Renderer
  -> IO ()
compositeRender :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> Renderer
-> IO ()
compositeRender Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp Renderer
renderer = IO ()
action where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  widget :: Widget s e
widget = WidgetNode s e
_cpsRoot 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
  model :: s
model = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  action :: IO ()
action = Widget s e -> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
forall s e.
Widget s e -> WidgetEnv s e -> WidgetNode s e -> Renderer -> IO ()
widgetRender Widget s e
widget WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot Renderer
renderer

handleMsgEvent
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> e
  -> WidgetResult sp ep
handleMsgEvent :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> e
-> WidgetResult sp ep
handleMsgEvent Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp e
event = WidgetResult sp ep
newResult where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  model :: s
model
    | Maybe s -> Bool
forall a. Maybe a -> Bool
isJust Maybe s
_cpsModel = Maybe s -> s
forall a. HasCallStack => Maybe a -> a
fromJust Maybe s
_cpsModel
    | Bool
otherwise = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  evtHandler :: EventHandler s e sp ep
evtHandler = Composite s e sp ep -> EventHandler s e sp ep
forall s e sp ep. Composite s e sp ep -> EventHandler s e sp ep
_cmpEventHandler Composite s e sp ep
comp
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
model
  response :: [EventResponse s e sp ep]
response = EventHandler s e sp ep
evtHandler WidgetEnv s e
cwenv WidgetNode s e
_cpsRoot s
model e
event
  newReqs :: [Maybe (WidgetRequest sp ep)]
newReqs = WidgetNode sp ep
-> WidgetKeyMap s e
-> EventResponse s e sp ep
-> Maybe (WidgetRequest sp ep)
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
WidgetNode sp ep
-> WidgetKeyMap s e
-> EventResponse s e sp ep
-> Maybe (WidgetRequest sp ep)
evtResponseToRequest WidgetNode sp ep
widgetComp WidgetKeyMap s e
_cpsWidgetKeyMap (EventResponse s e sp ep -> Maybe (WidgetRequest sp ep))
-> [EventResponse s e sp ep] -> [Maybe (WidgetRequest sp ep)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [EventResponse s e sp ep]
response
  newResult :: WidgetResult sp ep
newResult = WidgetNode sp ep -> Seq (WidgetRequest sp ep) -> WidgetResult sp ep
forall s e.
WidgetNode s e -> Seq (WidgetRequest s e) -> WidgetResult s e
WidgetResult WidgetNode sp ep
widgetComp ([WidgetRequest sp ep] -> Seq (WidgetRequest sp ep)
forall a. [a] -> Seq a
Seq.fromList ([Maybe (WidgetRequest sp ep)] -> [WidgetRequest sp ep]
forall a. [Maybe a] -> [a]
catMaybes [Maybe (WidgetRequest sp ep)]
newReqs))

handleMsgUpdate
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> (s -> s)
  -> WidgetResult sp ep
handleMsgUpdate :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> (s -> s)
-> WidgetResult sp ep
handleMsgUpdate Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp s -> s
fnUpdate = WidgetResult sp ep
result where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  model :: s
model
    | Maybe s -> Bool
forall a. Maybe a -> Bool
isJust Maybe s
_cpsModel = Maybe s -> s
forall a. HasCallStack => Maybe a -> a
fromJust Maybe s
_cpsModel
    | Bool
otherwise = Composite s e sp ep -> WidgetEnv sp ep -> s
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv
  newModel :: s
newModel = s -> s
fnUpdate s
model
  result :: WidgetResult sp ep
result
    | s
model s -> s -> Bool
forall a. Eq a => a -> a -> Bool
== s
newModel = WidgetNode sp ep -> WidgetResult sp ep
forall s e. WidgetNode s e -> WidgetResult s e
resultNode WidgetNode sp ep
widgetComp
    | Bool
otherwise = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> s
-> WidgetNode s e
-> WidgetNode sp ep
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> s
-> WidgetNode s e
-> WidgetNode sp ep
-> WidgetResult sp ep
mergeChild Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv s
newModel WidgetNode s e
_cpsRoot WidgetNode sp ep
widgetComp

toParentResult
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> WidgetNode sp ep
  -> WidgetResult s e
  -> WidgetResult sp ep
toParentResult :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp WidgetResult s e
result = WidgetResult sp ep
newResult where
  WidgetResult WidgetNode s e
newRoot Seq (WidgetRequest s e)
reqs = WidgetResult s e
result
  widgetId :: WidgetId
widgetId = WidgetNode sp ep
widgetComp WidgetNode sp ep
-> Getting WidgetId (WidgetNode sp ep) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
 -> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep))
-> ((WidgetId -> Const WidgetId WidgetId)
    -> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> Getting WidgetId (WidgetNode sp ep) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Const WidgetId WidgetId)
-> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
  newState :: CompositeState s e
newState = CompositeState s e
state {
    _cpsRoot :: WidgetNode s e
_cpsRoot = WidgetNode s e
newRoot
  }
  newComp :: WidgetNode sp ep
newComp = WidgetNode sp ep
widgetComp
    WidgetNode sp ep
-> (WidgetNode sp ep -> WidgetNode sp ep) -> WidgetNode sp ep
forall a b. a -> (a -> b) -> b
& (Widget sp ep -> Identity (Widget sp ep))
-> WidgetNode sp ep -> Identity (WidgetNode sp ep)
forall s a. HasWidget s a => Lens' s a
L.widget ((Widget sp ep -> Identity (Widget sp ep))
 -> WidgetNode sp ep -> Identity (WidgetNode sp ep))
-> Widget sp ep -> WidgetNode sp ep -> WidgetNode sp ep
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Composite s e sp ep -> CompositeState s e -> Widget sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep -> CompositeState s e -> Widget sp ep
createComposite Composite s e sp ep
comp CompositeState s e
newState
  newNode :: WidgetNode sp ep
newNode = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetNode sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetNode sp ep
updateSizeReq Composite s e sp ep
comp CompositeState s e
newState WidgetEnv sp ep
wenv WidgetNode sp ep
newComp
  newReqs :: Seq (WidgetRequest sp ep)
newReqs = Seq (Maybe (WidgetRequest sp ep)) -> Seq (WidgetRequest sp ep)
forall a. Seq (Maybe a) -> Seq a
seqCatMaybes (WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest sp ep)
forall s sp e ep.
(CompositeModel s, CompParentModel sp) =>
WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest sp ep)
toParentReq WidgetId
widgetId (WidgetRequest s e -> Maybe (WidgetRequest sp ep))
-> Seq (WidgetRequest s e) -> Seq (Maybe (WidgetRequest sp ep))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Seq (WidgetRequest s e)
reqs)
  newResult :: WidgetResult sp ep
newResult = WidgetNode sp ep -> Seq (WidgetRequest sp ep) -> WidgetResult sp ep
forall s e.
WidgetNode s e -> Seq (WidgetRequest s e) -> WidgetResult s e
WidgetResult WidgetNode sp ep
newNode Seq (WidgetRequest sp ep)
forall ep. Seq (WidgetRequest sp ep)
newReqs

evtResponseToRequest
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => WidgetNode sp ep
  -> WidgetKeyMap s e
  -> EventResponse s e sp ep
  -> Maybe (WidgetRequest sp ep)
evtResponseToRequest :: WidgetNode sp ep
-> WidgetKeyMap s e
-> EventResponse s e sp ep
-> Maybe (WidgetRequest sp ep)
evtResponseToRequest WidgetNode sp ep
widgetComp WidgetKeyMap s e
widgetKeys EventResponse s e sp ep
response = case EventResponse s e sp ep
response of
  Model s
newModel -> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetRequest sp ep -> Maybe (WidgetRequest sp ep))
-> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a b. (a -> b) -> a -> b
$ WidgetNode sp ep -> CompMsgUpdate -> WidgetRequest sp ep
forall i s a s e.
(Typeable i, HasInfo s a, HasWidgetId a WidgetId) =>
s -> i -> WidgetRequest s e
sendTo WidgetNode sp ep
widgetComp ((s -> s) -> CompMsgUpdate
forall s. CompositeModel s => (s -> s) -> CompMsgUpdate
CompMsgUpdate ((s -> s) -> CompMsgUpdate) -> (s -> s) -> CompMsgUpdate
forall a b. (a -> b) -> a -> b
$ s -> s -> s
forall a b. a -> b -> a
const s
newModel)
  Event e
event -> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetRequest sp ep -> Maybe (WidgetRequest sp ep))
-> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a b. (a -> b) -> a -> b
$ WidgetNode sp ep -> e -> WidgetRequest sp ep
forall i s a s e.
(Typeable i, HasInfo s a, HasWidgetId a WidgetId) =>
s -> i -> WidgetRequest s e
sendTo WidgetNode sp ep
widgetComp e
event
  Report ep
report -> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (ep -> WidgetRequest sp ep
forall s e. WidgetEvent e => e -> WidgetRequest s e
RaiseEvent ep
report)
  Request WidgetRequest s e
req -> WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest sp ep)
forall s sp e ep.
(CompositeModel s, CompParentModel sp) =>
WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest sp ep)
toParentReq WidgetId
widgetId WidgetRequest s e
req
  RequestParent WidgetRequest sp ep
req -> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just WidgetRequest sp ep
req
  Message WidgetKey
key i
msg -> (WidgetNode s e -> i -> WidgetRequest sp ep
forall i s a s e.
(Typeable i, HasInfo s a, HasWidgetId a WidgetId) =>
s -> i -> WidgetRequest s e
`sendTo` i
msg) (WidgetNode s e -> WidgetRequest sp ep)
-> Maybe (WidgetNode s e) -> Maybe (WidgetRequest sp ep)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WidgetKey -> WidgetKeyMap s e -> Maybe (WidgetNode s e)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup WidgetKey
key WidgetKeyMap s e
widgetKeys
  Task TaskHandler e
task -> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetRequest sp ep -> Maybe (WidgetRequest sp ep))
-> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a b. (a -> b) -> a -> b
$ WidgetId -> Path -> TaskHandler e -> WidgetRequest sp ep
forall s e i.
Typeable i =>
WidgetId -> Path -> IO i -> WidgetRequest s e
RunTask WidgetId
widgetId Path
path TaskHandler e
task
  Producer ProducerHandler e
producer -> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetRequest sp ep -> Maybe (WidgetRequest sp ep))
-> WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a b. (a -> b) -> a -> b
$ WidgetId -> Path -> ProducerHandler e -> WidgetRequest sp ep
forall s e i.
Typeable i =>
WidgetId -> Path -> ((i -> IO ()) -> IO ()) -> WidgetRequest s e
RunProducer WidgetId
widgetId Path
path ProducerHandler e
producer
  where
    sendTo :: s -> i -> WidgetRequest s e
sendTo s
node i
msg = WidgetId -> i -> WidgetRequest s e
forall s e i. Typeable i => WidgetId -> i -> WidgetRequest s e
SendMessage (s
node s -> Getting WidgetId s WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (a -> Const WidgetId a) -> s -> Const WidgetId s
forall s a. HasInfo s a => Lens' s a
L.info ((a -> Const WidgetId a) -> s -> Const WidgetId s)
-> ((WidgetId -> Const WidgetId WidgetId) -> a -> Const WidgetId a)
-> Getting WidgetId s WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Const WidgetId WidgetId) -> a -> Const WidgetId a
forall s a. HasWidgetId s a => Lens' s a
L.widgetId) i
msg
    widgetId :: WidgetId
widgetId = WidgetNode sp ep
widgetComp WidgetNode sp ep
-> Getting WidgetId (WidgetNode sp ep) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
 -> WidgetNode sp ep -> Const WidgetId (WidgetNode sp ep))
-> ((WidgetId -> Const WidgetId WidgetId)
    -> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> Getting WidgetId (WidgetNode sp ep) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Const WidgetId WidgetId)
-> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
    path :: Path
path = WidgetNode sp ep
widgetComp WidgetNode sp ep -> Getting Path (WidgetNode sp ep) Path -> Path
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Path WidgetNodeInfo)
-> WidgetNode sp ep -> Const Path (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Path WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Path (WidgetNode sp ep))
-> Getting Path WidgetNodeInfo Path
-> Getting Path (WidgetNode sp ep) Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Path WidgetNodeInfo Path
forall s a. HasPath s a => Lens' s a
L.path

mergeChild
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> CompositeState s e
  -> WidgetEnv sp ep
  -> s
  -> WidgetNode s e
  -> WidgetNode sp ep
  -> WidgetResult sp ep
mergeChild :: Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> s
-> WidgetNode s e
-> WidgetNode sp ep
-> WidgetResult sp ep
mergeChild Composite s e sp ep
comp CompositeState s e
state WidgetEnv sp ep
wenv s
newModel WidgetNode s e
widgetRoot WidgetNode sp ep
widgetComp = WidgetResult sp ep
newResult where
  CompositeState{Maybe s
WidgetKeyMap s e
WidgetNode s e
_cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsRoot :: WidgetNode s e
_cpsModel :: Maybe s
_cpsWidgetKeyMap :: forall s e. CompositeState s e -> WidgetKeyMap s e
_cpsRoot :: forall s e. CompositeState s e -> WidgetNode s e
_cpsModel :: forall s e. CompositeState s e -> Maybe s
..} = CompositeState s e
state
  cwenv :: WidgetEnv s e
cwenv = WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
forall sp ep s e.
WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
_cpsWidgetKeyMap s
newModel
  builtRoot :: WidgetNode s e
builtRoot = WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
forall sp ep s e.
WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
cascadeCtx WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp (Composite s e sp ep -> UIBuilder s e
forall s e sp ep. Composite s e sp ep -> UIBuilder s e
_cmpUiBuilder Composite s e sp ep
comp WidgetEnv s e
cwenv s
newModel)
      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
.~ WidgetNode s e
_cpsRoot 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))
-> ((WidgetId -> Const WidgetId WidgetId)
    -> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> Getting WidgetId (WidgetNode s e) WidgetId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WidgetId -> Const WidgetId WidgetId)
-> WidgetNodeInfo -> Const WidgetId WidgetNodeInfo
forall s a. HasWidgetId s a => Lens' s a
L.widgetId
  builtWidget :: Widget s e
builtWidget = WidgetNode s e
builtRoot 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
  mergedResult :: WidgetResult s e
mergedResult = Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
forall s e.
Widget s e
-> WidgetEnv s e
-> WidgetNode s e
-> WidgetNode s e
-> WidgetResult s e
widgetMerge Widget s e
builtWidget WidgetEnv s e
cwenv WidgetNode s e
builtRoot WidgetNode s e
widgetRoot
  mergedState :: CompositeState s e
mergedState = CompositeState s e
state {
    _cpsModel :: Maybe s
_cpsModel = s -> Maybe s
forall a. a -> Maybe a
Just s
newModel,
    _cpsRoot :: WidgetNode s e
_cpsRoot = WidgetResult s e
mergedResult 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,
    _cpsWidgetKeyMap :: WidgetKeyMap s e
_cpsWidgetKeyMap = WidgetKeyMap s e -> WidgetNode s e -> WidgetKeyMap s e
forall s e.
Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collectWidgetKeys WidgetKeyMap s e
forall k a. Map k a
M.empty (WidgetResult s e
mergedResult 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 sp ep
result = Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
forall s e ep sp.
(CompositeModel s, CompositeEvent e, CompositeEvent ep,
 CompParentModel sp) =>
Composite s e sp ep
-> CompositeState s e
-> WidgetEnv sp ep
-> WidgetNode sp ep
-> WidgetResult s e
-> WidgetResult sp ep
toParentResult Composite s e sp ep
comp CompositeState s e
mergedState WidgetEnv sp ep
wenv WidgetNode sp ep
widgetComp WidgetResult s e
mergedResult
  newReqs :: [WidgetRequest sp ep]
newReqs = WidgetData sp s -> s -> [WidgetRequest sp ep]
forall s a e. WidgetData s a -> a -> [WidgetRequest s e]
widgetDataSet (Composite s e sp ep -> WidgetData sp s
forall s e sp ep. Composite s e sp ep -> WidgetData sp s
_cmpWidgetData Composite s e sp ep
comp) s
newModel
    [WidgetRequest sp ep]
-> [WidgetRequest sp ep] -> [WidgetRequest sp ep]
forall a. [a] -> [a] -> [a]
++ ((s -> WidgetRequest sp ep) -> WidgetRequest sp ep)
-> [s -> WidgetRequest sp ep] -> [WidgetRequest sp ep]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> WidgetRequest sp ep) -> s -> WidgetRequest sp ep
forall a b. (a -> b) -> a -> b
$ s
newModel) (Composite s e sp ep -> [s -> WidgetRequest sp ep]
forall s e sp ep. Composite s e sp ep -> [s -> WidgetRequest sp ep]
_cmpOnChangeReq Composite s e sp ep
comp)
  newResult :: WidgetResult sp ep
newResult = WidgetResult sp ep
result
    WidgetResult sp ep
-> (WidgetResult sp ep -> WidgetResult sp ep) -> WidgetResult sp ep
forall a b. a -> (a -> b) -> b
& (Seq (WidgetRequest sp ep) -> Identity (Seq (WidgetRequest sp ep)))
-> WidgetResult sp ep -> Identity (WidgetResult sp ep)
forall s a. HasRequests s a => Lens' s a
L.requests ((Seq (WidgetRequest sp ep)
  -> Identity (Seq (WidgetRequest sp ep)))
 -> WidgetResult sp ep -> Identity (WidgetResult sp ep))
-> Seq (WidgetRequest sp ep)
-> WidgetResult sp ep
-> WidgetResult sp ep
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [WidgetRequest sp ep] -> Seq (WidgetRequest sp ep)
forall a. [a] -> Seq a
Seq.fromList [WidgetRequest sp ep]
newReqs

getModel
  :: (CompositeModel s, CompositeEvent e, CompositeEvent ep, CompParentModel sp)
  => Composite s e sp ep
  -> WidgetEnv sp ep
  -> s
getModel :: Composite s e sp ep -> WidgetEnv sp ep -> s
getModel Composite s e sp ep
comp WidgetEnv sp ep
wenv = sp -> WidgetData sp s -> s
forall s a. s -> WidgetData s a -> a
widgetDataGet (WidgetEnv sp ep -> sp
forall s e. WidgetEnv s e -> s
_weModel WidgetEnv sp ep
wenv) (Composite s e sp ep -> WidgetData sp s
forall s e sp ep. Composite s e sp ep -> WidgetData sp s
_cmpWidgetData Composite s e sp ep
comp)

toParentReq
  :: (CompositeModel s, CompParentModel sp)
  => WidgetId
  -> WidgetRequest s e
  -> Maybe (WidgetRequest sp ep)
toParentReq :: WidgetId -> WidgetRequest s e -> Maybe (WidgetRequest sp ep)
toParentReq WidgetId
_ WidgetRequest s e
IgnoreParentEvents = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just WidgetRequest sp ep
forall s e. WidgetRequest s e
IgnoreParentEvents
toParentReq WidgetId
_ WidgetRequest s e
IgnoreChildrenEvents = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just WidgetRequest sp ep
forall s e. WidgetRequest s e
IgnoreChildrenEvents
toParentReq WidgetId
_ (ResizeWidgets WidgetId
wid) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
ResizeWidgets WidgetId
wid)
toParentReq WidgetId
_ (ResizeWidgetsImmediate WidgetId
wid) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
ResizeWidgetsImmediate WidgetId
wid)
toParentReq WidgetId
_ (MoveFocus Maybe WidgetId
start FocusDirection
dir) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (Maybe WidgetId -> FocusDirection -> WidgetRequest sp ep
forall s e. Maybe WidgetId -> FocusDirection -> WidgetRequest s e
MoveFocus Maybe WidgetId
start FocusDirection
dir)
toParentReq WidgetId
_ (SetFocus WidgetId
path) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
SetFocus WidgetId
path)
toParentReq WidgetId
_ (GetClipboard WidgetId
path) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
GetClipboard WidgetId
path)
toParentReq WidgetId
_ (SetClipboard ClipboardData
clipboard) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (ClipboardData -> WidgetRequest sp ep
forall s e. ClipboardData -> WidgetRequest s e
SetClipboard ClipboardData
clipboard)
toParentReq WidgetId
_ (StartTextInput Rect
rect) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (Rect -> WidgetRequest sp ep
forall s e. Rect -> WidgetRequest s e
StartTextInput Rect
rect)
toParentReq WidgetId
_ WidgetRequest s e
StopTextInput = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just WidgetRequest sp ep
forall s e. WidgetRequest s e
StopTextInput
toParentReq WidgetId
_ (ResetOverlay WidgetId
wid) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
ResetOverlay WidgetId
wid)
toParentReq WidgetId
_ (SetOverlay WidgetId
wid Path
path) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> Path -> WidgetRequest sp ep
forall s e. WidgetId -> Path -> WidgetRequest s e
SetOverlay WidgetId
wid Path
path)
toParentReq WidgetId
_ (SetCursorIcon WidgetId
wid CursorIcon
icon) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> CursorIcon -> WidgetRequest sp ep
forall s e. WidgetId -> CursorIcon -> WidgetRequest s e
SetCursorIcon WidgetId
wid CursorIcon
icon)
toParentReq WidgetId
_ (ResetCursorIcon WidgetId
wid) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
ResetCursorIcon WidgetId
wid)
toParentReq WidgetId
_ (StartDrag WidgetId
wid Path
path WidgetDragMsg
info) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> Path -> WidgetDragMsg -> WidgetRequest sp ep
forall s e. WidgetId -> Path -> WidgetDragMsg -> WidgetRequest s e
StartDrag WidgetId
wid Path
path WidgetDragMsg
info)
toParentReq WidgetId
_ (StopDrag WidgetId
wid) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
StopDrag WidgetId
wid)
toParentReq WidgetId
_ WidgetRequest s e
RenderOnce = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just WidgetRequest sp ep
forall s e. WidgetRequest s e
RenderOnce
toParentReq WidgetId
_ (RenderEvery WidgetId
path PathStep
ms Maybe PathStep
repeat) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> PathStep -> Maybe PathStep -> WidgetRequest sp ep
forall s e.
WidgetId -> PathStep -> Maybe PathStep -> WidgetRequest s e
RenderEvery WidgetId
path PathStep
ms Maybe PathStep
repeat)
toParentReq WidgetId
_ (RenderStop WidgetId
path) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
RenderStop WidgetId
path)
toParentReq WidgetId
_ (RemoveRendererImage Text
name) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (Text -> WidgetRequest sp ep
forall s e. Text -> WidgetRequest s e
RemoveRendererImage Text
name)
toParentReq WidgetId
_ (ExitApplication Bool
exit) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (Bool -> WidgetRequest sp ep
forall s e. Bool -> WidgetRequest s e
ExitApplication Bool
exit)
toParentReq WidgetId
_ (UpdateWindow WindowRequest
req) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WindowRequest -> WidgetRequest sp ep
forall s e. WindowRequest -> WidgetRequest s e
UpdateWindow WindowRequest
req)
toParentReq WidgetId
_ (SetWidgetPath WidgetId
wid Path
path) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> Path -> WidgetRequest sp ep
forall s e. WidgetId -> Path -> WidgetRequest s e
SetWidgetPath WidgetId
wid Path
path)
toParentReq WidgetId
_ (ResetWidgetPath WidgetId
wid) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> WidgetRequest sp ep
forall s e. WidgetId -> WidgetRequest s e
ResetWidgetPath WidgetId
wid)
toParentReq WidgetId
wid (UpdateModel s -> s
fn) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> CompMsgUpdate -> WidgetRequest sp ep
forall s e i. Typeable i => WidgetId -> i -> WidgetRequest s e
SendMessage WidgetId
wid ((s -> s) -> CompMsgUpdate
forall s. CompositeModel s => (s -> s) -> CompMsgUpdate
CompMsgUpdate s -> s
fn))
toParentReq WidgetId
wid (RaiseEvent e
message) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> e -> WidgetRequest sp ep
forall s e i. Typeable i => WidgetId -> i -> WidgetRequest s e
SendMessage WidgetId
wid e
message)
toParentReq WidgetId
_ (SendMessage WidgetId
wid i
message) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> i -> WidgetRequest sp ep
forall s e i. Typeable i => WidgetId -> i -> WidgetRequest s e
SendMessage WidgetId
wid i
message)
toParentReq WidgetId
_ (RunTask WidgetId
wid Path
path IO i
action) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> Path -> IO i -> WidgetRequest sp ep
forall s e i.
Typeable i =>
WidgetId -> Path -> IO i -> WidgetRequest s e
RunTask WidgetId
wid Path
path IO i
action)
toParentReq WidgetId
_ (RunProducer WidgetId
wid Path
path (i -> IO ()) -> IO ()
action) = WidgetRequest sp ep -> Maybe (WidgetRequest sp ep)
forall a. a -> Maybe a
Just (WidgetId -> Path -> ((i -> IO ()) -> IO ()) -> WidgetRequest sp ep
forall s e i.
Typeable i =>
WidgetId -> Path -> ((i -> IO ()) -> IO ()) -> WidgetRequest s e
RunProducer WidgetId
wid Path
path (i -> IO ()) -> IO ()
action)

collectWidgetKeys
  :: Map WidgetKey (WidgetNode s e)
  -> WidgetNode s e
  -> Map WidgetKey (WidgetNode s e)
collectWidgetKeys :: Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collectWidgetKeys Map WidgetKey (WidgetNode s e)
keys WidgetNode s e
node = Map WidgetKey (WidgetNode s e)
newMap where
  children :: Seq (WidgetNode s e)
children = 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
  collect :: Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collect Map WidgetKey (WidgetNode s e)
currKeys WidgetNode s e
child = Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
forall s e.
Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collectWidgetKeys Map WidgetKey (WidgetNode s e)
currKeys WidgetNode s e
child
  updatedMap :: Map WidgetKey (WidgetNode s e)
updatedMap = case WidgetNode s e
node WidgetNode s e
-> Getting (Maybe WidgetKey) (WidgetNode s e) (Maybe WidgetKey)
-> Maybe WidgetKey
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const (Maybe WidgetKey) WidgetNodeInfo)
-> WidgetNode s e -> Const (Maybe WidgetKey) (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const (Maybe WidgetKey) WidgetNodeInfo)
 -> WidgetNode s e -> Const (Maybe WidgetKey) (WidgetNode s e))
-> ((Maybe WidgetKey -> Const (Maybe WidgetKey) (Maybe WidgetKey))
    -> WidgetNodeInfo -> Const (Maybe WidgetKey) WidgetNodeInfo)
-> Getting (Maybe WidgetKey) (WidgetNode s e) (Maybe WidgetKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe WidgetKey -> Const (Maybe WidgetKey) (Maybe WidgetKey))
-> WidgetNodeInfo -> Const (Maybe WidgetKey) WidgetNodeInfo
forall s a. HasKey s a => Lens' s a
L.key of
    Just WidgetKey
key -> WidgetKey
-> WidgetNode s e
-> Map WidgetKey (WidgetNode s e)
-> Map WidgetKey (WidgetNode s e)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert WidgetKey
key WidgetNode s e
node Map WidgetKey (WidgetNode s e)
keys
    Maybe WidgetKey
_ -> Map WidgetKey (WidgetNode s e)
keys
  newMap :: Map WidgetKey (WidgetNode s e)
newMap = (Map WidgetKey (WidgetNode s e)
 -> WidgetNode s e -> Map WidgetKey (WidgetNode s e))
-> Map WidgetKey (WidgetNode s e)
-> Seq (WidgetNode s e)
-> Map WidgetKey (WidgetNode s e)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
forall s e.
Map WidgetKey (WidgetNode s e)
-> WidgetNode s e -> Map WidgetKey (WidgetNode s e)
collect Map WidgetKey (WidgetNode s e)
updatedMap Seq (WidgetNode s e)
children

convertWidgetEnv :: WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv :: WidgetEnv sp ep -> WidgetKeyMap s e -> s -> WidgetEnv s e
convertWidgetEnv WidgetEnv sp ep
wenv WidgetKeyMap s e
widgetKeyMap s
model = WidgetEnv :: forall s e.
Text
-> FontManager
-> (Path -> Maybe WidgetNodeInfo)
-> Button
-> Button
-> Theme
-> Size
-> MVar (Map Text WidgetShared)
-> WidgetKeyMap s e
-> Maybe Path
-> Path
-> Maybe Path
-> Maybe (Path, WidgetDragMsg)
-> Maybe (Path, Point)
-> Maybe (Path, CursorIcon)
-> s
-> InputStatus
-> PathStep
-> Bool
-> (Point -> Bool)
-> LayoutDirection
-> Rect
-> Point
-> WidgetEnv s e
WidgetEnv {
  _weOs :: Text
_weOs = WidgetEnv sp ep -> Text
forall s e. WidgetEnv s e -> Text
_weOs WidgetEnv sp ep
wenv,
  _weFontManager :: FontManager
_weFontManager = WidgetEnv sp ep -> FontManager
forall s e. WidgetEnv s e -> FontManager
_weFontManager WidgetEnv sp ep
wenv,
  _weFindByPath :: Path -> Maybe WidgetNodeInfo
_weFindByPath = WidgetEnv sp ep -> Path -> Maybe WidgetNodeInfo
forall s e. WidgetEnv s e -> Path -> Maybe WidgetNodeInfo
_weFindByPath WidgetEnv sp ep
wenv,
  _weMainButton :: Button
_weMainButton = WidgetEnv sp ep -> Button
forall s e. WidgetEnv s e -> Button
_weMainButton WidgetEnv sp ep
wenv,
  _weContextButton :: Button
_weContextButton = WidgetEnv sp ep -> Button
forall s e. WidgetEnv s e -> Button
_weContextButton WidgetEnv sp ep
wenv,
  _weTheme :: Theme
_weTheme = WidgetEnv sp ep -> Theme
forall s e. WidgetEnv s e -> Theme
_weTheme WidgetEnv sp ep
wenv,
  _weWindowSize :: Size
_weWindowSize = WidgetEnv sp ep -> Size
forall s e. WidgetEnv s e -> Size
_weWindowSize WidgetEnv sp ep
wenv,
  _weWidgetShared :: MVar (Map Text WidgetShared)
_weWidgetShared = WidgetEnv sp ep -> MVar (Map Text WidgetShared)
forall s e. WidgetEnv s e -> MVar (Map Text WidgetShared)
_weWidgetShared WidgetEnv sp ep
wenv,
  _weWidgetKeyMap :: WidgetKeyMap s e
_weWidgetKeyMap = WidgetKeyMap s e
widgetKeyMap,
  _weCursor :: Maybe (Path, CursorIcon)
_weCursor = WidgetEnv sp ep -> Maybe (Path, CursorIcon)
forall s e. WidgetEnv s e -> Maybe (Path, CursorIcon)
_weCursor WidgetEnv sp ep
wenv,
  _weHoveredPath :: Maybe Path
_weHoveredPath = WidgetEnv sp ep -> Maybe Path
forall s e. WidgetEnv s e -> Maybe Path
_weHoveredPath WidgetEnv sp ep
wenv,
  _weFocusedPath :: Path
_weFocusedPath = WidgetEnv sp ep -> Path
forall s e. WidgetEnv s e -> Path
_weFocusedPath WidgetEnv sp ep
wenv,
  _weDragStatus :: Maybe (Path, WidgetDragMsg)
_weDragStatus = WidgetEnv sp ep -> Maybe (Path, WidgetDragMsg)
forall s e. WidgetEnv s e -> Maybe (Path, WidgetDragMsg)
_weDragStatus WidgetEnv sp ep
wenv,
  _weMainBtnPress :: Maybe (Path, Point)
_weMainBtnPress = WidgetEnv sp ep -> Maybe (Path, Point)
forall s e. WidgetEnv s e -> Maybe (Path, Point)
_weMainBtnPress WidgetEnv sp ep
wenv,
  _weOverlayPath :: Maybe Path
_weOverlayPath = WidgetEnv sp ep -> Maybe Path
forall s e. WidgetEnv s e -> Maybe Path
_weOverlayPath WidgetEnv sp ep
wenv,
  _weModel :: s
_weModel = s
model,
  _weInputStatus :: InputStatus
_weInputStatus = WidgetEnv sp ep -> InputStatus
forall s e. WidgetEnv s e -> InputStatus
_weInputStatus WidgetEnv sp ep
wenv,
  _weTimestamp :: PathStep
_weTimestamp = WidgetEnv sp ep -> PathStep
forall s e. WidgetEnv s e -> PathStep
_weTimestamp WidgetEnv sp ep
wenv,
  _weThemeChanged :: Bool
_weThemeChanged = WidgetEnv sp ep -> Bool
forall s e. WidgetEnv s e -> Bool
_weThemeChanged WidgetEnv sp ep
wenv,
  _weInTopLayer :: Point -> Bool
_weInTopLayer = WidgetEnv sp ep -> Point -> Bool
forall s e. WidgetEnv s e -> Point -> Bool
_weInTopLayer WidgetEnv sp ep
wenv,
  _weLayoutDirection :: LayoutDirection
_weLayoutDirection = LayoutDirection
LayoutNone,
  _weViewport :: Rect
_weViewport = WidgetEnv sp ep -> Rect
forall s e. WidgetEnv s e -> Rect
_weViewport WidgetEnv sp ep
wenv,
  _weOffset :: Point
_weOffset = WidgetEnv sp ep -> Point
forall s e. WidgetEnv s e -> Point
_weOffset WidgetEnv sp ep
wenv
}

cascadeCtx
  :: WidgetEnv sp ep -> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
cascadeCtx :: WidgetEnv sp ep
-> WidgetNode sp ep -> WidgetNode s e -> WidgetNode s e
cascadeCtx WidgetEnv sp ep
wenv WidgetNode sp ep
parent WidgetNode s e
child = WidgetNode s e
newChild where
  pVisible :: Bool
pVisible = WidgetNode sp ep
parent WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible
  pEnabled :: Bool
pEnabled = WidgetNode sp ep
parent WidgetNode sp ep -> Getting Bool (WidgetNode sp ep) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> WidgetNode sp ep -> Const Bool (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Bool WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Bool (WidgetNode sp ep))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode sp ep) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled
  cVisible :: Bool
cVisible = WidgetNode s e
child 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))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode s e) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible
  cEnabled :: Bool
cEnabled = WidgetNode s e
child 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))
-> ((Bool -> Const Bool Bool)
    -> WidgetNodeInfo -> Const Bool WidgetNodeInfo)
-> Getting Bool (WidgetNode s e) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WidgetNodeInfo -> Const Bool WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled
  newPath :: Path
newPath = WidgetNode sp ep
parent WidgetNode sp ep -> Getting Path (WidgetNode sp ep) Path -> Path
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const Path WidgetNodeInfo)
-> WidgetNode sp ep -> Const Path (WidgetNode sp ep)
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Const Path WidgetNodeInfo)
 -> WidgetNode sp ep -> Const Path (WidgetNode sp ep))
-> Getting Path WidgetNodeInfo Path
-> Getting Path (WidgetNode sp ep) Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Path WidgetNodeInfo Path
forall s a. HasPath s a => Lens' s a
L.path Path -> PathStep -> Path
forall a. Seq a -> a -> Seq a
|> PathStep
0
  newChild :: WidgetNode s e
newChild = WidgetNode s e
child
    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
.~ PathStep -> Path -> WidgetId
WidgetId (WidgetEnv sp ep
wenv WidgetEnv sp ep
-> Getting PathStep (WidgetEnv sp ep) PathStep -> PathStep
forall s a. s -> Getting a s a -> a
^. Getting PathStep (WidgetEnv sp ep) PathStep
forall s a. HasTimestamp s a => Lens' s a
L.timestamp) Path
newPath
    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))
-> ((Path -> Identity Path)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Path -> Identity Path)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Path -> Identity Path)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasPath s a => Lens' s a
L.path ((Path -> Identity Path)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> Path -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Path
newPath
    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))
-> ((Bool -> Identity Bool)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Bool -> Identity Bool)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasVisible s a => Lens' s a
L.visible ((Bool -> Identity Bool)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> Bool -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Bool
cVisible Bool -> Bool -> Bool
&& Bool
pVisible)
    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))
-> ((Bool -> Identity Bool)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Bool -> Identity Bool)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasEnabled s a => Lens' s a
L.enabled ((Bool -> Identity Bool)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> Bool -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Bool
cEnabled Bool -> Bool -> Bool
&& Bool
pEnabled)