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 » U++ Library support » Menus&Toolbars » beginner's questions about menu&bars [SOLVED]+[EXAMPLES]
beginner's questions about menu&bars [SOLVED]+[EXAMPLES] [message #1934] Tue, 28 March 2006 10:10 Go to next message
forlano is currently offline  forlano
Messages: 1071
Registered: March 2006
Location: Italy
Experienced Contributor
Hello,

I'm learning this amazing library but I'm having some problem. Please forgive me if I'm posting a silly question. Unfortunatly I found no reference about menu in assist in theIDE and I am confused about class MenuBar and Bar and how to use them.

Below is the code for a menubar that I got in the documentation. It has 1 pulldown menu attached to 'File'. Now I want add another pulldown, lets say 'Edit', to the right of 'File' with just one item, let's say 'select'. Can somebody add two lines of code to show me how to perform this task? After it I am sure to be able to realize any menu.

Thanks a lot in advance.
Luigi

#include <CtrlLib/CtrlLib.h>

struct App : public TopWindow {
	bool numbers_enabled;

	void Exit()
	{
		Close();
	}

	void EnableNumbers()
	{
		numbers_enabled = !numbers_enabled;
	}

	void ShowNumber(int n)
	{
		PromptOK(AsString(n));
	}

	void SubMenu(Bar& bar)
	{
		for(int i = 0; i < 10; i++)
			bar.Add(AsString(i), THISBACK1(ShowNumber, i));
	}


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

	void MainBar(Bar& bar)
	{
		bar.Add("Menu", THISBACK(Menu));
	}

	MenuBar menu;

	typedef App CLASSNAME;

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

GUI_APP_MAIN
{
	App().Run();
}

[Updated on: Mon, 01 May 2006 14:09] by Moderator

Report message to a moderator

Re: question about menu [message #1935 is a reply to message #1934] Tue, 28 March 2006 10:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
.......
	void MySelect() { .... }

	void Select(Bar& bar)
	{
		bar.Add("Select!", THISBACK(MySelect));
	}

	void MainBar(Bar& bar)
	{
		bar.Add("Menu", THISBACK(Menu));
		bar.Add("Select", THISBACK(Select));
	}
......


The difference between Bar and MenuBar is that "Bar" can mean ToolBar as well - you can share the same definition for both.

Mirek
Re: question about menu [message #1936 is a reply to message #1934] Tue, 28 March 2006 10:57 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
I think this should help:
#include <CtrlLib/CtrlLib.h>

struct App : public TopWindow {
	bool numbers_enabled;

	void Exit() {Close();}

	void EnableNumbers()     {numbers_enabled = !numbers_enabled;}
	void ShowNumber(int n)   {PromptOK(AsString(n));}
	void TestEdit()          {PromptOK("fromEdit");}  //added  No3 - your func
	//add here more funcs to call from menus,,,

	void SubMenu(Bar& bar) {  //this must be imagined as SubSubMenu in fact...
		for(int i = 0; i < 10; i++)
			bar.Add(AsString(i), THISBACK1(ShowNumber, i));
	}


	void Menu(Bar& bar) { //confusing name should be changed to "File"...
		bar.Add("Enable numbers", THISBACK(EnableNumbers)).Check(numbers_enabled);
		bar.Add(numbers_enabled, "Numbers", THISBACK(SubMenu));
		bar.Add("Exit", THISBACK(Exit)).Key(K_CTRL_E);
	}
	
	//added No2 - your extra menu item and subItems 
	void Edit(Bar& bar) {
		bar.Add("EditMy_1", THISBACK(TestEdit)).Key(K_CTRL_D);
		//add more items here...
	}//up to here

	void MainBar(Bar& bar){  //row of main menu "labels" - what you see without opening menus...
		bar.Add("Menu", THISBACK(Menu));
		bar.Add("Edit", THISBACK(Edit));  //added Step1 - extra menu item on Main & callback
	}

	MenuBar menu;

typedef App CLASSNAME;

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


GUI_APP_MAIN
{
	App().Run();
}
Re: question about menu [message #1942 is a reply to message #1935] Tue, 28 March 2006 14:08 Go to previous message
forlano is currently offline  forlano
Messages: 1071
Registered: March 2006
Location: Italy
Experienced Contributor
luzr wrote on Tue, 28 March 2006 03:29

.......
	void MySelect() { .... }

	void Select(Bar& bar)
	{
		bar.Add("Select!", THISBACK(MySelect));
	}

	void MainBar(Bar& bar)
	{
		bar.Add("Menu", THISBACK(Menu));
		bar.Add("Select", THISBACK(Select));
	}
......


The difference between Bar and MenuBar is that "Bar" can mean ToolBar as well - you can share the same definition for both.

Mirek


Thank you very much!
This example and the next one are very useful (please let me suggest to add it in the documentation). Now I can realize all menu I desire.

Luigi
Previous Topic: Navigating through menu items help line isn't shown [SOLVED?]
Next Topic: Minor crash with Menu... [FIXED]
Goto Forum:
  


Current Time: Tue Nov 19 13:55:15 CET 2019

Total time taken to generate the page: 0.01220 seconds