WINDEX
Public Member Functions | List of all members
wex::menu Class Reference

A drop down list of options that user can click to start an action. More...

#include <wex.h>

Public Member Functions

 menu (gui &parent)
 
void append (const std::string &title, const std::function< void(const std::string &)> &f=[](const std::string &title) {})
 Append menu item. More...
 
void append (const std::string &title, menu &submenu)
 Append submenu. More...
 
void popup (int x, int y)
 Popup menu and run user selection. More...
 
HMENU handle ()
 
bool check (int index, bool f=true)
 Set or unset check mark beside menu item. More...
 
int size ()
 Number of items in menu.
 

Detailed Description

A drop down list of options that user can click to start an action.

// construct top level window
gui& form = wex::windex::topWindow();
form.move({ 50,50,400,400});
form.text("Menu demo");

 int clicked = -1;

menu m( form );
m.append("test",[&](const std::string &title)
{
    clicked = 1;
});
m.append("second",[&](const std::string &title)
{
    clicked = 2;
});
m.append("third",[&](const std::string &title)
{
    clicked = 3;
});
m.popup( form, 200,200 );

msgbox( form,std::string("item ") + std::to_string(clicked) + " clicked");

form.show();

Member Function Documentation

◆ append() [1/2]

void wex::menu::append ( const std::string &  title,
const std::function< void(const std::string &)> &  f = [](const std::string &title) {} 
)
inline

Append menu item.

Parameters
[in]title
[in]ffunction to be run when menu item clicked

The function signature is void f( const std::string& title ).

The title can be used by the function if it needs to know the menue item title that caused execution i.e when several items invoke the same function

◆ append() [2/2]

void wex::menu::append ( const std::string &  title,
menu submenu 
)
inline

Append submenu.

Parameters
[in]title
[in]submenu

◆ check()

bool wex::menu::check ( int  index,
bool  f = true 
)
inline

Set or unset check mark beside menu item.

Parameters
[in]index0-based index of menu item
[in]ftrue if menu item is to be checked, default true
Returns
true if the menu item was previously checked

◆ popup()

void wex::menu::popup ( int  x,
int  y 
)
inline

Popup menu and run user selection.

Parameters
[in]xlocation
[in]ylocation

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