Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » Lambda support in MenuBar
Lambda support in MenuBar [message #46596] Mon, 06 June 2016 20:29 Go to previous message
mirek is currently offline  mirek
Messages: 13980
Registered: November 2005
Ultimate Member
Menu bar now has new methods for direct lambda support, as demonstrated by upgraded reference example:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct App : public TopWindow {
	bool numbers_enabled;

	void Exit()
	{
		Close();
	}

	void SubMenu(Bar& bar)
	{
		for(int i = 0; i < 10; i++)
			bar.Add(~AsString(i), [=] { PromptOK(AsString(i)); });
	}

	void Menu(Bar& bar)
	{
		bar.Add("Enable numbers", [=] { numbers_enabled = !numbers_enabled; })
		   .Check(numbers_enabled);
		bar.Add(numbers_enabled, "Numbers", THISBACK(SubMenu));
		bar.Add("Exit", [=] { Exit(); })
		   .Key(K_CTRL_E);
	}

	void MainBar(Bar& bar)
	{
		bar.Add("Numbers", THISBACK(Menu));
		bar.Sub("Items", [=](Bar& bar) {
			bar.Add("Item 1", [&] { Exclamation("Item 1 invoked"); });
			bar.Add("Item 2", [&] { Exclamation("Item 2 invoked"); });
		});
	}

	MenuBar menu;

	typedef App CLASSNAME;

	App()
	{
		numbers_enabled = false;
		AddFrame(menu);
		menu.Set(THISBACK(MainBar));
	}
};

GUI_APP_MAIN
{
	App().Run();
}


Nice thing is the possibility to define submenu 'inline'. Unfortunately, I had to rename the method name to 'Sub' (instead of Add) because of overloading ambiguity issues...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How You will celebrate 10 000 commit of U++?
Next Topic: EditField::operator String() removed
Goto Forum:
  


Current Time: Wed May 15 03:21:11 CEST 2024

Total time taken to generate the page: 0.02143 seconds