-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UIComponent class with toSVG method (#305)
- Loading branch information
1 parent
7572230
commit 2a41551
Showing
5 changed files
with
101 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module GridKit.UIComponent where | ||
|
||
import Data.Vec3.AffineTransform | ||
import Data.Foldable (foldMap) | ||
import Halogen.HTML (PlainHTML) | ||
|
||
class UIComponent a where | ||
toSVG :: AffineTransform Number -> a -> Array PlainHTML | ||
|
||
instance uiComponentArray :: UIComponent a => UIComponent (Array a) where | ||
toSVG transform = foldMap (toSVG transform) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,16 @@ | ||
module View.GridKit.Point where | ||
|
||
import Prelude | ||
|
||
import Data.Vec3 (Point2, _x, _y) | ||
import Data.Vec3.AffineTransform | ||
import Effect.Class (class MonadEffect) | ||
import Halogen as H | ||
import Halogen.HTML | ||
import Svg.Elements as S | ||
import Svg.Attributes hiding (path) as S | ||
|
||
import View.ReactiveInput as ReactiveInput | ||
|
||
type Input = | ||
{ position :: Point2 Number | ||
, model2svg :: AffineTransform Number | ||
} | ||
import Svg.Attributes as S | ||
|
||
data VoidF a | ||
type Slot = H.Slot VoidF Void | ||
import GridKit.UIComponent | ||
|
||
ui :: ∀ q m. MonadEffect m => H.Component HTML q Input Void m | ||
ui = ReactiveInput.mkComponent | ||
{ initialState: {} | ||
, render | ||
, handleAction: \_ _ -> pure unit | ||
, handleInput: \_ -> pure unit | ||
} | ||
newtype Point = Point (Point2 Number) | ||
|
||
render :: ∀ m. Input -> {} -> H.ComponentHTML Void () m | ||
render { position, model2svg } _ = | ||
S.circle [ S.class_ "point", S.cx (_x center), S.cy (_y center), S.r 5.0 ] | ||
where | ||
center = model2svg `transform` position | ||
instance uiComponentPoint :: UIComponent Point where | ||
toSVG model2svg (Point position) = | ||
[ S.circle [ S.class_ "point", S.cx (_x center), S.cy (_y center), S.r 3.0 ] ] | ||
where | ||
center = model2svg `transform` position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module View.GridKit.Rect where | ||
|
||
import Data.Vec3 (Point2, Vec2, _x, _y) | ||
import Data.Vec3.AffineTransform | ||
import Svg.Elements as S | ||
import Svg.Attributes as S | ||
|
||
import GridKit.UIComponent | ||
|
||
newtype Rect = Rect | ||
{ topLeft :: Point2 Number | ||
, size :: Vec2 Number | ||
} | ||
|
||
instance uiComponentRect :: UIComponent Rect where | ||
toSVG model2svg (Rect { topLeft, size }) = | ||
[ S.rect [ S.class_ "rect", S.x (_x xy), S.y (_y xy), S.width (_x wh), S.height (_y wh) ] ] | ||
where | ||
xy = model2svg `transform` topLeft | ||
wh = model2svg `transform` size |