@@ -29,11 +29,9 @@ import Hickory.ImGUI ()
2929import Data.Hashable (Hashable )
3030import Data.Proxy (Proxy (.. ))
3131
32- -- Types which have an 'attribute' representation in the editor
3332class Attr a where
3433 mkAttr :: Attribute a
3534
36- -- Sometimes the storage type differs (e.g. DearIMGui represents Vec3s as a float triple)
3735 type AttrRef a :: Type
3836 type AttrRef a = a
3937
@@ -49,21 +47,17 @@ typeOfAttr = \case
4947 ColorAttribute -> typeRep
5048
5149data AttrClasses a where
52- -- Provides proof of a type having certain instances
5350 AttrClasses :: (Eq a , Eq (AttrRef a )) => AttrClasses a
5451
55- -- Prove that each attribute has some necessary instances
5652proveAttrClasses :: Attribute a -> AttrClasses a
5753proveAttrClasses = \ case
5854 ColorAttribute -> AttrClasses
5955
60- -- Check if two attributes have the same type
6156eqAttr :: Attribute a1 -> Attribute a2 -> Maybe (a1 :~~: a2 )
6257eqAttr a b = eqTypeRep (typeOfAttr a) (typeOfAttr b)
6358
6459data SomeAttribute contents = forall a . Attr a => SomeAttribute { attr :: Attribute a , contents :: contents a }
6560
66- -- Look up the value for an attribute
6761withAttrVal :: forall a b k . (Attr a , Hashable k ) => HashMap k (SomeAttribute Identity ) -> k -> (a -> b ) -> b
6862withAttrVal attrs name f = case Map. lookup name attrs of
6963 Just (SomeAttribute attr (Identity v)) -> case eqAttr attr (mkAttr :: Attribute a ) of
@@ -79,19 +73,14 @@ mkDefaultComponent :: [SomeAttribute (Const String)] -> HashMap String (SomeAttr
7973mkDefaultComponent xs = Map. fromList $ xs <&> \ case
8074 SomeAttribute attr (Const name) -> (name, SomeAttribute attr (Identity $ defaultAttrVal attr))
8175
82- {- Generics -}
83-
8476class GRecordAttributes (f :: Type -> Type ) where
8577 gToAttributeList :: Proxy f -> [SomeAttribute (Const String )]
8678 gFromHashMap :: HashMap String (SomeAttribute Identity ) -> f p
8779
88- -- Empty constructor
8980instance GRecordAttributes U1 where
9081 gToAttributeList _ = []
9182 gFromHashMap _ = U1
9283
93- -- For metadata that doesn't affect structure (the D and C metadata),
94- -- we just pass through to the contained representation.
9584instance GRecordAttributes f => GRecordAttributes (M1 D x f ) where
9685 gToAttributeList _ = gToAttributeList (Proxy :: Proxy f )
9786 gFromHashMap hm = M1 (gFromHashMap hm)
@@ -100,27 +89,6 @@ instance GRecordAttributes f => GRecordAttributes (M1 C x f) where
10089 gToAttributeList _ = gToAttributeList (Proxy :: Proxy f )
10190 gFromHashMap hm = M1 (gFromHashMap hm)
10291
103- instance (GRecordAttributes f , GRecordAttributes g )
104- => GRecordAttributes (f :*: g ) where
105- gToAttributeList _ =
106- gToAttributeList (Proxy :: Proxy f ) ++ gToAttributeList (Proxy :: Proxy g )
107- gFromHashMap hm =
108- let left = gFromHashMap hm
109- right = gFromHashMap hm
110- in left :*: right
111-
112- -- A single field
113- instance (Selector s , Attr a ) => GRecordAttributes (M1 S s (K1 i a )) where
114- gToAttributeList _ =
115- let fieldName = selName (undefined :: M1 S s (K1 i a ) p )
116- in [ SomeAttribute (mkAttr @ a ) (Const fieldName) ]
117- gFromHashMap hm =
118- let fieldName = selName (undefined :: M1 S s (K1 i a ) p )
119- val = withAttrVal hm fieldName id
120- in M1 (K1 val)
121-
122- {- Generic GLSL struct definitions -}
123-
12492class GlslType a where
12593 glslTypeName :: Proxy a -> String
12694
@@ -138,12 +106,6 @@ instance GHasGlslUniformDef f => GHasGlslUniformDef (M1 D x f) where
138106instance GHasGlslUniformDef f => GHasGlslUniformDef (M1 C x f ) where
139107 gGlslLines _ = gGlslLines (Proxy :: Proxy f )
140108
141- instance (GHasGlslUniformDef f , GHasGlslUniformDef g )
142- => GHasGlslUniformDef (f :*: g ) where
143- gGlslLines _ =
144- gGlslLines (Proxy :: Proxy f ) ++
145- gGlslLines (Proxy :: Proxy g )
146-
147109instance (Selector s , GlslType a )
148110 => GHasGlslUniformDef (M1 S s (K1 i a )) where
149111 gGlslLines _ =
0 commit comments