nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
MenuItem Struct Reference

Simplest type of item possible, with a label and user-defined id. More...

#include <MenuItem.hpp>

Inheritance diagram for MenuItem:

Public Types

enum  MenuItemType {
  ITEM , LABEL , CHECKBOX , NUMBERBOX ,
  TEXTBOX , TEXTLIST
}
 All possible item types. More...
 

Public Member Functions

 MenuItem (std::string label, int id)
 Create a MenuItem, with user-defined id.
 
virtual void draw (Window *window, int x, int y, int width, bool hilite=false)
 Shows this item at #x, #y with #width.
 
virtual void handleInput ()
 Makes the menu item react to input, as seen on the global InputManager.
 

Public Attributes

MenuItemType type
 Specific type of this widget.
 
std::string label
 Text that will be shown on the screen.
 
int id
 User-defined id to identify this item.
 

Detailed Description

Simplest type of item possible, with a label and user-defined id.

Definition at line 11 of file MenuItem.hpp.

Member Enumeration Documentation

◆ MenuItemType

All possible item types.

When inheriting and creating your own, make sure to place it here.

Definition at line 17 of file MenuItem.hpp.

Constructor & Destructor Documentation

◆ MenuItem()

MenuItem::MenuItem ( std::string label,
int id )

Create a MenuItem, with user-defined id.

Note
MenuItems on the same menu should have different id s! If not, results are unpredictable.

Definition at line 6 of file MenuItem.cpp.

◆ ~MenuItem()

virtual MenuItem::~MenuItem ( )
inlinevirtual

Definition at line 28 of file MenuItem.hpp.

Member Function Documentation

◆ draw()

void MenuItem::draw ( Window * window,
int x,
int y,
int width,
bool hilite = false )
virtual

Shows this item at #x, #y with #width.

If this is the current item, send #hilite as true.

Note
Yeah, height is always 1.

Reimplemented in MenuItemCheckbox, MenuItemLabel, MenuItemNumberbox, MenuItemTextbox, and MenuItemTextlist.

Definition at line 12 of file MenuItem.cpp.

◆ handleInput()

void MenuItem::handleInput ( )
virtual

Makes the menu item react to input, as seen on the global InputManager.

Each type of MenuItem might react to input differently. A text box might want to show printable characters, a check box might want to check if space bar was pressed, whatever.

When inheriting this, make sure to implement it.

Reimplemented in MenuItemCheckbox, MenuItemLabel, MenuItemNumberbox, MenuItemTextbox, and MenuItemTextlist.

Definition at line 19 of file MenuItem.cpp.

Member Data Documentation

◆ id

int MenuItem::id

User-defined id to identify this item.

Definition at line 57 of file MenuItem.hpp.

◆ label

std::string MenuItem::label

Text that will be shown on the screen.

Definition at line 54 of file MenuItem.hpp.

◆ type

MenuItemType MenuItem::type

Specific type of this widget.

Note
It is set on the Constructor, don't change it manually!

Definition at line 51 of file MenuItem.hpp.


The documentation for this struct was generated from the following files: