Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elius94/issue22 #45

Merged
merged 9 commits into from Nov 19, 2022
Merged

Elius94/issue22 #45

merged 9 commits into from Nov 19, 2022

Conversation

Elius94
Copy link
Owner

@Elius94 Elius94 commented Nov 19, 2022

#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:

  • "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
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()

Fixes #22

Added override console log option:
It can be used to log into the log page using the standard log functuins
(console.log(), etc...)
It's an alisas (extended class) for PageBuilder
Moved inside it:
Style types and drawing chars.
changed his reference and other refactoring
Now they are using the new features of the ConsoleManager.
Divided widgetsCollection into one for popups and other for controls
Now they are using the new features of the ConsoleManager.
Divided widgetsCollection into one for popups and other for controls
It's the base for creating widgets.
@Elius94 Elius94 merged commit 0e8b743 into main Nov 19, 2022
@Elius94 Elius94 deleted the Elius94/issue22 branch November 19, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant