Module

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.

  • render draws on the component every animation frame.
  • update runs on each animation frame, just before render.
  • fixed runs at a set interval of time.
  • interactions are events which will be attached to the canvas element.
  • output defines how (or if) the component should send information out to a parent component.
  • input defines 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.

  • name is the name of the application, which doubles as the HTML id for the canvas element.
  • initialState is the initial state for the application.
  • viewBox is the desired dimensions for the drawing area.
  • window defines how the screen element should size and position itself.
  • behavior contains functions that control i/o, updates, and rendering.

#WindowMode Source

data WindowMode

There are three modes that determine the size and position of a Gesso component:

  • Fixed creates a screen of the specified size.
  • Stretch expands to fill its containing element.
  • FullScreen takes up the entire page from the top left corner to the bottom right.

Constructors

#defaultBehavior Source

defaultBehavior :: forall state input output. AppBehavior state input output

A 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 state

An function that may update the application state. It runs on every frame, before the render function. It knows the following:

  • Delta is a record containing current and previous timestamps and the time elapsed since the previous frame.
  • Scalers is a record containing scaling information for transforming coordinates between the drawing and the canvas.
  • state is 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 Unit

A function that draws on the component. It knows the following:

  • Context2D is the drawing context of the canvas element
  • Delta is a record containing current and previous timestamps and the time elapsed since the previous frame.
  • Scalers is a record containing scaling information for transforming coordinates between the drawing and the canvas.
  • state is the state of the application, with States containing 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.

#OutputProducer Source

type OutputProducer state output = Delta -> Scalers -> Compare state -> Effect (Maybe output)

When the state of an application changes, an output producer compares the old and new states and may send output to the component's parent based on the difference.

#InputReceiver Source

type InputReceiver state input = input -> UpdateFunction state

An 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.