{-# LANGUAGE OverloadedStrings #-}
module NanoUI.Widgets.Drawing
( DrawOp (..)
, DrawingBuild
, drawing
, drawingVersioned
, drawingCached
)
where
import Data.Text qualified as T
import Data.Primitive.SmallArray (SmallArray)
import Effectful (Eff, type (:>))
import NanoUI.Context (cachedWidgetLayout, registerDrawing)
import NanoUI.Draw (DrawOp (..), DrawingBuild)
import NanoUI.Layout.Arena (NodeType (NodeDrawing))
import NanoUI.Monad (Ui, askContext, nextId, uiIO)
import NanoUI.Style (Layout, defaultLayout)
import NanoUI.Types (Rect)
import NanoUI.Widgets.Node (Response, addWidget)
{-# INLINE drawing #-}
drawing :: Ui :> es => (Layout -> Layout) -> (Rect -> SmallArray DrawOp) -> Eff es Response
drawing :: forall (es :: [Effect]).
(Ui :> es) =>
(Layout -> Layout)
-> (Rect -> SmallArray DrawOp) -> Eff es Response
drawing = Int
-> (Layout -> Layout)
-> (Rect -> SmallArray DrawOp)
-> Eff es Response
forall (es :: [Effect]).
(Ui :> es) =>
Int
-> (Layout -> Layout)
-> (Rect -> SmallArray DrawOp)
-> Eff es Response
drawingVersioned Int
0
drawingVersioned :: Ui :> es => Int -> (Layout -> Layout) -> (Rect -> SmallArray DrawOp) -> Eff es Response
drawingVersioned :: forall (es :: [Effect]).
(Ui :> es) =>
Int
-> (Layout -> Layout)
-> (Rect -> SmallArray DrawOp)
-> Eff es Response
drawingVersioned Int
version Layout -> Layout
f Rect -> SmallArray DrawOp
build = do
wid <- Eff es WidgetId
forall (es :: [Effect]). (Ui :> es) => Eff es WidgetId
nextId
ctx <- askContext
uiIO (registerDrawing ctx wid version build)
addWidget wid NodeDrawing T.empty 0 (f defaultLayout)
drawingCached ::
Ui :> es =>
Double ->
Double ->
Float ->
Int ->
(Layout -> Layout) ->
IO Layout ->
DrawingBuild ->
Eff es Response
drawingCached :: forall (es :: [Effect]).
(Ui :> es) =>
Double
-> Double
-> Float
-> Int
-> (Layout -> Layout)
-> IO Layout
-> (Rect -> SmallArray DrawOp)
-> Eff es Response
drawingCached Double
dw Double
dh Float
lh Int
content Layout -> Layout
f IO Layout
compute Rect -> SmallArray DrawOp
build = do
wid <- Eff es WidgetId
forall (es :: [Effect]). (Ui :> es) => Eff es WidgetId
nextId
ctx <- askContext
layout <- uiIO (cachedWidgetLayout ctx wid dw dh lh content (f defaultLayout) compute)
uiIO (registerDrawing ctx wid content build)
addWidget wid NodeDrawing T.empty 0 layout