A modern UI library for kaboom.
npm i kaboom-flex-ui
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!".
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.
Function | Type |
---|---|
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.
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.
Function | Type |
---|---|
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.
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.
Function | Type |
---|---|
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.
Creates a UI box element with optional attributes and children elements. Creates a UI box element with specified attributes and optional children elements.
Function | Type |
---|---|
$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.
Creates a UI box element with optional attributes and children elements. Creates a UI box element with specified attributes and optional children elements.
Function | Type |
---|---|
$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.
Creates a UI box element with optional attributes and children elements. Creates a UI box element with specified attributes and optional children elements.
Function | Type |
---|---|
$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.
Creates a UI text element with the specified text and optional attributes.
Function | Type |
---|---|
$text |
(text: string, attrs?: Partial<UITextAttributes>) => UITextElement |
Parameters:
text
: The text content.attrs
: Optional attributes for the text element.
Creates a UI button element with the specified text and attributes.
Function | Type |
---|---|
$button |
(text: string, attrs: UIButtonAttributes) => UIBoxElement |
Parameters:
text
: The text content.attrs
: The attributes for the button element.
Represents a checkbox element generator function.
Function | Type |
---|---|
$checkbox |
(attrs: UICheckboxAttributes) => UIBoxElement |
Parameters:
attrs
: The attributes for the checkbox element.
Represents an input element generator function.
Function | Type |
---|---|
$input |
(attrs: UIInputAttributes) => UIBoxElement |
Parameters:
attrs
: The attributes for the input element.
A plugin that provides UI generation functionality.
Function | Type |
---|---|
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.
Represents a UI text element with specified attributes.
Method | Type |
---|---|
setParent |
(parent: UIManager) => void |
Method | Type |
---|---|
style |
(newAttributes: Partial<UITextAttributes>) => void |
Method | Type |
---|---|
setText |
(text: string) => void |
Method | Type |
---|---|
setKaboom |
(kaboom: KaboomCtx) => void |
Method | Type |
---|---|
getKaboom |
() => KaboomCtx |
Represents a UI box element with specified attributes and children elements.
Method | Type |
---|---|
triggerListener |
(event: string, ...args: any) => void |
Method | Type |
---|---|
setParent |
(parent: UIManager) => void |
Method | Type |
---|---|
style |
(newAttributes: Partial<UIBoxAttributes>) => void |
Method | Type |
---|---|
getChild |
<U extends UIElement = UIElement>(nth: number) => UIElementPublic<U> |
Method | Type |
---|---|
setKaboom |
(kaboom: KaboomCtx) => void |
Method | Type |
---|---|
getKaboom |
() => KaboomCtx |