Skip to content

Latest commit

 

History

History
213 lines (164 loc) · 8.33 KB

Control.md

File metadata and controls

213 lines (164 loc) · 8.33 KB

Classes

ControlEventEmitter

Constants

CM : ConsoleManager

the instance of ConsoleManager (singleton)

Interfaces

ControlConfig : Object

ControlConfig : Object

Kind: global interface
Properties

Name Type Default Description
id string

The id of the control.

attributes PhisicalValues

The phisical values of the control.

children InPageWidgetBuilder

The children of the control.

[visible] boolean true

If the control is visible or not.

[draggable] boolean false

If the control is draggable or not.

Control ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new Control(config)

This class is used to create a custom control (widget) with That is showed in a absolute position on the screen. It's a base class for all the controls (widgets).

Emits the following events:

  • "mouse": It carries the pure mouse event, but it fires only if the mouse is over the control.
  • "relativeMouse": It's like the "mouse" event, but it carries the relative mouse X and Y (relative to the control).

InPageWidget

Emits the following events:

Param Type Description
config ControlConfig

The configuration object for the control.

Example

const widget1 = new InPageWidgetBuilder()
widget1.addRow({ text: "┌────────┐", color: "yellow", style: "bold" })
widget1.addRow({ text: "│ START! │", color: "yellow", style: "bold" })
widget1.addRow({ text: "└────────┘", color: "yellow", style: "bold" })

const button1 = new Control({
   id: "btn1",
   visible: false,
   attributes: { x: 30, y: 18, width: 10, height: 3 },
   children: widget1
})
button1.on("relativeMouse", (event) => {
    // The relative mouse event is triggered with the mouse position relative to the widget
    //console.log(`Mouse event: x: ${event.data.x}, y: ${event.data.y}`)
    if (event.name === "MOUSE_LEFT_BUTTON_RELEASED") {
        GUI.log("Button 1 clicked!")
        if (valueEmitter) {
            clearInterval(valueEmitter)
            valueEmitter = null
        } else {
            valueEmitter = setInterval(frame, period)
        }
    }
})
button1.show()

control.delete()

This function is used to delete the Control and remove it from the ConsoleManager.

Kind: instance method of Control

control.keyListener(_str, key)

This function is used to make the ConsoleManager handle the key events when the popup is showed. Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed.

Kind: instance method of Control

Param Type Description
_str string

The string of the input.

key any

The key object.

control.getContent() ⇒ InPageWidgetBuilder

This function is used to get the content of the Control.

Kind: instance method of Control
Returns: InPageWidgetBuilder -

The content of the Control.


Example

const content = control.getContent()

control.focus() ⇒ Control

This function is used to focus the Control. It also register the key events.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


control.unfocus() ⇒ Control

This function is used to unfocus the Control. It also unregister the key events.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


control.show() ⇒ Control

This function is used to show the Control. It also register the mouse events and refresh the ConsoleManager.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


control.hide() ⇒ Control

This function is used to hide the Control. It also unregister the mouse events and refresh the ConsoleManager.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


control.isVisible() ⇒ boolean

This function is used to get the visibility of the Control.

Kind: instance method of Control
Returns: boolean -

The visibility of the Control.


control.isFocused() ⇒ boolean

This function is used to get the focus status of the Control.

Kind: instance method of Control
Returns: boolean -

The focused status of the Control.


control.manageInput() ⇒ Control

This function is used to add the Control key listener callback to te ConsoleManager.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


control.unManageInput() ⇒ Control

This function is used to remove the Control key listener callback to te ConsoleManager.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


control.drawLine(line) ⇒ void

This function is used to draw a single line of the widget to the screen. It also trim the line if it is too long.

Kind: instance method of Control

Param Type Description
line Array.<StyledElement>

the line to be drawn

control.draw() ⇒ Control

This function is used to draw the Control to the screen in the middle.

Kind: instance method of Control
Returns: Control -

The instance of the Control.


CM : ConsoleManager

the instance of ConsoleManager (singleton)

Kind: global constant