Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TestWidget<S>

Type parameters

  • S

Hierarchy

Index

Constructors

constructor

Methods

absoluteToLocal

addChild

  • addChild<T>(child: T): T
  • Adds a child widget to this widget. Removes any existing parent from the child first.

    Type parameters

    Parameters

    • child: T

      The child widget

    Returns T

    The child widget

cascadeDraw

  • cascadeDraw(): void
  • Calls the draw() method of this widget and all children widgets recursively. If a widget is disabled it will stop the cascade.

    Returns void

cascadeMouseClick

  • Sends a mouse event through a tree of Widgets. If any widget's onMouseClick returns true, the event will be captured and stop cascading.

    Widgets are called in reverse order, so the last one to render will be the first one called for onMouseClick.

    Parameters

    Returns boolean

cascadeUpdate

  • cascadeUpdate(): void
  • Calls update() for this widget and all children widgets recursively. Children added last will be called last. If a widget is disabled, the update will stop there.

    Returns void

clearMouseContext

  • clearMouseContext(): this

clearUpdateFunc

  • clearUpdateFunc(): this

draw

  • draw(): void
  • Draws on to the given terminal using the widget's current state. Will not draw if disabled.

    Returns void

drawGlyph

getAbsoluteOrigin

getOrigin

getState

  • getState(): S
  • Gets the current state of the widget. While not a copy, it's recommended to use setState rather than mutate this object.

    Returns S

isDisabled

  • isDisabled(): boolean

localToAbsolute

mouseClick

onDraw

  • onDraw(): void

onMouseClick

  • Will be fired on click() or cascadeClick(). Return 'true' to capture the event, which will make it no longer cascade to other widgets. Return 'false' to pass the event to other widgets.

    Parameters

    Returns boolean

    boolean - Capture the event

registerMouseContext

removeChild

  • removeChild<T>(child: T): T | undefined
  • Removes a child widget from the parent widget. Clears inherited Terminal/MouseHandler/KeyboardHandler

    Type parameters

    Parameters

    • child: T

      The child widget

    Returns T | undefined

    The child widget if found, undefined otherwise.

setDisabled

  • setDisabled(disabled?: boolean): this
  • Sets the disabled state.

    Parameters

    • Default value disabled: boolean = true

      Default true

    Returns this

    • The Widget

setMouseHandler

  • Sets the mouseHandler for this widget and all children widgets. Will be passed to any children added in the future as well.

    Parameters

    Returns this

    this

setOrigin

  • Sets the local origin of the widget relative to it's parent, then updates the absoluteOrigin of the widget

    Parameters

    • origin: Vector2

      Vector2 - The position relative to its parent

    Returns this

    • The widget

setParent

  • setParent<T>(parent: T): this

setState

  • setState(state: Partial<S>): this
  • Sets the state of the widget. Partial values allowed.

    Parameters

    • state: Partial<S>

      Partial

    Returns this

    • The widget

setTerminal

  • Sets the terminal for this widget and all children widgets. Will be passed to any children added in the future as well.

    Parameters

    Returns this

    this

setUpdateFunc

  • Set a function to run whenever update or cascadeUpdate is called. Generally this is used with closures/currying to transform game state to function state.

    Parameters

    Returns this

    The widget

update

  • update(): void
  • Calls an updateFunc if previously given, and merges it into the widgets state.

    Returns void

Generated using TypeDoc