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

Simple confirm dialog, displaying an accept and close buttons and optional
title. Usually embedded in a zstack component and displayed/hidden depending on
context.
-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Strict #-}

module Monomer.Widgets.Containers.Confirm (
  -- * Configuration
  ConfirmCfg,
  -- * Constructors
  confirm,
  confirm_,
  confirmMsg,
  confirmMsg_
) where

import Control.Applicative ((<|>))
import Control.Lens ((&), (^.), (.~), (<>~))
import Data.Default
import Data.Maybe
import Data.Text (Text)

import Monomer.Core
import Monomer.Core.Combinators

import Monomer.Widgets.Composite
import Monomer.Widgets.Containers.Box
import Monomer.Widgets.Containers.Keystroke
import Monomer.Widgets.Containers.Stack
import Monomer.Widgets.Singles.Button
import Monomer.Widgets.Singles.Icon
import Monomer.Widgets.Singles.Label
import Monomer.Widgets.Singles.Spacer

import qualified Monomer.Lens as L

{-|
Configuration options for confirm:

- 'titleCaption': the title of the alert dialog.
- 'acceptCaption': the caption of the accept button.
- 'closeCaption': the caption of the close button.
-}
data ConfirmCfg = ConfirmCfg {
  ConfirmCfg -> Maybe Text
_cfcTitle :: Maybe Text,
  ConfirmCfg -> Maybe Text
_cfcAccept :: Maybe Text,
  ConfirmCfg -> Maybe Text
_cfcCancel :: Maybe Text
}

instance Default ConfirmCfg where
  def :: ConfirmCfg
def = ConfirmCfg :: Maybe Text -> Maybe Text -> Maybe Text -> ConfirmCfg
ConfirmCfg {
    _cfcTitle :: Maybe Text
_cfcTitle = Maybe Text
forall a. Maybe a
Nothing,
    _cfcAccept :: Maybe Text
_cfcAccept = Maybe Text
forall a. Maybe a
Nothing,
    _cfcCancel :: Maybe Text
_cfcCancel = Maybe Text
forall a. Maybe a
Nothing
  }

instance Semigroup ConfirmCfg where
  <> :: ConfirmCfg -> ConfirmCfg -> ConfirmCfg
(<>) ConfirmCfg
a1 ConfirmCfg
a2 = ConfirmCfg :: Maybe Text -> Maybe Text -> Maybe Text -> ConfirmCfg
ConfirmCfg {
    _cfcTitle :: Maybe Text
_cfcTitle = ConfirmCfg -> Maybe Text
_cfcTitle ConfirmCfg
a2 Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ConfirmCfg -> Maybe Text
_cfcTitle ConfirmCfg
a1,
    _cfcAccept :: Maybe Text
_cfcAccept = ConfirmCfg -> Maybe Text
_cfcAccept ConfirmCfg
a2 Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ConfirmCfg -> Maybe Text
_cfcAccept ConfirmCfg
a1,
    _cfcCancel :: Maybe Text
_cfcCancel = ConfirmCfg -> Maybe Text
_cfcCancel ConfirmCfg
a2 Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ConfirmCfg -> Maybe Text
_cfcCancel ConfirmCfg
a1
  }

instance Monoid ConfirmCfg where
  mempty :: ConfirmCfg
mempty = ConfirmCfg
forall a. Default a => a
def

instance CmbTitleCaption ConfirmCfg where
  titleCaption :: Text -> ConfirmCfg
titleCaption Text
t = ConfirmCfg
forall a. Default a => a
def {
    _cfcTitle :: Maybe Text
_cfcTitle = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t
  }

instance CmbAcceptCaption ConfirmCfg where
  acceptCaption :: Text -> ConfirmCfg
acceptCaption Text
t = ConfirmCfg
forall a. Default a => a
def {
    _cfcAccept :: Maybe Text
_cfcAccept = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t
  }

instance CmbCancelCaption ConfirmCfg where
  cancelCaption :: Text -> ConfirmCfg
cancelCaption Text
t = ConfirmCfg
forall a. Default a => a
def {
    _cfcCancel :: Maybe Text
_cfcCancel = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t
  }

newtype ConfirmEvt e
  = ConfirmParentEvt e
  deriving (ConfirmEvt e -> ConfirmEvt e -> Bool
(ConfirmEvt e -> ConfirmEvt e -> Bool)
-> (ConfirmEvt e -> ConfirmEvt e -> Bool) -> Eq (ConfirmEvt e)
forall e. Eq e => ConfirmEvt e -> ConfirmEvt e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfirmEvt e -> ConfirmEvt e -> Bool
$c/= :: forall e. Eq e => ConfirmEvt e -> ConfirmEvt e -> Bool
== :: ConfirmEvt e -> ConfirmEvt e -> Bool
$c== :: forall e. Eq e => ConfirmEvt e -> ConfirmEvt e -> Bool
Eq, Int -> ConfirmEvt e -> ShowS
[ConfirmEvt e] -> ShowS
ConfirmEvt e -> String
(Int -> ConfirmEvt e -> ShowS)
-> (ConfirmEvt e -> String)
-> ([ConfirmEvt e] -> ShowS)
-> Show (ConfirmEvt e)
forall e. Show e => Int -> ConfirmEvt e -> ShowS
forall e. Show e => [ConfirmEvt e] -> ShowS
forall e. Show e => ConfirmEvt e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfirmEvt e] -> ShowS
$cshowList :: forall e. Show e => [ConfirmEvt e] -> ShowS
show :: ConfirmEvt e -> String
$cshow :: forall e. Show e => ConfirmEvt e -> String
showsPrec :: Int -> ConfirmEvt e -> ShowS
$cshowsPrec :: forall e. Show e => Int -> ConfirmEvt e -> ShowS
Show)

-- | Creates a confirm dialog with the provided content.
confirm
  :: (WidgetModel s, WidgetEvent e)
  => e                             -- ^ The accept button event.
  -> e                             -- ^ The cancel button event.
  -> WidgetNode () (ConfirmEvt e)  -- ^ The content to display in the dialog.
  -> WidgetNode s e               -- ^ The created dialog.
confirm :: e -> e -> WidgetNode () (ConfirmEvt e) -> WidgetNode s e
confirm e
acceptEvt e
cancelEvt WidgetNode () (ConfirmEvt e)
dialogBody = WidgetNode s e
newNode where
  newNode :: WidgetNode s e
newNode = e
-> e
-> [ConfirmCfg]
-> WidgetNode () (ConfirmEvt e)
-> WidgetNode s e
forall s e.
(WidgetModel s, WidgetEvent e) =>
e
-> e
-> [ConfirmCfg]
-> WidgetNode () (ConfirmEvt e)
-> WidgetNode s e
confirm_ e
acceptEvt e
cancelEvt [ConfirmCfg]
forall a. Default a => a
def WidgetNode () (ConfirmEvt e)
dialogBody

-- | Creates an alert dialog with the provided content. Accepts config.
confirm_
  :: (WidgetModel s, WidgetEvent e)
  => e                             -- ^ The accept button event.
  -> e                             -- ^ The cancel button event.
  -> [ConfirmCfg]                   -- ^ The config options for the dialog.
  -> WidgetNode () (ConfirmEvt e)  -- ^ The content to display in the dialog.
  -> WidgetNode s e               -- ^ The created dialog.
confirm_ :: e
-> e
-> [ConfirmCfg]
-> WidgetNode () (ConfirmEvt e)
-> WidgetNode s e
confirm_ e
acceptEvt e
cancelEvt [ConfirmCfg]
configs WidgetNode () (ConfirmEvt e)
dialogBody = WidgetNode s e
newNode where
  config :: ConfirmCfg
config = [ConfirmCfg] -> ConfirmCfg
forall a. Monoid a => [a] -> a
mconcat [ConfirmCfg]
configs
  createUI :: WidgetEnv () (ConfirmEvt e) -> () -> WidgetNode () (ConfirmEvt e)
createUI = (WidgetEnv () (ConfirmEvt e) -> WidgetNode () (ConfirmEvt e))
-> e
-> e
-> ConfirmCfg
-> WidgetEnv () (ConfirmEvt e)
-> ()
-> WidgetNode () (ConfirmEvt e)
forall s ep.
(WidgetModel s, WidgetEvent ep) =>
(WidgetEnv s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> ep
-> ep
-> ConfirmCfg
-> WidgetEnv s (ConfirmEvt ep)
-> s
-> WidgetNode s (ConfirmEvt ep)
buildUI (WidgetNode () (ConfirmEvt e)
-> WidgetEnv () (ConfirmEvt e) -> WidgetNode () (ConfirmEvt e)
forall a b. a -> b -> a
const WidgetNode () (ConfirmEvt e)
dialogBody) e
acceptEvt e
cancelEvt ConfirmCfg
config
  compCfg :: [CompositeCfg s e sp ep]
compCfg = [MergeReqsHandler s e -> CompositeCfg s e sp ep
forall s e sp ep. MergeReqsHandler s e -> CompositeCfg s e sp ep
compositeMergeReqs MergeReqsHandler s e
forall s e. MergeReqsHandler s e
mergeReqs]
  newNode :: WidgetNode s e
newNode = WidgetType
-> WidgetData s ()
-> (WidgetEnv () (ConfirmEvt e)
    -> () -> WidgetNode () (ConfirmEvt e))
-> EventHandler () (ConfirmEvt e) s e
-> [CompositeCfg () (ConfirmEvt e) s e]
-> WidgetNode s e
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
"confirm" (() -> WidgetData s ()
forall s a. a -> WidgetData s a
WidgetValue ()) WidgetEnv () (ConfirmEvt e) -> () -> WidgetNode () (ConfirmEvt e)
createUI EventHandler () (ConfirmEvt e) s e
forall s ep sp.
WidgetEnv s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
-> s
-> ConfirmEvt ep
-> [EventResponse s (ConfirmEvt ep) sp ep]
handleEvent [CompositeCfg () (ConfirmEvt e) s e]
forall s e sp ep. [CompositeCfg s e sp ep]
compCfg

-- | Creates an alert dialog with a text message as content.
confirmMsg
  :: (WidgetModel s, WidgetEvent e)
  => Text              -- ^ The message to display in the dialog.
  -> e                -- ^ The accept button event.
  -> e                -- ^ The cancel button event.
  -> WidgetNode s e  -- ^ The created dialog.
confirmMsg :: Text -> e -> e -> WidgetNode s e
confirmMsg Text
msg e
acceptEvt e
cancelEvt = Text -> e -> e -> [ConfirmCfg] -> WidgetNode s e
forall s e.
(WidgetModel s, WidgetEvent e) =>
Text -> e -> e -> [ConfirmCfg] -> WidgetNode s e
confirmMsg_ Text
msg e
acceptEvt e
cancelEvt [ConfirmCfg]
forall a. Default a => a
def

-- | Creates an alert dialog with a text message as content. Accepts config.
confirmMsg_
  :: (WidgetModel s, WidgetEvent e)
  => Text              -- ^ The message to display in the dialog.
  -> e                -- ^ The accept button event.
  -> e                -- ^ The cancel button event.
  -> [ConfirmCfg]      -- ^ The config options for the dialog.
  -> WidgetNode s e  -- ^ The created dialog.
confirmMsg_ :: Text -> e -> e -> [ConfirmCfg] -> WidgetNode s e
confirmMsg_ Text
message e
acceptEvt e
cancelEvt [ConfirmCfg]
configs = WidgetNode s e
newNode where
  config :: ConfirmCfg
config = [ConfirmCfg] -> ConfirmCfg
forall a. Monoid a => [a] -> a
mconcat [ConfirmCfg]
configs
  dialogBody :: WidgetEnv s e -> WidgetNode s e
dialogBody WidgetEnv s e
wenv = Text -> [LabelCfg s e] -> WidgetNode s e
forall s e. Text -> [LabelCfg s e] -> WidgetNode s e
label_ Text
message [LabelCfg s e
forall t. CmbMultiline t => t
multiline]
    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))
-> ((Style -> Identity Style)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Style -> Identity Style)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style -> Identity Style)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasStyle s a => Lens' s a
L.style ((Style -> Identity Style)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> Style -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s e -> Lens' ThemeState StyleState -> Style
forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s e
wenv forall s a. HasDialogMsgBodyStyle s a => Lens' s a
Lens' ThemeState StyleState
L.dialogMsgBodyStyle
  createUI :: WidgetEnv () (ConfirmEvt e) -> () -> WidgetNode () (ConfirmEvt e)
createUI = (WidgetEnv () (ConfirmEvt e) -> WidgetNode () (ConfirmEvt e))
-> e
-> e
-> ConfirmCfg
-> WidgetEnv () (ConfirmEvt e)
-> ()
-> WidgetNode () (ConfirmEvt e)
forall s ep.
(WidgetModel s, WidgetEvent ep) =>
(WidgetEnv s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> ep
-> ep
-> ConfirmCfg
-> WidgetEnv s (ConfirmEvt ep)
-> s
-> WidgetNode s (ConfirmEvt ep)
buildUI WidgetEnv () (ConfirmEvt e) -> WidgetNode () (ConfirmEvt e)
forall s e s e. WidgetEnv s e -> WidgetNode s e
dialogBody e
acceptEvt e
cancelEvt ConfirmCfg
config
  compCfg :: [CompositeCfg s e sp ep]
compCfg = [MergeReqsHandler s e -> CompositeCfg s e sp ep
forall s e sp ep. MergeReqsHandler s e -> CompositeCfg s e sp ep
compositeMergeReqs MergeReqsHandler s e
forall s e. MergeReqsHandler s e
mergeReqs]
  newNode :: WidgetNode s e
newNode = WidgetType
-> WidgetData s ()
-> (WidgetEnv () (ConfirmEvt e)
    -> () -> WidgetNode () (ConfirmEvt e))
-> EventHandler () (ConfirmEvt e) s e
-> [CompositeCfg () (ConfirmEvt e) s e]
-> WidgetNode s e
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
"confirm" (() -> WidgetData s ()
forall s a. a -> WidgetData s a
WidgetValue ()) WidgetEnv () (ConfirmEvt e) -> () -> WidgetNode () (ConfirmEvt e)
createUI EventHandler () (ConfirmEvt e) s e
forall s ep sp.
WidgetEnv s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
-> s
-> ConfirmEvt ep
-> [EventResponse s (ConfirmEvt ep) sp ep]
handleEvent [CompositeCfg () (ConfirmEvt e) s e]
forall s e sp ep. [CompositeCfg s e sp ep]
compCfg

mergeReqs :: MergeReqsHandler s e
mergeReqs :: MergeReqsHandler s e
mergeReqs WidgetEnv s e
wenv WidgetNode s e
newNode WidgetNode s e
oldNode s
model = [WidgetRequest s e]
forall s e. [WidgetRequest s e]
reqs where
  acceptPath :: Maybe (WidgetRequest s e)
acceptPath = WidgetId -> WidgetRequest s e
forall s e. WidgetId -> WidgetRequest s e
SetFocus (WidgetId -> WidgetRequest s e)
-> Maybe WidgetId -> Maybe (WidgetRequest s e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WidgetEnv s e -> WidgetKey -> Maybe WidgetId
forall s e. WidgetEnv s e -> WidgetKey -> Maybe WidgetId
widgetIdFromKey WidgetEnv s e
wenv WidgetKey
"acceptBtn"
  isVisible :: s -> a
isVisible s
node = s
node s -> Getting a s a -> a
forall s a. s -> Getting a s a -> a
^. (a -> Const a a) -> s -> Const a s
forall s a. HasInfo s a => Lens' s a
L.info ((a -> Const a a) -> s -> Const a s)
-> ((a -> Const a a) -> a -> Const a a) -> Getting a s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Const a a) -> a -> Const a a
forall s a. HasVisible s a => Lens' s a
L.visible
  reqs :: [WidgetRequest s e]
reqs
    | Bool -> Bool
not (WidgetNode s e -> Bool
forall s a a. (HasInfo s a, HasVisible a a) => s -> a
isVisible WidgetNode s e
oldNode) Bool -> Bool -> Bool
&& WidgetNode s e -> Bool
forall s a a. (HasInfo s a, HasVisible a a) => s -> a
isVisible WidgetNode s e
newNode = [Maybe (WidgetRequest s e)] -> [WidgetRequest s e]
forall a. [Maybe a] -> [a]
catMaybes [Maybe (WidgetRequest s e)
forall s e. Maybe (WidgetRequest s e)
acceptPath]
    | Bool
otherwise = []

buildUI
  :: (WidgetModel s, WidgetEvent ep)
  => (WidgetEnv s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
  -> ep
  -> ep
  -> ConfirmCfg
  -> WidgetEnv s (ConfirmEvt ep)
  -> s
  -> WidgetNode s (ConfirmEvt ep)
buildUI :: (WidgetEnv s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> ep
-> ep
-> ConfirmCfg
-> WidgetEnv s (ConfirmEvt ep)
-> s
-> WidgetNode s (ConfirmEvt ep)
buildUI WidgetEnv s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep)
dialogBody ep
pAcceptEvt ep
pCancelEvt ConfirmCfg
config WidgetEnv s (ConfirmEvt ep)
wenv s
model = WidgetNode s (ConfirmEvt ep)
mainTree where
  acceptEvt :: ConfirmEvt ep
acceptEvt = ep -> ConfirmEvt ep
forall e. e -> ConfirmEvt e
ConfirmParentEvt ep
pAcceptEvt
  cancelEvt :: ConfirmEvt ep
cancelEvt = ep -> ConfirmEvt ep
forall e. e -> ConfirmEvt e
ConfirmParentEvt ep
pCancelEvt

  title :: Text
title = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (ConfirmCfg -> Maybe Text
_cfcTitle ConfirmCfg
config)
  accept :: Text
accept = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"Accept" (ConfirmCfg -> Maybe Text
_cfcAccept ConfirmCfg
config)
  cancel :: Text
cancel = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"Cancel" (ConfirmCfg -> Maybe Text
_cfcCancel ConfirmCfg
config)
  emptyOverlay :: Style
emptyOverlay = WidgetEnv s (ConfirmEvt ep) -> Lens' ThemeState StyleState -> Style
forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s (ConfirmEvt ep)
wenv forall s a. HasEmptyOverlayStyle s a => Lens' s a
Lens' ThemeState StyleState
L.emptyOverlayStyle

  acceptBtn :: WidgetNode s (ConfirmEvt ep)
acceptBtn = Text -> ConfirmEvt ep -> WidgetNode s (ConfirmEvt ep)
forall e s. WidgetEvent e => Text -> e -> WidgetNode s e
mainButton Text
accept ConfirmEvt ep
acceptEvt WidgetNode s (ConfirmEvt ep)
-> Text -> WidgetNode s (ConfirmEvt ep)
forall s e. WidgetNode s e -> Text -> WidgetNode s e
`nodeKey` Text
"acceptBtn"
  cancelBtn :: WidgetNode s (ConfirmEvt ep)
cancelBtn = Text -> ConfirmEvt ep -> WidgetNode s (ConfirmEvt ep)
forall e s. WidgetEvent e => Text -> e -> WidgetNode s e
button Text
cancel ConfirmEvt ep
cancelEvt
  buttons :: WidgetNode s (ConfirmEvt ep)
buttons = [WidgetNode s (ConfirmEvt ep)] -> WidgetNode s (ConfirmEvt ep)
forall (t :: * -> *) s e.
Traversable t =>
t (WidgetNode s e) -> WidgetNode s e
hstack [ WidgetNode s (ConfirmEvt ep)
forall s. WidgetNode s (ConfirmEvt ep)
acceptBtn, WidgetNode s (ConfirmEvt ep)
forall s e. WidgetNode s e
spacer, WidgetNode s (ConfirmEvt ep)
forall s. WidgetNode s (ConfirmEvt ep)
cancelBtn ]

  closeIcon :: WidgetNode s e
closeIcon = IconType -> [IconCfg] -> WidgetNode s e
forall s e. IconType -> [IconCfg] -> WidgetNode s e
icon_ IconType
IconClose [Double -> IconCfg
forall t. CmbWidth t => Double -> t
width Double
2]
    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))
-> ((Style -> Identity Style)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Style -> Identity Style)
-> WidgetNode s e
-> Identity (WidgetNode s e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style -> Identity Style)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasStyle s a => Lens' s a
L.style ((Style -> Identity Style)
 -> WidgetNode s e -> Identity (WidgetNode s e))
-> Style -> WidgetNode s e -> WidgetNode s e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s (ConfirmEvt ep) -> Lens' ThemeState StyleState -> Style
forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s (ConfirmEvt ep)
wenv forall s a. HasDialogCloseIconStyle s a => Lens' s a
Lens' ThemeState StyleState
L.dialogCloseIconStyle
  confirmTree :: WidgetNode s (ConfirmEvt ep)
confirmTree = [StackCfg]
-> [WidgetNode s (ConfirmEvt ep)] -> WidgetNode s (ConfirmEvt ep)
forall (t :: * -> *) s e.
Traversable t =>
[StackCfg] -> t (WidgetNode s e) -> WidgetNode s e
vstack_ [((SizeReq, SizeReq) -> (SizeReq, SizeReq)) -> StackCfg
forall t.
CmbSizeReqUpdater t =>
((SizeReq, SizeReq) -> (SizeReq, SizeReq)) -> t
sizeReqUpdater (SizeReq, SizeReq) -> (SizeReq, SizeReq)
clearExtra] [
      [WidgetNode s (ConfirmEvt ep)] -> WidgetNode s (ConfirmEvt ep)
forall (t :: * -> *) s e.
Traversable t =>
t (WidgetNode s e) -> WidgetNode s e
hstack [
        Text -> WidgetNode s (ConfirmEvt ep)
forall s e. Text -> WidgetNode s e
label Text
title WidgetNode s (ConfirmEvt ep)
-> (WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> WidgetNode s (ConfirmEvt ep)
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> ((Style -> Identity Style)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Style -> Identity Style)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style -> Identity Style)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasStyle s a => Lens' s a
L.style ((Style -> Identity Style)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> Style
-> WidgetNode s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s (ConfirmEvt ep) -> Lens' ThemeState StyleState -> Style
forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s (ConfirmEvt ep)
wenv forall s a. HasDialogTitleStyle s a => Lens' s a
Lens' ThemeState StyleState
L.dialogTitleStyle,
        WidgetNode s (ConfirmEvt ep)
forall s e. WidgetNode s e
filler,
        [BoxCfg s (ConfirmEvt ep)]
-> WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep)
forall s e.
(WidgetModel s, WidgetEvent e) =>
[BoxCfg s e] -> WidgetNode s e -> WidgetNode s e
box_ [BoxCfg s (ConfirmEvt ep)
forall t. CmbAlignTop t => t
alignTop, ConfirmEvt ep -> BoxCfg s (ConfirmEvt ep)
forall t e. CmbOnClick t e => e -> t
onClick ConfirmEvt ep
cancelEvt] WidgetNode s (ConfirmEvt ep)
forall s e. WidgetNode s e
closeIcon
      ],
      WidgetEnv s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep)
dialogBody WidgetEnv s (ConfirmEvt ep)
wenv,
      WidgetNode s (ConfirmEvt ep)
forall s e. WidgetNode s e
filler,
      [BoxCfg s (ConfirmEvt ep)]
-> WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep)
forall s e.
(WidgetModel s, WidgetEvent e) =>
[BoxCfg s e] -> WidgetNode s e -> WidgetNode s e
box_ [BoxCfg s (ConfirmEvt ep)
forall t. CmbAlignRight t => t
alignRight] WidgetNode s (ConfirmEvt ep)
forall s. WidgetNode s (ConfirmEvt ep)
buttons
        WidgetNode s (ConfirmEvt ep)
-> (WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> WidgetNode s (ConfirmEvt ep)
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> ((Style -> Identity Style)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Style -> Identity Style)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style -> Identity Style)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasStyle s a => Lens' s a
L.style ((Style -> Identity Style)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> Style
-> WidgetNode s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ WidgetEnv s (ConfirmEvt ep) -> Lens' ThemeState StyleState -> Style
forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s (ConfirmEvt ep)
wenv forall s a. HasDialogButtonsStyle s a => Lens' s a
Lens' ThemeState StyleState
L.dialogButtonsStyle
    ] WidgetNode s (ConfirmEvt ep)
-> (WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> WidgetNode s (ConfirmEvt ep)
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> ((Style -> Identity Style)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Style -> Identity Style)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style -> Identity Style)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasStyle s a => Lens' s a
L.style ((Style -> Identity Style)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> Style
-> WidgetNode s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ WidgetEnv s (ConfirmEvt ep) -> Lens' ThemeState StyleState -> Style
forall s e. WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme WidgetEnv s (ConfirmEvt ep)
wenv forall s a. HasDialogFrameStyle s a => Lens' s a
Lens' ThemeState StyleState
L.dialogFrameStyle
  confirmBox :: WidgetNode s (ConfirmEvt ep)
confirmBox = [BoxCfg s (ConfirmEvt ep)]
-> WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep)
forall s e.
(WidgetModel s, WidgetEvent e) =>
[BoxCfg s e] -> WidgetNode s e -> WidgetNode s e
box_ [ConfirmEvt ep -> BoxCfg s (ConfirmEvt ep)
forall t e. CmbOnClickEmpty t e => e -> t
onClickEmpty ConfirmEvt ep
cancelEvt] WidgetNode s (ConfirmEvt ep)
confirmTree
    WidgetNode s (ConfirmEvt ep)
-> (WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep))
-> WidgetNode s (ConfirmEvt ep)
forall a b. a -> (a -> b) -> b
& (WidgetNodeInfo -> Identity WidgetNodeInfo)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall s a. HasInfo s a => Lens' s a
L.info ((WidgetNodeInfo -> Identity WidgetNodeInfo)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> ((Style -> Identity Style)
    -> WidgetNodeInfo -> Identity WidgetNodeInfo)
-> (Style -> Identity Style)
-> WidgetNode s (ConfirmEvt ep)
-> Identity (WidgetNode s (ConfirmEvt ep))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style -> Identity Style)
-> WidgetNodeInfo -> Identity WidgetNodeInfo
forall s a. HasStyle s a => Lens' s a
L.style ((Style -> Identity Style)
 -> WidgetNode s (ConfirmEvt ep)
 -> Identity (WidgetNode s (ConfirmEvt ep)))
-> Style
-> WidgetNode s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Style
emptyOverlay
  mainTree :: WidgetNode s (ConfirmEvt ep)
mainTree = [(Text, ConfirmEvt ep)]
-> WidgetNode s (ConfirmEvt ep) -> WidgetNode s (ConfirmEvt ep)
forall e s.
WidgetEvent e =>
[(Text, e)] -> WidgetNode s e -> WidgetNode s e
keystroke [(Text
"Esc", ConfirmEvt ep
cancelEvt)] WidgetNode s (ConfirmEvt ep)
confirmBox

handleEvent
  :: WidgetEnv s (ConfirmEvt ep)
  -> WidgetNode s (ConfirmEvt ep)
  -> s
  -> ConfirmEvt ep
  -> [EventResponse s (ConfirmEvt ep) sp ep]
handleEvent :: WidgetEnv s (ConfirmEvt ep)
-> WidgetNode s (ConfirmEvt ep)
-> s
-> ConfirmEvt ep
-> [EventResponse s (ConfirmEvt ep) sp ep]
handleEvent WidgetEnv s (ConfirmEvt ep)
wenv WidgetNode s (ConfirmEvt ep)
node s
model ConfirmEvt ep
evt = case ConfirmEvt ep
evt of
  ConfirmParentEvt ep
pevt -> [ep -> EventResponse s (ConfirmEvt ep) sp ep
forall s e sp ep. ep -> EventResponse s e sp ep
Report ep
pevt]