{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeFamilies #-}
module GI.Gtk.Declarative.Attributes
( Attribute(..)
, classes
, ClassSet
, on
, onM
, EventHandler(..)
)
where
import qualified Data.GI.Base.Attributes as GI
import qualified Data.GI.Base.Signals as GI
import Data.HashSet ( HashSet )
import qualified Data.HashSet as HashSet
import qualified Data.Text as T
import Data.Text ( Text )
import Data.Typeable
import GHC.TypeLits ( KnownSymbol
, Symbol
)
import qualified GI.Gtk as Gtk
import GI.Gtk.Declarative.Attributes.Internal.EventHandler
import GI.Gtk.Declarative.Attributes.Internal.Conversions
data Attribute widget event where
(:=)
::(GI.AttrOpAllowed 'GI.AttrConstruct info widget
, GI.AttrOpAllowed 'GI.AttrSet info widget
, GI.AttrGetC info widget attr getValue
, GI.AttrSetTypeConstraint info setValue
, KnownSymbol attr
, Typeable attr
, Eq setValue
, Typeable setValue
)
=> GI.AttrLabelProxy (attr :: Symbol) -> setValue -> Attribute widget event
Classes
::Gtk.IsWidget widget
=> ClassSet
-> Attribute widget event
OnSignalPure
::( Gtk.GObject widget
, GI.SignalInfo info
, gtkCallback ~ GI.HaskellCallbackType info
, ToGtkCallback gtkCallback Pure
)
=> Gtk.SignalProxy widget info
-> EventHandler gtkCallback widget Pure event
-> Attribute widget event
OnSignalImpure
::( Gtk.GObject widget
, GI.SignalInfo info
, gtkCallback ~ GI.HaskellCallbackType info
, ToGtkCallback gtkCallback Impure
)
=> Gtk.SignalProxy widget info
-> EventHandler gtkCallback widget Impure event
-> Attribute widget event
type ClassSet = HashSet Text
instance Functor (Attribute widget) where
fmap f = \case
attr := value -> attr := value
Classes cs -> Classes cs
OnSignalPure signal eh -> OnSignalPure signal (fmap f eh)
OnSignalImpure signal eh -> OnSignalImpure signal (fmap f eh)
classes :: Gtk.IsWidget widget => [T.Text] -> Attribute widget event
classes = Classes . HashSet.fromList
on
:: ( Gtk.GObject widget
, GI.SignalInfo info
, gtkCallback ~ GI.HaskellCallbackType info
, ToGtkCallback gtkCallback Pure
, ToEventHandler gtkCallback widget Pure
, userEventHandler ~ UserEventHandler gtkCallback widget Pure event
)
=> Gtk.SignalProxy widget info
-> userEventHandler
-> Attribute widget event
on signal = OnSignalPure signal . toEventHandler
onM
:: ( Gtk.GObject widget
, GI.SignalInfo info
, gtkCallback ~ GI.HaskellCallbackType info
, ToGtkCallback gtkCallback Impure
, ToEventHandler gtkCallback widget Impure
, userEventHandler ~ UserEventHandler gtkCallback widget Impure event
)
=> Gtk.SignalProxy widget info
-> userEventHandler
-> Attribute widget event
onM signal = OnSignalImpure signal . toEventHandler