UNPKG

@dcgw/excalibur-extended-label

Version:

Excalibur's Label class, but with extra features

147 lines (146 loc) 5.11 kB
import { Actor, BaseAlign, Color, FontStyle, TextAlign, Vector } from "excalibur"; export interface LabelOptions { /** The text to draw. */ readonly text?: string; /** The CSS font family string (e.g. `sans-serif`, `Droid Sans Pro`). Web * fonts are supported, same as in CSS. */ readonly fontFamily?: string; /** The font style for the label. * * @default FontStyle.Normal */ readonly fontStyle?: FontStyle; /** True if the text is bold. * * @default false */ readonly bold?: boolean; /** The font size in pixels. * * @default 10 */ readonly fontSize?: number; /** Horizontal text alignment. * * @default TextAlign.Left */ readonly textAlign?: TextAlign; /** Baseline alignment. * * @default BaseAlign.Alphabetic */ readonly baseAlign?: BaseAlign; /** The height of each line of text in pixels, for multiline text. * * Set to `undefined` to use the font size as the line height. * * @default undefined */ readonly lineHeight?: number; /** The maximum width of a line of text, in pixels, after which the text * will wrap to the next line. * * Set to `Infinity` to disable text wrapping. * * @default Infinity */ readonly wrapWidth?: number; /** The position of the text in pixels. */ readonly pos?: Vector; /** The velocity of the text in pixels per second. */ readonly vel?: Vector; /** The acceleration of the text in pixels per second per second. */ readonly acc?: Vector; /** The rotation of the text in radians. */ readonly rotation?: number; /** The rotational velocity of the text in radians per second. */ readonly rx?: number; /** True if the text is visible, false if it is invisible. * * @default true */ readonly visible?: boolean; /** The color of the text. */ readonly color?: Color; /** The color of the text outline. Set to Color.Transparent to hide the outline. * * @default Color.Transparent */ readonly outlineColor?: Color; /** The width of the text outline, in pixels. Set to 0 to hide the outline. * * @default 0 */ readonly outlineWidth?: number; /** Overall opacity of the label, from 0 to 1. * * @default 1 */ readonly alpha?: number; /** Do not use. * * @deprecated This field has an unwanted and confusing interaction with * the underlying Actor class. * * @see https://github.com/excaliburjs/Excalibur/issues/874#issuecomment-814557137 */ readonly opacity?: number; /** The color of the shadow. Set to Color.Transparent to hide the shadow. * * @default Color.Transparent */ readonly shadowColor?: Color; /** The offset of the shadow from the text, in pixels. * * @default Vector.Zero */ readonly shadowOffset?: Vector; /** Radius of the shadow blur in pixels. * * @default 0 */ readonly shadowBlurRadius?: number; } export default class Label extends Actor { /** The text to draw. */ text: string; /** True if the text is bold. * * @default false */ bold: boolean; /** The CSS font family string (e.g. `sans-serif`, `Droid Sans Pro`). Web fonts * are supported, same as in CSS. */ fontFamily: string; /** Font size in the selected units (`fontUnit`). * * @default 10 */ fontSize: number; /** The font style for this label * * @default FontStyle.Normal */ fontStyle: FontStyle; /** Horizontal text alignment. * * @default TextAlign.Left */ textAlign: TextAlign; /** Vertical baseline text alignment. * * @default BaseAlign.Bottom */ baseAlign: BaseAlign; /** The height of each line of text in pixels, for multiline text. * * Set to `undefined` to use the font size as the line height. */ lineHeight: number | undefined; /** The maximum width of a line of text, in pixels, after which the text * will wrap to the next line. * * Set to `Infinity` to disable text wrapping. */ wrapWidth: number; /** The color of the text outline. Set to Color.Transparent to hide the outline. */ outlineColor: Color; /** The width of the text outline, in pixels. Set to 0 to hide the outline. */ outlineWidth: number; /** The color of the shadow. Set to Color.Transparent to hide the shadow. */ shadowColor: Color; /** The offset of the shadow from the text, in pixels. */ shadowOffset: Vector; /** Radius of the shadow blur in pixels. */ shadowBlurRadius: number; /** Overall opacity of the label, from 0 to 1. */ alpha: number; /** Do not use. * * @deprecated This field has an unwanted and confusing interaction with * the underlying Actor class. * * @see https://github.com/excaliburjs/Excalibur/issues/874#issuecomment-814557137 */ opacity: number; constructor(options?: LabelOptions); draw(context: CanvasRenderingContext2D, delta: number): void; private wrapLines; }