JMgui
Loading...
Searching...
No Matches
ListMenu Class Reference

#include <JMgui.h>

Inheritance diagram for ListMenu:
GuiElement

Classes

class  ItemSelectedEvent
class  ItemDeselectedEvent

Public Member Functions

 ListMenu (float PosX, float PosY, float SizeX, float SizeY)
 ListMenu (float PosX, float PosY, float SizeX, float SizeY, std::string Title)
void render ()
 draw the element to the buffer. Override this to make the element custom.
std::string addItem (std::string itemName)
 Adds a new item to the list. Returns the new item's name. If the item is a duplicate, the name will have a number added to it.
void removeItem (std::string itemName)
 Removed an item from the list by name.
void removeAllItems ()
 Removes all items from the list.
std::string selected () const
 returns the primary selection.
bool isSecondSelected (std::string itemName)
 returns true if the item is second selected.
bool addItemSelectedEventListener (std::string itemName, std::function< void(JMeventDispatcher::Event *)> func)
 add an event listener for when a specific item is selected. Returns true if the item exists and the listener was added.
bool addItemDeselectedEventListener (std::string itemName, std::function< void(JMeventDispatcher::Event *)> func)
 add an event listener for when a specific item is deselected. Returns true if the item exists and the listener was added.
bool selectItem (std::string itemName)
 selects an item by name. If another item is already selected, the item will be second-selected
bool deselectItem (std::string itemName)
 deselects an item by name.
bool selectItemWithoutEvent (std::string itemName)
 selects an item by name. If another item is already selected, the item will be second-selected. Doesn't trigger event.
bool deselectItemWithoutEvent (std::string itemName)
 deselects an item by name. Doesn't trigger event.
bool selectItem (int index)
 selects an item by index. If another item is already selected, the item will be second-selected
bool deselectItem (int inex)
 deselects an item by index.
bool selectItemWithoutEvent (int index)
 selects an item by index. If another item is already selected, the item will be second-selected. Doesn't trigger event.
bool deselectItemWithoutEvent (int index)
 deselects an item by index. Doesn't trigger event.
void deselectAll ()
 de-selects all the items and clears the selectedItems vector.
void deselectAllWithoutEvent ()
 de-selects all the items and clears the selectedItems vector. Doesn't trigger events.
Public Member Functions inherited from GuiElement
 GuiElement (float PosX, float PosY, float SizeX, float SizeY)
 GuiElement (GuiElement &)=delete
GuiElementoperator= (const GuiElement &)=delete
 GuiElement (GuiElement &&)=default
GuiElementoperator= (GuiElement &&)=default
virtual void setup (GuiElementHandler *Handler)
virtual void setup (JMwindow *Window)
float width () const
float height () const
float xPos () const
float yPos () const
void setPosition (float x, float y)
void setSize (float x, float y)
void setSizeX (float x)
void setSizeY (float y)
bool mouseOver () const
 returns true if the mouse is over the element.
float localMouseX () const
 Returns the mouse position relative to the bottom left corner of the element.
float localMouseY () const
 Returns the mouse position relative to the bottom left corner of the element.
bool clicked () const
 returns true if the mouse is over the element and the left button is pressed and released.
bool rightClicked () const
 returns true if the mouse is over the element and the right button is pressed and released.
bool pressed () const
 returns true if the mouse is over the element and the left button is pressed.
virtual void display ()
 is called by the element handler to display the element on the screen.
int renderLayer ()

Public Attributes

bool addAlphabet = true
 if true, new items will be added in alphabetical order.
bool selectableItems = true
 if true, an item can be selected when clicked and selectedItem is set to its name.
bool secondSelectableItems = true
 if true, more than one items can be selected by control or shift clicking.
Public Attributes inherited from GuiElement
float dispTitleX = 0.0f
float dispTitleY = 0.0f
bool allowInput = true
 used to prevent user input to this element if needed.
bool forceAllowInput = false
 if true, when the element handlers allowInput is set to false, this element will be exempt.
bool hide = false
 the element is not updated or displayed if true
bool constantUpdate = false
 Set this to true to re-render the element every frame. By default, the element is only re-rendered when animating (mouse over animation and pressed animation).
bool staticElement = false
 if true, the element will only be rendered for the startup animation or if the window is resized, then displayed staticly. User input will not work.
bool reRender = false
 If set to true, the element is re-rendered once, then this is set to false.
std::string helpMessage = ""
 The help message that displays when the mouse is hovered over the object.
JMwindowwindow = nullptr
 the window that this element is drawn to.
ClickEventevent_clicked = nullptr
RightClickEventevent_rightClicked = nullptr
std::string displayTitle = ""

Additional Inherited Members

Protected Member Functions inherited from GuiElement
void registerEvent (JMeventDispatcher::Event *event)
 adds an event to the window's event handler.
Protected Attributes inherited from GuiElement
int RenderLayer = 0
GuiElementHandlerhandler = nullptr
 the handler object that this element is drawn by.
JMGraphics * gr = nullptr
 the graphics object of the parent window. use this objects graphics functions to draw the ui element.
JMGraphics::Buffer * graphicsBuffer = nullptr
 the element is drawn to a graphics buffer so that the graphics only have to be generated when nescecary, and still displayed on the screen every frame.
JMGraphics::Font * dispTitleFont = nullptr
 The font used to render the title.
float posX = 0.0f
float posY = 0.0f
float sizeX = 0.0f
float sizeY = 0.0f
glm::vec2 dispTitleSize = glm::vec2(0.0f, 0.0f)
 stores the physical size of the displayed title
float dispTitleScale = 1.0f
 sets the physical size of the title
float anim_start = 0.0f
 use to create a startup animation. Increases from 0.0f to 1.0f over time when the element is first displayed.
float anim_mouseOver = 0.0f
 use to create a mouse over animation. Increases from 0.0f to 1.0f over time when the mouse is over the element.
float anim_pressed = 0.0f
 use to create a pressed animation. Increases from 0.0f to 1.0f over time when the element is pressed with the mouse.
float anim_clicked = 0.0f
 use to create a clicked animation. When the element is clicked, it will be set to 1.0f, then decrease to 0.0f over time.
bool fixedX = false
 If true, the element cannot be resized on the x axis.
bool fixedY = false
 If true, the element cannot be resized on the y axis.

Detailed Description

A scrollable list of items. Items can be added and removed at runtime. All items must have a unique name. If a duplicate item is added, it will be renamed by either incrementing a number if its at the end of the name, or adding a number if none exists. This new name is returned from addItem() so be sure to update other references to this name if necessary.
Multiple items can also be selected by default. If the item was not the primary selection, the events instances secondSelected bool will be set to true.

Member Function Documentation

◆ render()

void ListMenu::render ( )
virtual

draw the element to the buffer. Override this to make the element custom.

Reimplemented from GuiElement.


The documentation for this class was generated from the following file: