Skip to content

Commit

Permalink
Initial documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kulcsar committed Jun 21, 2019
1 parent 61c280b commit 72eff73
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 29 deletions.
11 changes: 7 additions & 4 deletions FontInfo.constructor.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# FontInfo.constructor

Default constructor for the FontInfo class.
Default constructor for the `FontInfo` class.

`constructor(font: FontName, size: number)`
```typescript
constructor(font: FontName, size: number)
```

`font: FontName` FontName of font to use. Possible values: `FontName.Font5` and `FontName.Font8`.
## Parameters

`size: number` Multiplier for font. For example, to use a double-sized font, set `size` to 2.
- `font: FontName` [`FontName`](FontName.md) of font to use.
- `size: number` Multiplier for font. For example, to use a double-sized font, set `size` to 2.
11 changes: 11 additions & 0 deletions FontInfo.font.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FontInfo.font property

Get an `Image.font` object related to the `FontInfo` object.

```typescript
FontInfo.font: Image.Font
```

## Return value

An `Image.font` object with the properties set in the `FontInfo` object.
11 changes: 11 additions & 0 deletions FontInfo.fontName.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FontInfo.fontName property

Get a [`FontName`](FontName.md) enum value related to the `FontInfo` object.

```typescript
FontInfo.fontName: FontName
```

## Return value

A [`FontName`](FontName.md) value.
11 changes: 11 additions & 0 deletions FontInfo.height.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FontInfo.height property

Get the character height of the `FontInfo` object.

```typescript
FontInfo.height: number
```

## Return value

A `number` representing the character height of the font used in the `FontInfo` object.
11 changes: 11 additions & 0 deletions FontInfo.size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# FontInfo.size property

Get the multiplier used by the `FontInfo` object.

```typescript
FontInfo.size: number
```

## Return value

A `number` representing the multiplier used by the `FontInfo` object. For example, if the font is double-sized, `size` will return `2`.
15 changes: 15 additions & 0 deletions FontInfo.width.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# FontInfo.width method

Calculate the width of a string in pixels.

```typescript
FontInfo.width(text: string): number
```

## Parameters

- `text: string` Text to measure.

## Return value

A `number` representing the width of the text in pixels.
7 changes: 7 additions & 0 deletions FontName.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# FontName enum

Enumerates the available fonts in the system.

## Values
- `FontName.Font5`
- `FontName.Font8`
9 changes: 9 additions & 0 deletions TextAlignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TextAlignment enum

Enumerates the possible alignments when wrapping text within a bounding box.

## Values

- `TextAlignment.Left`
- `TextAlignment.Center`
- `TextAlignment.Right`
37 changes: 21 additions & 16 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Display Strings API

## Enumerations

- [`FontName`](FontName.md)
- [`TextAlignment`](TextAlignment.md)

## `FontInfo` class

- [`constructor(FontName, number)`](FontInfo.constructor.md)
- **Properties**
- `font`
- `fontName`
- `height`
- `size`
- **Public methods**
- `width(string)`
- [`constructor(FontName, number)`](FontInfo.constructor.md)
- **Properties**
- [`font`](FontInfo.font.md)
- [`fontName`](FontInfo.fontName.md)
- [`height`](FontInfo.height.md)
- [`size`](FontInfo.size.md)
- **Public methods**
- [`width(string)`](FontInfo.width.md)

## `drawStrings` namespace
- `createFontInfo(FontName, number)`
- `height(FontInfo)`
- `width(string, FontInfo)`
- `write(string, Image, number, number, number, FontInfo)`
- `writeCenter(string, Image, number, number, FontInfo)`
- `writeMultiple(string[], Image, number, number, number, FontInfo, number)`
- `writeMultipleCenter(string[], Image, number, number, FontInfo, number)`
- `writeWrapped(string, Image, number, number, number, number, FontInfo, number, number)`
- [`createFontInfo(FontName, number)`](drawStrings.createFontInfo.md)
- [`height(FontInfo)`](drawStrings.height.md)
- [`width(string, FontInfo)`](drawStrings.width.md)
- [`write(string, Image, number, number, number, FontInfo)`](drawStrings.write.md)
- [`writeCenter(string, Image, number, number, FontInfo)`](drawStrings.writeCenter.md)
- [`writeMultiple(string[], Image, number, number, number, FontInfo, number)`](drawStrings.writeMultiple.md)
- [`writeMultipleCenter(string[], Image, number, number, FontInfo, number)`](drawStrings.writeMultipleCenter.md)
- [`writeWrapped(string, Image, number, number, number, number, FontInfo, number, number)`](drawStrings.writeWrapped.md)
18 changes: 9 additions & 9 deletions displayStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ namespace drawStrings {
* @param {Image} img - Drawing canvas.
* @param {number} x - Horizontal coordinate for top-left of string.
* @param {number} y - Vertical coordinate for top-left of string.
* @param {color} color - Color to use when drawing text.
* @param {number} color - Color to use when drawing text.
* @param {FontInfo} fi - Font to use.
*/
//% blockId=drawstring_write
//% block="write %text on image %img=screen_image_picker at x %x y %y with color %color=colorindexpicker in font %fi"
//% text.defl="Hello!" x.defl=0 y.defl=0 color.defl=1 color.min=0 color.max=15 fi.shadow="variables_get"
//% hidden
export function write(text: string, img: Image,
x: number, y: number, color: color, fi: FontInfo)
x: number, y: number, color: number, fi: FontInfo)
: void {
if (!fi) {
fi = createFontInfo(DEFAULT_FONT)
Expand All @@ -215,15 +215,15 @@ namespace drawStrings {
* @param {string} text - String to draw.
* @param {Image} img - Drawing canvas.
* @param {number} y - Vertical coordinate for top of string.
* @param {color} color - Color to use when drawing text.
* @param {number} color - Color to use when drawing text.
* @param {FontInfo} fi - Font to use.
*/
//% blockId=drawstring_write_center
//% block="write %text centered on image %img=screen_image_picker at y %y with color %color=colorindexpicker in font %fi"
//% text.defl="Hello!" x.defl=0 y.defl=0 color.defl=1 fi.shadow="variables_get"
//% hidden
export function writeCenter(text: string, img: Image,
y: number, color: color, fi: FontInfo): void {
y: number, color: number, fi: FontInfo): void {
if (!fi) {
fi = createFontInfo(DEFAULT_FONT)
} // if (!fi)
Expand All @@ -236,15 +236,15 @@ namespace drawStrings {
* @param {Image} img - Drawing canvas.
* @param {number} x - Horizontal coordinate for top-left of first string.
* @param {number} y - Vertical coordinate for top-left of first string.
* @param {color} color - Color to use when drawing text.
* @param {number} color - Color to use when drawing text.
* @param {FontInfo} fi - Font to use.
* @param {number} spacing - Number of pixels to skip between strings.
*/
//% blockId=drawstring_write_multi
//% block="write strings %text on image %img=screen_image_picker at x %x y %y with color %color=colorindexpicker in font %fi || with spacing %spacing"
//% text.shadow="variables_get" x.defl=0 y.defl=0 color.defl=1 color.min=0 color.max=15 spacing.defl=1 fi.shadow="variables_get"
export function writeMultiple(text: string[], img: Image,
x: number, y: number, color: color, fi: FontInfo,
x: number, y: number, color: number, fi: FontInfo,
spacing: number = 1)
: void {
if (!fi) {
Expand All @@ -263,15 +263,15 @@ namespace drawStrings {
* @param {string[]} text - Strings to draw.
* @param {Image} img - Drawing canvas.
* @param {number} y - Vertical coordinate for top of first string.
* @param {color} color - Color to use when drawing text.
* @param {number} color - Color to use when drawing text.
* @param {FontInfo} fi - Font to use.
* @param {number} spacing - Number of pixels to skip between strings.
*/
//% blockId=drawstring_write_multi_center
//% block="write strings %text centered on image %img=screen_image_picker at y %y with color %color=colorindexpicker in font %fi || with spacing %spacing"
//% text.shadow="variables_get" y.defl=0 color.defl=1 color.min=0 color.max=15 spacing.defl=1 fi.shadow="variables_get"
export function writeMultipleCenter(text: string[], img: Image,
y: number, color: color, fi: FontInfo,
y: number, color: number, fi: FontInfo,
spacing: number = 1)
: void {
if (!fi) {
Expand All @@ -292,7 +292,7 @@ namespace drawStrings {
* @param {number} x1 - Horizontal coordinate of top-left of bounding box.
* @param {number} y1 - Vertical coordinate of top-left of bounding box.
* @param {number} x2 - Horizontal coordinate of bottom-right of bounding box.
* @param {number} y2 - Horizontal coordinate of bottom-right of bounding box.
* @param {number} y2 - Vertical coordinate of bottom-right of bounding box.
* @param {TextAlignment} align - Alignment of text within bounding box.
* @param {number} color - Color to use when drawing.
* @param {FontInfo} fi - Font to use.
Expand Down
16 changes: 16 additions & 0 deletions drawStrings.createFontInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# createFontInfo function

Create a `FontInfo` object. Used in the Blocks interface.

```typescript
drawStrings.createFontInfo(font: FontName,
size: number = 0): FontInfo
```

## Parameters
- `font: FontName` A value from the [`FontName`](FontName.md) enum.
- `size: number` Multiplier for font. For example, to use a double-sized font, set `size` to 2.

## Return value

A `FontInfo` object representing the requested font.
15 changes: 15 additions & 0 deletions drawStrings.height.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# height function

Get the character height of the `FontInfo` object. Used in the Blocks interface.

```typescript
drawStrings.height(fi: FontInfo): number
```

## Parameters

- `fi: FontInfo` The `FontInfo` object of interest.

## Return value

A `number` representing the character height of the font used in the `FontInfo` object.
16 changes: 16 additions & 0 deletions drawStrings.width.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# width function

Calculate the width of a string in pixels. Used in the Blocks interface.

```typescript
drawStrings.width(text: string, fi: FontInfo): number
```

## Parameters

- `text: string` Text to measure.
- `fi: FontInfo` `FontInfo` object to use when calculating width.

## Return value

A `number` representing the width of the text in pixels.
17 changes: 17 additions & 0 deletions drawStrings.write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# write function

Draw a string on the given image.

```typescript
drawStrings.write(text: string, img: Image, x: number,
y: number, color: number, fi: FontInfo): void
```

## Parameters

- `text: string` String to draw.
- `img: Image` Drawing canvas.
- `x: number` Horizontal coordinate for top-left of string.
- `y: number` Vertical coordinate for top-left of string.
- `color: number` Color to use when drawing text.
- `fi: FontInfo` Font to use.
16 changes: 16 additions & 0 deletions drawStrings.writeCenter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# writeCenter function

Draw a string on the given image centered horizontally.

```typescript
drawStrings.writeCenter(text: string, img: Image,
y: number, color: number, fi: FontInfo): void
```

## Parameters

- `text: string` String to draw.
- `img: Image` Drawing canvas.
- `y: number` Vertical coordinate for top of string.
- `color: number` Color to use when drawing text.
- `fi: FontInfo` Font to use.
19 changes: 19 additions & 0 deletions drawStrings.writeMultiple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# writeMultiple function

Draw an array of strings on the given image.

```typescript
drawStrings.writeMultiple(text: string[], img: Image,
x: number, y: number,
color: number, fi: FontInfo, spacing: number = 1): void
```

## Parameters

- `text: string[]` Strings to draw.
- `img: Image` Drawing canvas.
- `x: number` Horizontal coordinate for top-left of string.
- `y: number` Vertical coordinate for top-left of string.
- `color: number` Color to use when drawing text.
- `fi: FontInfo` Font to use.
- `spacing: number` Number of pixels to skip between strings.
17 changes: 17 additions & 0 deletions drawStrings.writeMultipleCenter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# writeMultipleCenter function

Draw an array of strings on the given image centered horizontally.

```typescript
drawStrings.writeMultipleCenter(text: string[], img: Image,
y: number, color: number, fi: FontInfo): void
```

## Parameters

- `text: string[]` Strings to draw.
- `img: Image` Drawing canvas.
- `y: number` Vertical coordinate for top of first string.
- `color: number` Color to use when drawing text.
- `fi: FontInfo` Font to use.
- `spacing: number` Number of pixels to skip between strings.
28 changes: 28 additions & 0 deletions drawStrings.writeWrapped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# writeWrapped function

Wrap a string within a bounding box.

```typescript
drawStringswriteWrapped(text: string, img: Image,
x1: number, y1: number, x2: number, y2: number,
align: TextAlignment, color: number, fi: FontInfo,
startChar: number = 0, spacing: number = 0): number
```

## Parameters

- `text: string` String to draw.
- `img: Image` Drawing canvas.
- `x1: number` Horizontal coordinate of top-left of bounding box.
- `y1: number` Vertical coordinate of top-left of bounding box.
- `x2: number` Horizontal coordinate of bottom-right of bounding box.
- `y2: number` Vertical coordinate of bottom-right of bounding box.
- `align: TextAlignment` Value from the [`TextAlignment`](TextAlignment.md) enum for the alignment of text within bounding box.
- `color: number` Color to use when drawing text.
- `fi: FontInfo` Font to use.
- `startChar: number` Starting character of string.
- `spacing: number` Pixels to skip between lines.

## Return value

A `number` representing the next character that needs to be drawn; -1 if the text fits within bounding box.

0 comments on commit 72eff73

Please sign in to comment.