Gesso.Application
- Package
- purescript-gesso
- Repository
- smilack/purescript-gesso
Functions and configuration necessary to start a Gesso application.
#AppBehavior Source
type AppBehavior state input output = { fixed :: FixedUpdate state, input :: InputReceiver state input, interactions :: Interactions state, output :: OutputProducer state output, render :: RenderFunction state, update :: UpdateFunction state }AppBehavior holds the functions that make an application run.
renderdraws on the component every animation frame.updateruns on each animation frame, just beforerender.fixedruns at a set interval of time.interactionsare events which will be attached to the canvas element.outputdefines how (or if) the component should send information out to a parent component.inputdefines how the component's state should change in response to receiving input from a parent component.
#AppSpec Source
type AppSpec state input output = { behavior :: AppBehavior state input output, initialState :: state, name :: String, viewBox :: Rect, window :: WindowMode }AppSpec holds information about the setup and behavior of a Gesso
component.
nameis the name of the application, which doubles as the HTMLidfor the canvas element.initialStateis the initial state for the application.viewBoxis the desired dimensions for the drawing area.windowdefines how the screen element should size and position itself.behaviorcontains functions that control i/o, updates, and rendering.
#WindowMode Source
data WindowModeThere are three modes that determine the size and position of a Gesso component:
Fixedcreates a screen of the specified size.Stretchexpands to fill its containing element.FullScreentakes up the entire page from the top left corner to the bottom right.
Constructors
#defaultBehavior Source
defaultBehavior :: forall state input output. AppBehavior state input outputA default AppBehavior which can be modified piecemeal like Halogen's
EvalSpec. It does nothing on its own.
Re-exports from Gesso.Application.Behavior
#UpdateFunction Source
type UpdateFunction state = Delta -> TimestampedUpdate stateAn function that may update the application state. It runs on every frame, before the render function. It knows the following:
Deltais a record containing current and previous timestamps and the time elapsed since the previous frame.Scalersis a record containing scaling information for transforming coordinates between the drawing and the canvas.stateis the state of the application
The update function may return a new state if changes are necessary (or
Nothing if not).
This type is also used by Interaction handlers and when receiving input from a host application.
#TimestampedUpdate Source
type TimestampedUpdate state = Scalers -> state -> Effect (Maybe state)A partially applied UpdateFunction that already has the Delta record.
#RenderFunction Source
type RenderFunction state = Context2D -> Delta -> Scalers -> States state -> Effect UnitA function that draws on the component. It knows the following:
Context2Dis the drawing context of the canvas elementDeltais a record containing current and previous timestamps and the time elapsed since the previous frame.Scalersis a record containing scaling information for transforming coordinates between the drawing and the canvas.stateis the state of the application, withStatescontaining the two most recent states and the time progress between them (on the interval[0, 1]).
The render function may run any operations in Effect, not just functions
related to drawing on the canvas.
#InputReceiver Source
type InputReceiver state input = input -> UpdateFunction stateAn input receiver is a variant of an update function that can receive information from the component's parent and produce an update function in response.
#FixedUpdate Source
type FixedUpdate state = { function :: UpdateFunction state, interval :: Interval }An update function that occurs at a fixed, regular interval, rather than on every animation frame.