| Safe Haskell | Safe-Inferred |
|---|
CanvasHs.Data
Description
The CanvasHs.Data module exposes all data types needed for the Event handler function. It exposes Events, Shapes, Actions and Output and all their needed sub-types
- type Point = (Int, Int)
- type Path = [Point]
- type Color = (Int, Int, Int, Float)
- class Defaults a where
- defaults :: a
- data EventData = EventData {}
- type FontSize = Int
- data Alignment
- = AlignLeft
- | AlignRight
- | AlignCenter
- data TextData = TextData {}
- data Shape
- = Rect Point Int Int
- | Circle Point Int
- | Arc Point Int Int
- | Line Path
- | Polygon Path
- | Text Point String TextData
- | Fill Color Shape
- | Stroke Color Int Shape
- | Rotate Int Shape
- | Translate Int Int Shape
- | Scale Float Float Shape
- | Event EventData Shape
- | Offset Point Shape
- | Container Int Int [Shape]
- data BlockingAction
- data Action
- data WindowDisplayType
- = FullWindow
- | FullScreen
- | FixedSize Int Int
- type RegularOutput = (Maybe Shape, [Action])
- data Output
- data Modifier
- data Event
- = MouseDown Point String
- | MouseClick Point String
- | MouseUp Point String
- | MouseDoubleClick Point String
- | MouseDrag Point String Point String
- | MouseOver Point String
- | MouseOut Point String
- | KeyDown String [Modifier]
- | KeyUp String [Modifier]
- | KeyClick String [Modifier]
- | Scroll String Int Int
- | StartEvent
- | FileLoadedString String String
- | FileLoadedBinary String ByteString
- | Tick String
- | UploadComplete (String, ByteString)
- | WindowResize Int Int
- | PromptResponse String
Documentation
type Color = (Int, Int, Int, Float)
Represents a RGBA color as tuple of 3 Ints for RGB (value should range from 0 to 255) and a float for A (value should range from 0 to 1.0), (r, g, b, a) these value ranges are not enforced by the encoding and values outside of the range will be send to the canvas unchanged and could result in unexpected behaviour.
class Defaults a where
A class that defines a function defaults that returns a default value for a given record
Methods
defaults :: a
data EventData
Constructors
| EventData | |
Fields
| |
data Alignment
Defines text alignment, used in conjunction with TextData
Constructors
| AlignLeft | Aligns the start of the text to the specified point. |
| AlignRight | Aligns the end of the text to the specified point. |
| AlignCenter | Aligns the center of the text to the specified point. |
data TextData
Used in conjunction with the Text shape to describe how to draw text
Constructors
| TextData | |
Fields
| |
data Shape
All drawable Shapes and the transformations that can be applied to them. In practice these will be combined in one big shape tree. By default shapes are filled in black (0,0,0,1.0)
Constructors
| Rect Point Int Int | A rectangle. Has a startpoint (left upper corner) and width, height |
| Circle Point Int | A circle. Has a centerpoint and a radius |
| Arc Point Int Int | An arch. Has a centerpoint, radius and angle, rotation is done by Rotate. |
| Line Path | A line. Has a path containing its points, doesn't connect start and end. |
| Polygon Path | A polygon. Has a path containing its points, does connect start to end to form a closed shape |
| Text Point String TextData | Text. Has a point (how to align to that point is set using the alignment field in TextData)
a string containing the text to draw and |
| Fill Color Shape | Applies fill. Has a |
| Stroke Color Int Shape | Applies stroke. Has a |
| Rotate Int Shape | Applies rotation. Has a rotation (counterclockwise) in degrees and a shape that needs to be rotated. |
| Translate Int Int Shape | Applies translation. Has an xdiff and ydiff (how much the Shape should be moved in x an y direction) and a shape that needs to be translated. |
| Scale Float Float Shape | Applies scale. Has xscale, yscale (how much the shape should be scaled in width and height) and a shape that needs to be scaled. |
| Event EventData Shape | Indicates that the given shape is interested in Events. |
| Offset Point Shape | Overrides the normal rotationpoint or scalepoint with the one specified |
| Container Int Int [Shape] | A container. Has width and height and a list of shapes in this container.
Note that by default a container is drawn at point (0, 0) and it can be moved using |
data BlockingAction
A BlockingAction can not be combined with other Shapes or Actions in Output. Like an Action it will instruct
CanvasHs to do something. It will execute and then trigger an Event with the result of the BlockingAction
Constructors
| LoadFileString String | Loads a file as string. Has a filepath to load from |
| LoadFileBinary String | Loads a file in binary mode. Has a filepath to load from |
data Action
An Action will instruct CanvasHs to do something on either the haskell side, such as saving a file or
starting a timer, or on the canvas side such as prompting for input or downloading a file. These Actions
may or may not result in an Event and could be done either by Haskell or the Canvas (javascript)
Constructors
| SaveFileString String String | Saves a file as string. Has a filepath to save to, and a String of the file contents. If the file already has contents it will be overwritten |
| SaveFileBinary String ByteString | Saves a file in binary mode. Has a filepath to save to, and a ByteString of the file contents. When the file already has contents it will be overwritten |
| Timer Int String | Starts a repeating Timer. Has a timeout in ms and a String identifying the Timer. |
| StopTimer String | Stops a started timer, idintief by it's id. |
| Debug Bool | Turns the debug console on or off. Has a Bool, True means show, False means hide is send to javascript |
| DragNDrop Bool Bool | Turns file drag |
| DisplayType WindowDisplayType | Changes the window display type to the specified |
| Download String String | Sends a file to the javascript so the user can download it. Has the filename and filecontents as String is send to javacript |
| RequestUpload Bool | Asks the user to select a file to upload, the Bool indicates if multiple files can be selected or not. could result in one or multiple UploadComplete events. is send to javascript |
| Prompt String String | Prompts the user a message and asks for a certain value, with a default for that value. Has a String of the message to show and a String of the default value. |
data WindowDisplayType
The window display type for use in conjunction with the DisplayType Event. FixedSize has a Width and Height
Constructors
| FullWindow | |
| FullScreen | |
| FixedSize Int Int |
type RegularOutput = (Maybe Shape, [Action])
data Output
Output is the return type of the handler. It is either a BlockingAction or RemoteOutput It can't have both a BlockingAction and a Shape to draw, because the BlockingAction will trigger handler, which could then return also return a Shape, we then would not know which Shape to draw.
Constructors
| Block BlockingAction | |
| Out RegularOutput |
data Modifier
data Event
The events that can be triggered by CanvasHs. These could either be the result of user input (such as
i.e. MouseDown or KeyUp) or could be triggered by an Action such as FileLoaded or Tick, or could be
triggered by CanvasHs itself (StartEvent)
Constructors
| MouseDown Point String | A mousedown event consisting of a point and ID string of the interested object |
| MouseClick Point String | A mouseclick event consisting of a point and ID string of the interested object |
| MouseUp Point String | A mouseup event consisting of a point and ID string of the interested object |
| MouseDoubleClick Point String | A mousedoubleclick event consisting of a point and ID string of the interested object |
| MouseDrag Point String Point String | A mousedrag event with start and end, both consisting of a Point an ID string |
| MouseOver Point String | A mouseover event, consisting of a point and ID string of the interested object |
| MouseOut Point String | A mouseout event, consisting of a point and ID string of the interested object |
| KeyDown String [Modifier] | A keydown event, consist of a key that was pressed and a list of modifiers that were active |
| KeyUp String [Modifier] | A keyup event, consist of a key that was pressed and a list of modifiers that were active |
| KeyClick String [Modifier] | A keyclick event, consist of a key that was pressed and a list of modifiers that were active |
| Scroll String Int Int | A scroll event consisting of an ID string of the interested object, a xdiff and an ydiff (how much was scrolled in the x and y direction) |
| StartEvent | Start event is triggered when the server is started to notify user |
| FileLoadedString String String | When a file requested using the LoadFileString |
| FileLoadedBinary String ByteString | When a file requested using the LoadFileString Action has been loaded. Has a filepath and file contents as ByteString |
| Tick String | Tick event from a Timer. Has a string identifying the Timer |
| UploadComplete (String, ByteString) | An upload has been completed. Has contents |
| WindowResize Int Int | A reseizewindoweventm has a new width and height |
| PromptResponse String | A response of the user to the prompt. Has a String of the response. |
Instances
| Eq Event | |
| Show Event | |
| FromJSON Event | The FromJSON instance of |