Skip to content

Latest commit

 

History

History
186 lines (139 loc) · 7.54 KB

OptionPopup.md

File metadata and controls

186 lines (139 loc) · 7.54 KB

Classes

OptionPopupEventEmitter

Members

x : number

The x offset of the popup to be drown. If 0 it will be placed on the center

y : number

The y offset of the popup to be drown. If 0 it will be placed on the center

Constants

CM : ConsoleManager

the instance of ConsoleManager (singleton)

Interfaces

OptionPopupConfig : Object

The configuration for the OptionPopup class.

OptionPopupConfig : Object

The configuration for the OptionPopup class.

Kind: global interface
Properties

Name Type Description
id string

The id of the popup.

title string

The title of the popup.

options Array.<(string|number)>

The options of the popup.

selected string | number

The selected option of the popup.

[visible] boolean

If the popup is visible.

OptionPopup ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new OptionPopup(id, title, options, selected, visible)

This class is used to create a popup with a list of selectable options.

OptionPopup

Emits the following events:

  • "confirm" when the user confirm the option
  • "cancel" when the user cancel the option
  • "exit" when the user exit the option
Param Type Description
id string

The id of the popup.

title string

The title of the popup.

options Array.<(string|number)>

The options of the popup.

selected string | number

The selected option.

visible boolean

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

Example

const popup = new OptionPopup({
 id:"popup1", 
 title: "Choose the option", 
 options, 
 selected
}).show().on("confirm", (option) => { console.log(option) }) // show the popup and wait for the user to confirm

optionPopup.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 OptionPopup

Param Type Description
str string

The string of the input.

key Object

The key object.

optionPopup.getSelected() ⇒ string | number

This function is used to get the selected option.

Kind: instance method of OptionPopup
Returns: string | number -

The selected value of the popup.


optionPopup.setSelected(selected) ⇒ OptionPopup

This function is used to change the selection of the popup. It also refresh the ConsoleManager.

Kind: instance method of OptionPopup
Returns: OptionPopup -

The instance of the OptionPopup.

Param Type Description
selected string | number

The new value of the selection.

optionPopup.show() ⇒ OptionPopup

This function is used to show the popup. It also register the key events and refresh the ConsoleManager.

Kind: instance method of OptionPopup
Returns: OptionPopup -

The instance of the OptionPopup.


optionPopup.hide() ⇒ OptionPopup

This function is used to hide the popup. It also unregister the key events and refresh the ConsoleManager.

Kind: instance method of OptionPopup
Returns: OptionPopup -

The instance of the OptionPopup.


optionPopup.isVisible() ⇒ boolean

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

Kind: instance method of OptionPopup
Returns: boolean -

The visibility of the popup.


optionPopup.manageInput() ⇒ OptionPopup

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

Kind: instance method of OptionPopup
Returns: OptionPopup -

The instance of the OptionPopup.


optionPopup.unManageInput() ⇒ OptionPopup

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

Kind: instance method of OptionPopup
Returns: OptionPopup -

The instance of the OptionPopup.


optionPopup.draw() ⇒ OptionPopup

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

Kind: instance method of OptionPopup
Returns: OptionPopup -

The instance of the OptionPopup.


x : number

The x offset of the popup to be drown. If 0 it will be placed on the center

Kind: global variable

y : number

The y offset of the popup to be drown. If 0 it will be placed on the center

Kind: global variable

CM : ConsoleManager

the instance of ConsoleManager (singleton)

Kind: global constant