{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module GI.Gtk.Declarative.Widget
( Widget(..)
, FromWidget(..)
)
where
import Data.Typeable
import GI.Gtk.Declarative.EventSource
import GI.Gtk.Declarative.Patch
data Widget event where
Widget
::( Typeable widget
, Patchable widget
, Functor widget
, EventSource widget
)
=> widget event
-> Widget event
instance Functor Widget where
fmap f (Widget w) = Widget (fmap f w)
instance Patchable Widget where
create (Widget w) = create w
patch s (Widget (w1 :: t1 e1)) (Widget (w2 :: t2 e2)) = case eqT @t1 @t2 of
Just Refl -> patch s w1 w2
_ -> Replace (create w2)
instance EventSource Widget where
subscribe (Widget w) = subscribe w
class FromWidget widget target where
fromWidget :: widget event -> target event
instance ( Typeable parent
, Typeable child
, Patchable (parent child)
, Functor (parent child)
, EventSource (parent child)
)
=> FromWidget (parent child) Widget where
fromWidget = Widget