Elius94 / console-gui-tools

A simple library to draw option menu or other popup inputs and layout on Node.js console.
MIT License
106 stars 17 forks source link

Elius94/issue22 #45

Closed Elius94 closed 1 year ago

Elius94 commented 1 year ago

ADDED IN PAGE WIDGET

And cleaned code

Control ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new Control(id, visible, attributes, children)

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:

InPageWidget

Emits the following events:

Param Type Description
id string

The id of the popup.

visible boolean

If the popup is visible. Default is false (make it appears using show()).

attributes PhisicalValues

The phisical values of the control (x, y, width, height).

children InPageWidgetBuilder

The content of 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("btn1", false, { x: 30, y: 18, width: 10, height: 3 }, 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()