MenuBox
extends ListBox
in package
Creation of an interactive pseudo-GUI menu with elements such as buttons, radio buttons, checkboxes and some others
Table of Contents
- $AutoSizeEnabled : bool
- $CloseEvent : Closure|null
- $Id : string
- $ItemsContainerHeight : int
- $KeyPressEvent : Closure|null
- $OffsetChangedEvent : Closure|null
- $OpenEvent : Closure|null
- $ScrollDownCharacter : string
- $ScrollOffset : int
- $ScrollUpCharacter : string
- $SelectedItemChangedEvent : Closure|null
- $Title : string
- $defaultDisabledBackgroundColor : string
- $defaultDisabledForegroundColor : string
- $defaultItemBackgroundColor : string
- $defaultItemForegroundColor : string
- $defaultItemHeaderBackgroundColor : string
- $defaultItemHeaderForegroundColor : string
- $defaultRowHeaderItemDelimiterBackgroundColor : string
- $defaultRowHeaderItemDelimiterForegroundColor : string
- $items : array<string|int, mixed>
- $rowHeaderItemDelimiter : string
- $rowsHeaderType : string
- $titleBackgroundColor : string
- $titleForegroundColor : string
- __construct() : mixed
- MenuBox constructor.
- AddItem() : MenuBox
- Adds item to collection
- ClearItems() : MenuBox
- Clears items
- ClearResultOutput() : void
- Close() : void
- Closes menu
- Dispose() : void
- Disposes current MenuBox and makes unavailable for any actions
- GetCurrentActiveMenuBox() : MenuBox|null
- Finds and returns current active MenuBox. Returns NULL if no one MenuBox is running
- GetElementById() : MenuBoxControl|null
- Finds item by its ID and returns it. Return NULL if item with specified ID was not found.
- GetElementsByType() : array<string|int, MenuBoxControl>
- Returns a list of element of specified type
- GetItemNumberByItem() : int
- Returns sorted item number by item. Returns -1 if MenuBox doesn't contain this item.
- GetLastPressedKey() : string
- GetMenuBoxById() : MenuBox|null
- Finds and returns MenuBox with the same ID. Returns NULL if MenuBox not found.
- GetNumberedItems() : array<string|int, MenuBoxControl>
- GetResultOutput() : string
- GetSelectedItem() : MenuBoxItem|null
- Returns current selected item. If for some reason the current element is not selected, the method will automatically select the closest available one. If there are no such elements, it will return NULL
- GetSelectedItemNumber() : int|null
- GetSortedItems() : array<string|int, MenuBoxControl>
- GetThis() : object|null
- Returns your object which you passed in constructor
- HasItem() : bool
- Returns TRUE if this MenuBox contains this item
- IsClosed() : bool
- Returns TRUE if menu closed
- IsDisposed() : bool
- PreventNextRefresh() : void
- Prevents next container's refresh
- Refresh() : void
- Renders menu again
- RemoveItem() : void
- Removes item from this MenuBox
- Render() : void
- Builds and renders your menu and runs read-line to select menu item
- ResultOutput() : void
- Prints callback output of selected and called MenuBoxItem. It's recommended to use instead of Console::Write, because this method saves output after selecting another item.
- ResultOutputLine() : void
- Prints callback output of selected and called MenuBoxItem and moves caret to new line. It's recommended to use instead of Console::WriteLine, because this method saves output after selecting another item.
- SetDescription() : MenuBox
- Sets description for your menu, which will be displayed between title and items
- SetDescriptionStyle() : MenuBox
- Sets style for description
- SetRowHeaderItemDelimiter() : ListBox
- Sets delimiter between header and item (for example: ". ")
- SetRowHeaderItemDelimiterStyle() : ListBox
- Sets style for delimiter between header and item
- SetRowsHeaderType() : ListBox
- Sets header type for items
- SetSelectedItemNumber() : void
- Sets selected item number. If item with specified number doesn't exist, does nothing.
- SetTitleColor() : ListBox
- Set color of title. Use ForegroundColors and BackgroundColors enums
- SetZeroItem() : MenuBox
- Sets zero item to your menu
Properties
$AutoSizeEnabled
public
bool
$AutoSizeEnabled
= false
Is autosize mode enabled
$CloseEvent
public
Closure|null
$CloseEvent
= null
Menu is closing event handler. Function have to accept Events\MenuBoxCloseEvent
$Id
public
string
$Id
= ""
This ID is using to find your MenuBox. Not for anything else.
$ItemsContainerHeight
public
int
$ItemsContainerHeight
= 0
A count of items which can be rendered
$KeyPressEvent
public
Closure|null
$KeyPressEvent
= null
Key pressed event handler. Function have to accept Events\KeyPressEvent
$OffsetChangedEvent
public
Closure|null
$OffsetChangedEvent
= null
Offset changed event handler. Function have to accept Events\OffsetChangedEvent
$OpenEvent
public
Closure|null
$OpenEvent
= null
Menu is opening event handler. Function have to accept Events\MenuBoxOpenEvent
$ScrollDownCharacter
public
string
$ScrollDownCharacter
= "↓"
A character which displays in bottom of items container if there are items below
$ScrollOffset
public
int
$ScrollOffset
= 0
A scroll offset from top
$ScrollUpCharacter
public
string
$ScrollUpCharacter
= "↑"
A character which displays in top of items container if there are items above
$SelectedItemChangedEvent
public
Closure|null
$SelectedItemChangedEvent
= null
Selected item changed event handler. Function have to accept Events\SelectedItemChangedEvent
$Title
public
string
$Title
= ""
Title of box
$defaultDisabledBackgroundColor
protected
string
$defaultDisabledBackgroundColor
= \Data\String\BackgroundColors::AUTO
$defaultDisabledForegroundColor
protected
string
$defaultDisabledForegroundColor
= \Data\String\ForegroundColors::PURPLE
$defaultItemBackgroundColor
protected
string
$defaultItemBackgroundColor
= \Data\String\BackgroundColors::AUTO
$defaultItemForegroundColor
protected
string
$defaultItemForegroundColor
= \Data\String\ForegroundColors::PURPLE
$defaultItemHeaderBackgroundColor
protected
string
$defaultItemHeaderBackgroundColor
= \Data\String\BackgroundColors::AUTO
$defaultItemHeaderForegroundColor
protected
string
$defaultItemHeaderForegroundColor
= \Data\String\ForegroundColors::PURPLE
$defaultRowHeaderItemDelimiterBackgroundColor
protected
string
$defaultRowHeaderItemDelimiterBackgroundColor
= \Data\String\BackgroundColors::AUTO
$defaultRowHeaderItemDelimiterForegroundColor
protected
string
$defaultRowHeaderItemDelimiterForegroundColor
= \Data\String\ForegroundColors::PURPLE
$items
protected
array<string|int, mixed>
$items
= array()
Control items collection
$rowHeaderItemDelimiter
protected
string
$rowHeaderItemDelimiter
= ". "
$rowsHeaderType
protected
string
$rowsHeaderType
= \CliForms\Common\RowHeaderType::NUMERIC
$titleBackgroundColor
protected
string
$titleBackgroundColor
= \Data\String\BackgroundColors::AUTO
$titleForegroundColor
protected
string
$titleForegroundColor
= \Data\String\ForegroundColors::CYAN
Methods
__construct()
MenuBox constructor.
public
__construct(string $title, object $mythis) : mixed
Parameters
- $title : string
-
Title of menu
- $mythis : object
-
These arguments are using to access to your class from callback functions
Return values
mixed —AddItem()
Adds item to collection
public
AddItem(MenuBoxControl $item) : MenuBox
Parameters
- $item : MenuBoxControl
Tags
Return values
MenuBox —ClearItems()
Clears items
public
ClearItems([bool $removeZeroItem = true ]) : MenuBox
Parameters
- $removeZeroItem : bool = true
Tags
Return values
MenuBox —ClearResultOutput()
public
ClearResultOutput() : void
Tags
Return values
void —Clears result output
Close()
Closes menu
public
Close() : void
Tags
Return values
void —Dispose()
Disposes current MenuBox and makes unavailable for any actions
public
Dispose() : void
Tags
Return values
void —GetCurrentActiveMenuBox()
Finds and returns current active MenuBox. Returns NULL if no one MenuBox is running
public
static GetCurrentActiveMenuBox() : MenuBox|null
Return values
MenuBox|null —GetElementById()
Finds item by its ID and returns it. Return NULL if item with specified ID was not found.
public
GetElementById(string $id) : MenuBoxControl|null
Parameters
- $id : string
Tags
Return values
MenuBoxControl|null —GetElementsByType()
Returns a list of element of specified type
public
GetElementsByType(string $className) : array<string|int, MenuBoxControl>
Parameters
- $className : string
-
Full path to class. To simplify, you can pass
Checkbox::class
orLabel::class
Tags
Return values
array<string|int, MenuBoxControl> —GetItemNumberByItem()
Returns sorted item number by item. Returns -1 if MenuBox doesn't contain this item.
public
GetItemNumberByItem(MenuBoxControl $item) : int
Parameters
- $item : MenuBoxControl
Tags
Return values
int —GetLastPressedKey()
public
GetLastPressedKey() : string
Tags
Return values
string —Last pressed key on keyboard
GetMenuBoxById()
Finds and returns MenuBox with the same ID. Returns NULL if MenuBox not found.
public
static GetMenuBoxById(string $id) : MenuBox|null
Parameters
- $id : string
Return values
MenuBox|null —GetNumberedItems()
public
GetNumberedItems([bool $includeZeroItem = true ]) : array<string|int, MenuBoxControl>
Parameters
- $includeZeroItem : bool = true
-
Includes zero item. Attention! If you exclude zero item, the first index of array will be "1", not "0"
Tags
Return values
array<string|int, MenuBoxControl> —Numbered items. Element with 0 index is zero item (or null)
GetResultOutput()
public
GetResultOutput() : string
Tags
Return values
string —Result output
GetSelectedItem()
Returns current selected item. If for some reason the current element is not selected, the method will automatically select the closest available one. If there are no such elements, it will return NULL
public
GetSelectedItem() : MenuBoxItem|null
Tags
Return values
MenuBoxItem|null —GetSelectedItemNumber()
public
GetSelectedItemNumber() : int|null
Tags
Return values
int|null —Selected item number. If for some reason the current element is not selected, the method will automatically select the closest available one. If there are no such elements, it will return NULL
GetSortedItems()
public
GetSortedItems([bool $includeZeroItem = true ]) : array<string|int, MenuBoxControl>
Parameters
- $includeZeroItem : bool = true
-
Includes zero item. Attention! If you exclude zero item, the first index of array will be "1", not "0"
Tags
Return values
array<string|int, MenuBoxControl> —Sorted and numbered items. Element with 0 index is still zero item (or null). Please note that the indexes of this method are different from those of the GetNumberedItems method.
GetThis()
Returns your object which you passed in constructor
public
GetThis() : object|null
Tags
Return values
object|null —HasItem()
Returns TRUE if this MenuBox contains this item
public
HasItem(MenuBoxControl $control) : bool
Parameters
- $control : MenuBoxControl
Tags
Return values
bool —IsClosed()
Returns TRUE if menu closed
public
IsClosed() : bool
Tags
Return values
bool —IsDisposed()
public
IsDisposed() : bool
Return values
bool —TRUE if current MenuBox is disposed
PreventNextRefresh()
Prevents next container's refresh
public
PreventNextRefresh() : void
Return values
void —Refresh()
Renders menu again
public
Refresh() : void
Tags
Return values
void —RemoveItem()
Removes item from this MenuBox
public
RemoveItem(MenuBoxControl $control) : void
Parameters
- $control : MenuBoxControl
Tags
Return values
void —Render()
Builds and renders your menu and runs read-line to select menu item
public
Render() : void
Tags
Return values
void —ResultOutput()
Prints callback output of selected and called MenuBoxItem. It's recommended to use instead of Console::Write, because this method saves output after selecting another item.
public
ResultOutput(string $text[, ForegroundColors $foregroundColor = ForegroundColors::AUTO ][, BackgroundColors $backgroundColor = BackgroundColors::AUTO ]) : void
Parameters
- $text : string
- $foregroundColor : ForegroundColors = ForegroundColors::AUTO
- $backgroundColor : BackgroundColors = BackgroundColors::AUTO
Tags
Return values
void —ResultOutputLine()
Prints callback output of selected and called MenuBoxItem and moves caret to new line. It's recommended to use instead of Console::WriteLine, because this method saves output after selecting another item.
public
ResultOutputLine(string $text[, ForegroundColors $foregroundColor = ForegroundColors::AUTO ][, BackgroundColors $backgroundColor = BackgroundColors::AUTO ]) : void
Parameters
- $text : string
- $foregroundColor : ForegroundColors = ForegroundColors::AUTO
- $backgroundColor : BackgroundColors = BackgroundColors::AUTO
Tags
Return values
void —SetDescription()
Sets description for your menu, which will be displayed between title and items
public
SetDescription([string $description = "" ]) : MenuBox
Parameters
- $description : string = ""
Tags
Return values
MenuBox —SetDescriptionStyle()
Sets style for description
public
SetDescriptionStyle(string $foregroundColor[, string $backgroundColor = BackgroundColors::AUTO ]) : MenuBox
Parameters
- $foregroundColor : string
- $backgroundColor : string = BackgroundColors::AUTO
Tags
Return values
MenuBox —SetRowHeaderItemDelimiter()
Sets delimiter between header and item (for example: ". ")
public
SetRowHeaderItemDelimiter(string $delimiter) : ListBox
Parameters
- $delimiter : string
Return values
ListBox —SetRowHeaderItemDelimiterStyle()
Sets style for delimiter between header and item
public
SetRowHeaderItemDelimiterStyle(string $foregroundColor, string $backgroundColor) : ListBox
Parameters
- $foregroundColor : string
- $backgroundColor : string
Return values
ListBox —SetRowsHeaderType()
Sets header type for items
public
SetRowsHeaderType(RowHeaderType $headerType) : ListBox
Parameters
- $headerType : RowHeaderType
Tags
Return values
ListBox —SetSelectedItemNumber()
Sets selected item number. If item with specified number doesn't exist, does nothing.
public
SetSelectedItemNumber(int $itemNumber) : void
Parameters
- $itemNumber : int
Tags
Return values
void —SetTitleColor()
Set color of title. Use ForegroundColors and BackgroundColors enums
public
SetTitleColor(ForegroundColors $foregroundColor[, BackgroundColors $backgroundColor = "" ]) : ListBox
Parameters
- $foregroundColor : ForegroundColors
- $backgroundColor : BackgroundColors = ""
Return values
ListBox —SetZeroItem()
Sets zero item to your menu
public
SetZeroItem(MenuBoxItem|null $item) : MenuBox
Parameters
- $item : MenuBoxItem|null