Skip to content

1.2 Wiki notation, types, and functions

Jonas de Luna Skulberg edited this page Sep 10, 2023 · 3 revisions

This short section will go over how the wiki is written so it can be read and understood more clearly.

Components

This is an example of how a component may be described, as well as a breakdown of what each part means:

class Graphica.Text(text, options)

Parameters:

  • text: string
  • options:
{
  position?: InputPosition;
  color?: string;
  fontSize?: number;
  anchorY?: "top" | "middle" | "bottom";
  anchorX?: "left" | "center" | "right";
  weight?: fontWeight;
}

Methods:

  • setText(text: string): void

Explanation:

This short section describes the Text component used in Graphica. We can see that it is a class, and we instantiate it with its' constructor taking 2 arguments. The first one is a text; simple - it's just a string. The second is an object of type options. The type of object that is required to pass in is described under the Parameters section. We can see it has the properties position, color, fontSize, anchorY, anchorX, and weight - all of which are optional denoted by the ?. After the semicolon we can see each of these properties types or possible values. There will be a page listing all globally used types in Graphica such as InputPosition. For the anchorY we see that we can specify a string out of the 3 listed here, denoted with the | or between the 3 alternatives.

Types

Here are some type notation that may be useful;

  • number[] denotes an array of numbers
  • Array<number> is the same as number[]
  • [number] is an array of length 1. Similarly, [number, number] is an array of strictly length 2. Passing an array of length 1 or 3 will throw an error
  • number | undefined is to be interpreted as number or undefined, passing in either should work.
  • [InputPosition,InputPosition,InputPosition,...InputPosition[] is interpreted as an array of at least 3 InputPositions with no upper bound.

Additionally it is not always logical whether an argument should be passed through the object of options or directly to the constructor. If in doubt, consult the wiki. Usually the required parameters will be passed directly into the constructor with other options like color, line width etc. belonging in the object.

Lastly, Components (classes) can also be used as types sometimes, like Point can be used in InputPosition to reference the position of a point.

Clone this wiki locally