- Control ⇐
EventEmitter
- CM :
ConsoleManager
the instance of ConsoleManager (singleton)
- 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. |
Kind: global class
Extends: EventEmitter
- Control ⇐
EventEmitter
- new Control(config)
- .delete()
- .keyListener(_str, key)
- .getContent() ⇒
InPageWidgetBuilder
- .focus() ⇒
Control
- .unfocus() ⇒
Control
- .show() ⇒
Control
- .hide() ⇒
Control
- .isVisible() ⇒
boolean
- .isFocused() ⇒
boolean
- .manageInput() ⇒
Control
- .unManageInput() ⇒
Control
- .drawLine(line) ⇒
void
- .draw() ⇒
Control
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).
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()
This function is used to delete the Control and remove it from the ConsoleManager.
Kind: instance method of Control
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. |
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.
This function is used to get the visibility of the Control.
Kind: instance method of Control
Returns: boolean
-
The visibility of the Control.
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.
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.
the instance of ConsoleManager (singleton)
Kind: global constant