R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
UI::RaylibMenu Class Reference

Raylib implementation of the IMenu interface. More...

#include <RaylibMenu.hpp>

Inheritance diagram for UI::RaylibMenu:
Inheritance graph
Collaboration diagram for UI::RaylibMenu:
Collaboration graph

Public Member Functions

 RaylibMenu (Graphics::IGraphics &graphics)
 Construct a new RaylibMenu.
 
 ~RaylibMenu () override=default
 Destroy the RaylibMenu.
 
void Update () override
 Update all menu elements.
 
void Render () override
 Render all menu elements.
 
void AddButton (std::shared_ptr< IButton > button) override
 Add a button to the menu.
 
void RemoveButton (size_t index) override
 Remove a button from the menu by index.
 
std::shared_ptr< IButtonGetButton (size_t index) override
 Get a button by index.
 
size_t GetButtonCount () const override
 Get the number of buttons in the menu.
 
void Clear () override
 Remove all buttons from the menu.
 
void SetVisible (bool visible) override
 Set menu visibility.
 
bool IsVisible () const override
 Check menu visibility.
 
void HandleKeyboardNavigation () override
 Handle keyboard navigation input.
 
void SelectNext () override
 Select the next navigable element.
 
void SelectPrevious () override
 Select the previous navigable element.
 
void TriggerSelected () override
 Trigger the currently selected element (simulate click).
 
int GetSelectedIndex () const override
 Get the index of the currently selected element.
 
void SetSelectedIndex (int index) override
 Set the selected element by index.
 
- Public Member Functions inherited from UI::IMenu
virtual ~IMenu ()=default
 Virtual destructor.
 

Private Attributes

Graphics::IGraphics_graphics
 Graphics dependency.
 
std::vector< std::shared_ptr< IButton > > _buttons
 Collection of buttons.
 
bool _visible {true}
 Menu visibility state.
 
int _selectedIndex {-1}
 Currently selected button index (-1 = none)
 

Detailed Description

Raylib implementation of the IMenu interface.

Owns a list of buttons and calls Update()/Render() on them. Uses Graphics::IGraphics only as a dependency carrier for potential future menu-level drawing (background/panels) and to keep a consistent creation signature with the UI factory.

Definition at line 25 of file RaylibMenu.hpp.

Constructor & Destructor Documentation

◆ RaylibMenu()

UI::RaylibMenu::RaylibMenu ( Graphics::IGraphics graphics)
explicit

Construct a new RaylibMenu.

Parameters
graphicsGraphics wrapper dependency.

Definition at line 15 of file RaylibMenu.cpp.

◆ ~RaylibMenu()

UI::RaylibMenu::~RaylibMenu ( )
overridedefault

Destroy the RaylibMenu.

Member Function Documentation

◆ AddButton()

void UI::RaylibMenu::AddButton ( std::shared_ptr< IButton button)
overridevirtual

Add a button to the menu.

Parameters
buttonShared pointer to the button to add.

Implements UI::IMenu.

Definition at line 46 of file RaylibMenu.cpp.

References _buttons.

◆ Clear()

void UI::RaylibMenu::Clear ( )
overridevirtual

Remove all buttons from the menu.

Implements UI::IMenu.

Definition at line 75 of file RaylibMenu.cpp.

References _buttons, and _selectedIndex.

◆ GetButton()

std::shared_ptr< IButton > UI::RaylibMenu::GetButton ( size_t  index)
overridevirtual

Get a button by index.

Parameters
indexIndex of the button.
Returns
Shared pointer to the button, or nullptr if out of range.

Implements UI::IMenu.

Definition at line 64 of file RaylibMenu.cpp.

References _buttons.

◆ GetButtonCount()

size_t UI::RaylibMenu::GetButtonCount ( ) const
overridevirtual

Get the number of buttons in the menu.

Returns
Number of buttons.

Implements UI::IMenu.

Definition at line 71 of file RaylibMenu.cpp.

References _buttons.

◆ GetSelectedIndex()

int UI::RaylibMenu::GetSelectedIndex ( ) const
overridevirtual

Get the index of the currently selected element.

Returns
Selected index, or -1 if none selected.

Implements UI::IMenu.

Definition at line 213 of file RaylibMenu.cpp.

References _selectedIndex.

◆ HandleKeyboardNavigation()

void UI::RaylibMenu::HandleKeyboardNavigation ( )
overridevirtual

◆ IsVisible()

bool UI::RaylibMenu::IsVisible ( ) const
overridevirtual

Check menu visibility.

Returns
true if visible.

Implements UI::IMenu.

Definition at line 88 of file RaylibMenu.cpp.

References _visible.

◆ RemoveButton()

void UI::RaylibMenu::RemoveButton ( size_t  index)
overridevirtual

Remove a button from the menu by index.

Parameters
indexIndex of the button to remove.

Implements UI::IMenu.

Definition at line 52 of file RaylibMenu.cpp.

References _buttons, and _selectedIndex.

◆ Render()

void UI::RaylibMenu::Render ( )
overridevirtual

Render all menu elements.

Note
Must be called between the backend BeginDrawing/EndDrawing calls.

Implements UI::IMenu.

Definition at line 33 of file RaylibMenu.cpp.

References _buttons, and _visible.

◆ SelectNext()

void UI::RaylibMenu::SelectNext ( )
overridevirtual

Select the next navigable element.

Note
Wraps around to first element when at the end.

Implements UI::IMenu.

Definition at line 144 of file RaylibMenu.cpp.

References _buttons, and _selectedIndex.

Referenced by HandleKeyboardNavigation().

◆ SelectPrevious()

void UI::RaylibMenu::SelectPrevious ( )
overridevirtual

Select the previous navigable element.

Note
Wraps around to last element when at the beginning.

Implements UI::IMenu.

Definition at line 172 of file RaylibMenu.cpp.

References _buttons, and _selectedIndex.

Referenced by HandleKeyboardNavigation().

◆ SetSelectedIndex()

void UI::RaylibMenu::SetSelectedIndex ( int  index)
overridevirtual

Set the selected element by index.

Parameters
indexIndex of element to select, or -1 to clear selection.

Implements UI::IMenu.

Definition at line 217 of file RaylibMenu.cpp.

References _buttons, and _selectedIndex.

Referenced by SetVisible().

◆ SetVisible()

void UI::RaylibMenu::SetVisible ( bool  visible)
overridevirtual

Set menu visibility.

Parameters
visibletrue to show the menu, false to hide it.

Implements UI::IMenu.

Definition at line 80 of file RaylibMenu.cpp.

References _visible, and SetSelectedIndex().

Here is the call graph for this function:

◆ TriggerSelected()

void UI::RaylibMenu::TriggerSelected ( )
overridevirtual

Trigger the currently selected element (simulate click).

Implements UI::IMenu.

Definition at line 205 of file RaylibMenu.cpp.

References _buttons, and _selectedIndex.

Referenced by HandleKeyboardNavigation().

◆ Update()

void UI::RaylibMenu::Update ( )
overridevirtual

Update all menu elements.

Note
Should be called once per frame.

Implements UI::IMenu.

Definition at line 17 of file RaylibMenu.cpp.

References _buttons, _visible, and HandleKeyboardNavigation().

Here is the call graph for this function:

Member Data Documentation

◆ _buttons

std::vector<std::shared_ptr<IButton> > UI::RaylibMenu::_buttons
private

◆ _graphics

Graphics::IGraphics& UI::RaylibMenu::_graphics
private

Graphics dependency.

Definition at line 84 of file RaylibMenu.hpp.

Referenced by HandleKeyboardNavigation().

◆ _selectedIndex

int UI::RaylibMenu::_selectedIndex {-1}
private

Currently selected button index (-1 = none)

Definition at line 87 of file RaylibMenu.hpp.

Referenced by Clear(), GetSelectedIndex(), RemoveButton(), SelectNext(), SelectPrevious(), SetSelectedIndex(), and TriggerSelected().

◆ _visible

bool UI::RaylibMenu::_visible {true}
private

Menu visibility state.

Definition at line 86 of file RaylibMenu.hpp.

Referenced by IsVisible(), Render(), SetVisible(), and Update().


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