0.0.8 • Published 4 months ago

kaboom-flex-ui v0.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Kaboom Flex UI

A modern UI library for kaboom.

Installation

npm i kaboom-flex-ui

Getting Started

Firstly, import the UI plugin and load it into kaboom.

import flexUIPlugin from "kaboom-flex-ui";

const k = kaboom({
    plugins: [ flexUIPlugin ]
});

Then, to create a UI you will have to call the makeUI function with a function that returns a UI element.

const mainMenu = k.makeUI(() => k.$box(
    {
        width: 500,
        height: 500,
        background: YELLOW
    },
    k.$text("Hello, World!")
));

After defining the UI you will have to add it the current scene using its add method.

mainMenu.add();

After a reload you should now see a yellow rectangle on your screen with the text "Hello, World!".

Docs

:toolbox: Functions

:gear: makeUI

Takes in a Kaboom context and a UI generator function, returning a UI manager. The UI manager allows addition, removal, and re-addition of UI elements. Takes in a UI generator function that creates a UI element and returns a UI manager. The UI manager enables addition, removal, and re-addition of the UI.

FunctionType
makeUI{ (kaboom: KaboomCtx, generator: UIGenerator): UIManager; (generator: UIGenerator): UIManager; }

Parameters:

  • kaboom: The Kaboom context used for UI creation.
  • generator: The UI generator function that generates a UI element.
  • generator: The UI generator function that generates a UI element.

:gear: makeUI

Takes in a Kaboom context and a UI generator function, returning a UI manager. The UI manager allows addition, removal, and re-addition of UI elements. Takes in a UI generator function that creates a UI element and returns a UI manager. The UI manager enables addition, removal, and re-addition of the UI.

FunctionType
makeUI{ (kaboom: KaboomCtx, generator: UIGenerator): UIManager; (generator: UIGenerator): UIManager; }

Parameters:

  • kaboom: The Kaboom context used for UI creation.
  • generator: The UI generator function that generates a UI element.
  • generator: The UI generator function that generates a UI element.

:gear: makeUI

Takes in a Kaboom context and a UI generator function, returning a UI manager. The UI manager allows addition, removal, and re-addition of UI elements. Takes in a UI generator function that creates a UI element and returns a UI manager. The UI manager enables addition, removal, and re-addition of the UI.

FunctionType
makeUI{ (kaboom: KaboomCtx, generator: UIGenerator): UIManager; (generator: UIGenerator): UIManager; }

Parameters:

  • kaboom: The Kaboom context used for UI creation.
  • generator: The UI generator function that generates a UI element.
  • generator: The UI generator function that generates a UI element.

:gear: $box

Creates a UI box element with optional attributes and children elements. Creates a UI box element with specified attributes and optional children elements.

FunctionType
$box{ (...children: UIElement[]): UIBoxElement; (attrs: Partial<UIBoxAttributes>, ...children: UIElement[]): UIBoxElement; }

Parameters:

  • children: The children UI elements.
  • attrs: The attributes for the box element.
  • children: The children UI elements.

:gear: $box

Creates a UI box element with optional attributes and children elements. Creates a UI box element with specified attributes and optional children elements.

FunctionType
$box{ (...children: UIElement[]): UIBoxElement; (attrs: Partial<UIBoxAttributes>, ...children: UIElement[]): UIBoxElement; }

Parameters:

  • children: The children UI elements.
  • attrs: The attributes for the box element.
  • children: The children UI elements.

:gear: $box

Creates a UI box element with optional attributes and children elements. Creates a UI box element with specified attributes and optional children elements.

FunctionType
$box{ (...children: UIElement[]): UIBoxElement; (attrs: Partial<UIBoxAttributes>, ...children: UIElement[]): UIBoxElement; }

Parameters:

  • children: The children UI elements.
  • attrs: The attributes for the box element.
  • children: The children UI elements.

:gear: $text

Creates a UI text element with the specified text and optional attributes.

FunctionType
$text(text: string, attrs?: Partial<UITextAttributes>) => UITextElement

Parameters:

  • text: The text content.
  • attrs: Optional attributes for the text element.

:gear: $button

Creates a UI button element with the specified text and attributes.

FunctionType
$button(text: string, attrs: UIButtonAttributes) => UIBoxElement

Parameters:

  • text: The text content.
  • attrs: The attributes for the button element.

:gear: $checkbox

Represents a checkbox element generator function.

FunctionType
$checkbox(attrs: UICheckboxAttributes) => UIBoxElement

Parameters:

  • attrs: The attributes for the checkbox element.

:gear: $input

Represents an input element generator function.

FunctionType
$input(attrs: UIInputAttributes) => UIBoxElement

Parameters:

  • attrs: The attributes for the input element.

:gear: default

A plugin that provides UI generation functionality.

FunctionType
default(ctx: KaboomCtx) => { readonly makeUI: { (kaboom: KaboomCtx, generator: UIGenerator): UIManager; (generator: UIGenerator): UIManager; }; ... 4 more ...; readonly $input: (attrs: UIInputAttributes) => UIBoxElement; }

Parameters:

  • ctx: The Kaboom context.

:factory: UITextElement

Represents a UI text element with specified attributes.

Methods

:gear: setParent

MethodType
setParent(parent: UIManager) => void

:gear: style

MethodType
style(newAttributes: Partial<UITextAttributes>) => void

:gear: setText

MethodType
setText(text: string) => void

:gear: setKaboom

MethodType
setKaboom(kaboom: KaboomCtx) => void

:gear: getKaboom

MethodType
getKaboom() => KaboomCtx

:factory: UIBoxElement

Represents a UI box element with specified attributes and children elements.

Methods

:gear: triggerListener

MethodType
triggerListener(event: string, ...args: any) => void

:gear: setParent

MethodType
setParent(parent: UIManager) => void

:gear: style

MethodType
style(newAttributes: Partial<UIBoxAttributes>) => void

:gear: getChild

MethodType
getChild<U extends UIElement = UIElement>(nth: number) => UIElementPublic<U>

:gear: setKaboom

MethodType
setKaboom(kaboom: KaboomCtx) => void

:gear: getKaboom

MethodType
getKaboom() => KaboomCtx
0.0.8

4 months ago

0.0.7

5 months ago

0.0.3

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.6

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago