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 |
|
forlano
Messages: 1182 Registered: March 2006 Location: Italy
|
Senior 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 #1936 is a reply to message #1934] |
Tue, 28 March 2006 10:57 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate 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();
}
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 14:40:42 CET 2024
Total time taken to generate the page: 0.01726 seconds
|