mirror of
https://github.com/fjvallarino/monomer.git
synced 2024-09-21 00:38:01 +03:00
Create lenses for Widget.hs types
This commit is contained in:
parent
ebb524cab6
commit
2dab19f9ae
21
src/Monomer/Widget/LensCore.hs
Normal file
21
src/Monomer/Widget/LensCore.hs
Normal file
@ -0,0 +1,21 @@
|
||||
--{-# LANGUAGE ConstraintKinds #-}
|
||||
--{-# LANGUAGE ExistentialQuantification #-}
|
||||
--{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE FunctionalDependencies #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
module Monomer.Widget.LensCore where
|
||||
|
||||
import Control.Lens.TH (abbreviatedFields, makeLensesWith)
|
||||
|
||||
import Monomer.Widget.Types
|
||||
|
||||
makeLensesWith abbreviatedFields ''SizePolicy
|
||||
makeLensesWith abbreviatedFields ''SizeReq
|
||||
makeLensesWith abbreviatedFields ''WidgetEnv
|
||||
makeLensesWith abbreviatedFields ''WidgetRequest
|
||||
makeLensesWith abbreviatedFields ''WidgetResult
|
||||
makeLensesWith abbreviatedFields ''WidgetPlatform
|
||||
makeLensesWith abbreviatedFields ''WidgetValue
|
||||
makeLensesWith abbreviatedFields ''WidgetInstance
|
@ -200,7 +200,7 @@ data Widget s e =
|
||||
data WidgetInstance s e =
|
||||
WidgetInstance {
|
||||
-- | Type of the widget
|
||||
_wiType :: !WidgetType,
|
||||
_wiWidgetType :: !WidgetType,
|
||||
-- | Key/Identifier of the widget
|
||||
_wiKey :: Maybe WidgetKey,
|
||||
-- | The path of the instance in the widget tree
|
||||
|
@ -24,7 +24,7 @@ rootPath = Seq.empty
|
||||
|
||||
defaultWidgetInstance :: WidgetType -> Widget s e -> WidgetInstance s e
|
||||
defaultWidgetInstance widgetType widget = WidgetInstance {
|
||||
_wiType = widgetType,
|
||||
_wiWidgetType = widgetType,
|
||||
_wiKey = Nothing,
|
||||
_wiPath = Seq.empty,
|
||||
_wiWidget = widget,
|
||||
@ -86,7 +86,7 @@ useState (Just (WidgetState state)) = cast state
|
||||
|
||||
instanceMatches :: WidgetInstance s e -> WidgetInstance s e -> Bool
|
||||
instanceMatches newInstance oldInstance = typeMatches && keyMatches where
|
||||
typeMatches = _wiType oldInstance == _wiType newInstance
|
||||
typeMatches = _wiWidgetType oldInstance == _wiWidgetType newInstance
|
||||
keyMatches = _wiKey oldInstance == _wiKey newInstance
|
||||
|
||||
updateSizeReq :: SizeReq -> WidgetInstance s e -> SizeReq
|
||||
|
Loading…
Reference in New Issue
Block a user