{-# LANGUAGE Strict #-}
module Monomer.Main.UserUtil where
import Control.Lens
import Data.Default
import Data.Maybe
import Monomer.Widgets.Composite
import Monomer.Widgets.Singles.Spacer
import qualified Monomer.Core.Lens as L
{-# DEPRECATED setFocusOnKey "Use SetFocusOnKey instead (wenv argument should be removed)." #-}
setFocusOnKey :: WidgetEnv s e -> WidgetKey -> EventResponse s e sp ep
setFocusOnKey :: forall s e sp ep.
WidgetEnv s e -> WidgetKey -> EventResponse s e sp ep
setFocusOnKey WidgetEnv s e
wenv WidgetKey
key = WidgetRequest s e -> EventResponse s e sp ep
forall s e sp ep. WidgetRequest s e -> EventResponse s e sp ep
Request (WidgetId -> WidgetRequest s e
forall s e. WidgetId -> WidgetRequest s e
SetFocus WidgetId
widgetId) where
widgetId :: WidgetId
widgetId = WidgetId -> Maybe WidgetId -> WidgetId
forall a. a -> Maybe a -> a
fromMaybe WidgetId
forall a. Default a => a
def (WidgetEnv s e -> WidgetKey -> Maybe WidgetId
forall s e. WidgetEnv s e -> WidgetKey -> Maybe WidgetId
widgetIdFromKey WidgetEnv s e
wenv WidgetKey
key)
setClipboardData :: ClipboardData -> EventResponse s e sp ep
setClipboardData :: forall s e sp ep. ClipboardData -> EventResponse s e sp ep
setClipboardData ClipboardData
cdata = WidgetRequest s e -> EventResponse s e sp ep
forall s e sp ep. WidgetRequest s e -> EventResponse s e sp ep
Request (ClipboardData -> WidgetRequest s e
forall s e. ClipboardData -> WidgetRequest s e
SetClipboard ClipboardData
cdata)
setCursorIcon :: WidgetNode s e -> CursorIcon -> EventResponse s e sp ep
setCursorIcon :: forall s e sp ep.
WidgetNode s e -> CursorIcon -> EventResponse s e sp ep
setCursorIcon WidgetNode s e
node CursorIcon
icon = WidgetRequest s e -> EventResponse s e sp ep
forall s e sp ep. WidgetRequest s e -> EventResponse s e sp ep
Request (WidgetId -> CursorIcon -> WidgetRequest s e
forall s e. WidgetId -> CursorIcon -> WidgetRequest s e
SetCursorIcon WidgetId
widgetId CursorIcon
icon) where
widgetId :: WidgetId
widgetId = WidgetNode s e
node WidgetNode s e
-> Getting WidgetId (WidgetNode s e) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode s e -> Const WidgetId (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
Lens' (WidgetNode s e) WidgetNodeInfo
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
Lens' WidgetNodeInfo WidgetId
L.widgetId
resetCursorIcon :: WidgetNode s e -> EventResponse s e sp ep
resetCursorIcon :: forall s e sp ep. WidgetNode s e -> EventResponse s e sp ep
resetCursorIcon WidgetNode s e
node = WidgetRequest s e -> EventResponse s e sp ep
forall s e sp ep. WidgetRequest s e -> EventResponse s e sp ep
Request (WidgetId -> WidgetRequest s e
forall s e. WidgetId -> WidgetRequest s e
ResetCursorIcon WidgetId
widgetId) where
widgetId :: WidgetId
widgetId = WidgetNode s e
node WidgetNode s e
-> Getting WidgetId (WidgetNode s e) WidgetId -> WidgetId
forall s a. s -> Getting a s a -> a
^. (WidgetNodeInfo -> Const WidgetId WidgetNodeInfo)
-> WidgetNode s e -> Const WidgetId (WidgetNode s e)
forall s a. HasInfo s a => Lens' s a
Lens' (WidgetNode s e) WidgetNodeInfo
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
Lens' WidgetNodeInfo WidgetId
L.widgetId
exitApplication :: EventResponse s e sp ep
exitApplication :: forall s e sp ep. EventResponse s e sp ep
exitApplication = WidgetRequest s e -> EventResponse s e sp ep
forall s e sp ep. WidgetRequest s e -> EventResponse s e sp ep
Request (Bool -> WidgetRequest s e
forall s e. Bool -> WidgetRequest s e
ExitApplication Bool
True)
cancelExitApplication :: EventResponse s e sp ep
cancelExitApplication :: forall s e sp ep. EventResponse s e sp ep
cancelExitApplication = WidgetRequest s e -> EventResponse s e sp ep
forall s e sp ep. WidgetRequest s e -> EventResponse s e sp ep
Request (Bool -> WidgetRequest s e
forall s e. Bool -> WidgetRequest s e
ExitApplication Bool
False)
widgetIf :: Bool -> WidgetNode s e -> WidgetNode s e
widgetIf :: forall s e. Bool -> WidgetNode s e -> WidgetNode s e
widgetIf Bool
True WidgetNode s e
node = WidgetNode s e
node
widgetIf Bool
False WidgetNode s e
_ = WidgetNode s e
forall s e. WidgetNode s e
spacer WidgetNode s e -> Bool -> WidgetNode s e
forall s e. WidgetNode s e -> Bool -> WidgetNode s e
`nodeVisible` Bool
False
widgetMaybe :: Maybe a -> (a -> WidgetNode s e) -> WidgetNode s e
widgetMaybe :: forall a s e. Maybe a -> (a -> WidgetNode s e) -> WidgetNode s e
widgetMaybe Maybe a
Nothing a -> WidgetNode s e
_ = WidgetNode s e
forall s e. WidgetNode s e
spacer WidgetNode s e -> Bool -> WidgetNode s e
forall s e. WidgetNode s e -> Bool -> WidgetNode s e
`nodeVisible` Bool
False
widgetMaybe (Just a
val) a -> WidgetNode s e
fn = a -> WidgetNode s e
fn a
val
styleIf :: Bool -> StyleState -> StyleState
styleIf :: Bool -> StyleState -> StyleState
styleIf Bool
True StyleState
state = StyleState
state
styleIf Bool
False StyleState
_ = StyleState
forall a. Monoid a => a
mempty
styleMaybe :: Maybe a -> (a -> StyleState) -> StyleState
styleMaybe :: forall a. Maybe a -> (a -> StyleState) -> StyleState
styleMaybe Maybe a
Nothing a -> StyleState
_ = StyleState
forall a. Monoid a => a
mempty
styleMaybe (Just a
state) a -> StyleState
fn = a -> StyleState
fn a
state
configIf :: Monoid a => Bool -> a -> a
configIf :: forall a. Monoid a => Bool -> a -> a
configIf Bool
True a
val = a
val
configIf Bool
False a
_ = a
forall a. Monoid a => a
mempty
configMaybe :: Monoid a => Maybe b -> (b -> a) -> a
configMaybe :: forall a b. Monoid a => Maybe b -> (b -> a) -> a
configMaybe Maybe b
Nothing b -> a
_ = a
forall a. Monoid a => a
mempty
configMaybe (Just b
val) b -> a
fn = b -> a
fn b
val
responseIf :: Bool -> EventResponse s e sp ep -> EventResponse s e sp ep
responseIf :: forall s e sp ep.
Bool -> EventResponse s e sp ep -> EventResponse s e sp ep
responseIf Bool
True EventResponse s e sp ep
resp = EventResponse s e sp ep
resp
responseIf Bool
False EventResponse s e sp ep
_ = EventResponse s e sp ep
forall s e sp ep. EventResponse s e sp ep
NoOpResponse
responseMaybe :: Maybe (EventResponse s e sp ep) -> EventResponse s e sp ep
responseMaybe :: forall s e sp ep.
Maybe (EventResponse s e sp ep) -> EventResponse s e sp ep
responseMaybe (Just EventResponse s e sp ep
resp) = EventResponse s e sp ep
resp
responseMaybe Maybe (EventResponse s e sp ep)
Nothing = EventResponse s e sp ep
forall s e sp ep. EventResponse s e sp ep
NoOpResponse