This repository has been archived by the owner on Jun 18, 2023. It is now read-only.
-
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.
feat(client): changed the tiny existing render code to use the update…
…d core
- Loading branch information
1 parent
8d06e63
commit 8ba7f2a
Showing
2 changed files
with
46 additions
and
0 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,43 @@ | ||
module Lunarbox.Render where | ||
|
||
import Prelude | ||
import Data.List as List | ||
import Lunarflow.Ast (AstF(..)) | ||
import Lunarflow.Geometry.Foreign (fitIntoBounds) | ||
import Lunarflow.Geometry.Types as Shape | ||
import Lunarflow.Layout (Layout, LayoutF) | ||
import Matryoshka (Algebra, cata) | ||
import Run (Run) | ||
import Run.Reader (READER, local) | ||
|
||
type RenderContext | ||
= { doNotRender :: List.List Int | ||
} | ||
|
||
type RenderM r | ||
= Run ( reader :: READER RenderContext | r ) | ||
|
||
-- | Prepare stuff for rendering inside a lambda. | ||
shiftContext :: Int -> RenderContext -> RenderContext | ||
shiftContext by ctx = ctx { doNotRender = ((+) by) <$> ctx.doNotRender } | ||
|
||
{-- | ||
So: | ||
- When we encounter a lambda, we draw the body and then the box around it | ||
- When we encouner a var, we check where it is in scope and draw until here | ||
--} | ||
render :: forall r. Layout -> RenderM r Shape.Shape | ||
render = cata algebra | ||
where | ||
algebra :: Algebra LayoutF (RenderM r Shape.Shape) | ||
algebra (Lambda { args } body) = do | ||
bodyShape <- local (shiftContext $ List.length args) body | ||
let | ||
bounds = fitIntoBounds bodyShape | ||
pure | ||
$ Shape.group {} | ||
[ Shape.fromBounds { fill: "transparent", stroke: "red" } bounds | ||
, bodyShape | ||
] | ||
|
||
algebra _ = pure mempty |