|
|
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » How to combine two widget-class in the topwindow
|
Re: How to combine two widget-class in the topwindow [message #2039 is a reply to message #2038] |
Thu, 30 March 2006 15:06   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
#include <CtrlLib/CtrlLib.h>
//you can keep this (and more like this) class declarations in one yourApp.h file
class App : public TopWindow {
private:
bool numbers_enabled;
//declare your widgets by adding below...
MenuBar menu;
StatusBar status;
InfoCtrl info1;
public:
void Exit() {Close();}
void EnableNumbers() {numbers_enabled = !numbers_enabled;}
void ShowNumber(int n) {PromptOK(AsString(n));}
void TestEdit() {PromptOK("fromEdit");} //added No3 - your func
void Dummy() {PromptOK("your function needs to be implemented!");}
//useful to have one dummy function while work in progress...
//...to fill calling "gaps"
//add here more funcs to call from menus,,,
//bar declarations
void SubSubMenu(Bar& bar);
void FileMenu(Bar& bar);
void EditMenu(Bar& bar);
void HelpMenu(Bar& bar);
void TopMenus(Bar& bar);
typedef App CLASSNAME;
App();
};
//while all implementations below you can keep in one or more *.cpp files (split by classes)
void App::SubSubMenu(Bar& bar) {
for(int i = 0; i < 10; i++)
bar.Add(AsString(i), THISBACK1(ShowNumber, i));
}
void App::FileMenu(Bar& bar) { //confusing name changed from "Menu" to "File"...
bar.Add("Enable numbers", THISBACK(EnableNumbers)).Check(numbers_enabled);
bar.Add(numbers_enabled, "Numbers", THISBACK(SubSubMenu));
bar.Add("Exit", THISBACK(Exit)).Key(K_CTRL_E);
}
//added No2 - your extra menu item and subItems
void App::EditMenu(Bar& bar) {
bar.Add("EditMy_1", THISBACK(TestEdit)).Key(K_CTRL_D);
bar.Add("Copy", THISBACK(Dummy)).Key(K_CTRL_C);
bar.Add("Cut", THISBACK(Dummy)).Key(K_CTRL_X);
bar.Add("Paste", THISBACK(Dummy)).Key(K_CTRL_V);
//add more items here...
}
void App::HelpMenu(Bar& bar)
{
bar.Add("Help", THISBACK(Dummy)).Key(K_F1);
bar.Add("About...", THISBACK(Dummy));
}
void App::TopMenus(Bar& bar){ //row of top menu "labels" - what you see without opening menus...
bar.Add("File", THISBACK(FileMenu));
bar.Add("Edit", THISBACK(EditMenu)); //added Step1 - extra menu item on Main & callback
bar.Add("Help", THISBACK(HelpMenu));
}
App::App()
{
//initialize your members on App creation (constructor)
numbers_enabled = true;
AddFrame(menu);
menu.Set(THISBACK(TopMenus));
//status stuff
status.AddFrame(info1.Width(250));
AddFrame(status.Height(25));
info1="info1: Welcome to the Ultimate++ !";
}
GUI_APP_MAIN
{
App().Title("Forlano Menu and Status -v1").Zoomable().Sizeable().Run();
}
[Updated on: Thu, 30 March 2006 19:39] Report message to a moderator
|
|
|
|
|
|
Re: How to combine two widget-class in the topwindow [message #2100 is a reply to message #2090] |
Fri, 31 March 2006 23:14   |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
fudadmin wrote on Fri, 31 March 2006 19:17 |
1. Complex interfaces should be more or less evenly distributed among classes and their constructors. That's why classes exists!
2. I personally know 3 main ways of creating widgets:
2.1 As Mirek mentioned here - with Layout Designer
2.2 Program everything yourself by hand
2.3 Copy code from *.lay files and create your own programmed classes.
Which case you would like to discuss?
|
The package AddressBook shows how to integrate the product of the Layout Designer with the code. Unfortunately I saw strange signs like <...> , , that I do not understand yet... So points 2.1 and 2.3 cannot be discussed with me, at least not in the immediate future.
Fortunatly remains another possibility, 2.2. It should be the most general approach although at the cost to write more code lines... but I'm ready.
The current problem is to put between the menubar and the status bar a group of 4 tab pages. Each of them will contain other widgets. I've inquired the available documentation and the code example to get useful advices but both AddressBook and theIde packages use layout files. So I do not know how to let appear some thing that could resemble a tabbed window. Nevertheless I tried many weird things like that below good to open a window but without tabs.
Any advices for a minimalist approach as the example below? After that something will appear I will try to merge it with the menu and status bar and then start to fill each tab.
Thank you,
Luigi
#include <CtrlLib/CtrlLib.h>
GUI_APP_MAIN
{
TopWindow w;
TabCtrl tab0, tab1;
//AddFrame(tab0);
w.Add(tab0, "one");
w.Add(tab1, "two");
w.Run();
}
|
|
|
Re: How to combine two widget-class in the topwindow [message #2101 is a reply to message #2100] |
Fri, 31 March 2006 23:40   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
forlano wrote on Fri, 31 March 2006 22:14 |
The current problem is to put between the menubar and the status bar a group of 4 tab pages. Each of them will contain other widgets.
|
did you mean this?:
#include <CtrlLib/CtrlLib.h>
GUI_APP_MAIN
{
TopWindow w;
TabCtrl tabs;
w.Add(tabs.SizePos()); //fills all available space...
tabs.Add("one");
tabs.Add("two");
tabs.Add("three");
//add more accordingly or create in a a loop...
w.Run();
}
[Updated on: Fri, 31 March 2006 23:40] Report message to a moderator
|
|
|
|
|
Re: How to combine two widget-class in the topwindow [message #2108 is a reply to message #2104] |
Sat, 01 April 2006 14:31   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
Here we go:
#include <CtrlLib/CtrlLib.h>
//tabs example- not very correct but might be usuful for learning...
//personalized tab (1 child) widget
class LuigiTab : public ParentCtrl {
Button btn;
DocEdit doc;
public:
typedef LuigiTab CLASSNAME;
LuigiTab();
~LuigiTab(){;}
};
LuigiTab::LuigiTab() {
btn.SetLabel("Just Button");
btn.SetRect(20,20,100,25);
Add(btn);
//I strongly recommend to learn positioning from Designer- use Ctrl-T!
doc.LeftPosZ(30, 500).TopPosZ(50, 300);
Add(doc);
}
//personalized tabs (many -container) widget
class LuigiTabs : public TabCtrl {
LuigiTab tab1,tab2,tab3;
public:
typedef LuigiTabs CLASSNAME;
LuigiTabs();
~LuigiTabs(){;}
};
LuigiTabs::LuigiTabs() {
tab1.SizePos();
tab2.SizePos();
tab3.SizePos();
Add(tab1,"one");
Add(tab2,"two");
Add(tab3,"three");
}
//you can keep this (and more like this) class declarations in one yourApp.h file
class App : public TopWindow {
private:
bool numbers_enabled;
//prepare to add your widgets by declaring below...
MenuBar menu;
LuigiTabs tabs; //inserted declaration of personalized... - see class
StatusBar status;
InfoCtrl info1;
public:
void Exit() {Close();}
void EnableNumbers() {numbers_enabled = !numbers_enabled;}
void ShowNumber(int n) {PromptOK(AsString(n));}
void TestEdit() {PromptOK("fromEdit");} //added No3 - your func
void Dummy() {PromptOK("your function needs to be implemented!");}
//useful to have one dummy function while work in progress...
//...to fill calling "gaps"
//add here more funcs to call from menus,,,
//bar declarations
void SubSubMenu(Bar& bar);
void FileMenu(Bar& bar);
void EditMenu(Bar& bar);
void HelpMenu(Bar& bar);
void TopMenus(Bar& bar);
typedef App CLASSNAME;
App();
};
//while all implementations below you can keep in one or more *.cpp files (split by classes)
void App::SubSubMenu(Bar& bar) {
for(int i = 0; i < 10; i++)
bar.Add(AsString(i), THISBACK1(ShowNumber, i));
}
void App::FileMenu(Bar& bar) { //confusing name changed from "Menu" to "File"...
bar.Add("Enable numbers", THISBACK(EnableNumbers)).Check(numbers_enabled);
bar.Add(numbers_enabled, "Numbers", THISBACK(SubSubMenu));
bar.Add("Exit", THISBACK(Exit)).Key(K_CTRL_E);
}
//added No2 - your extra menu item and subItems
void App::EditMenu(Bar& bar) {
bar.Add("EditMy_1", THISBACK(TestEdit)).Key(K_CTRL_D);
bar.Add("Copy", THISBACK(Dummy)).Key(K_CTRL_C);
bar.Add("Cut", THISBACK(Dummy)).Key(K_CTRL_X);
bar.Add("Paste", THISBACK(Dummy)).Key(K_CTRL_V);
//add more items here...
}
void App::HelpMenu(Bar& bar)
{
bar.Add("Help", THISBACK(Dummy)).Key(K_F1);
bar.Add("About...", THISBACK(Dummy));
}
void App::TopMenus(Bar& bar){ //row of top menu "labels" - what you see without opening menus...
bar.Add("File", THISBACK(FileMenu));
bar.Add("Edit", THISBACK(EditMenu)); //added Step1 - extra menu item on Main & callback
bar.Add("Help", THISBACK(HelpMenu));
}
App::App()
{
//initialize your members on App creation (constructor)
numbers_enabled = true;
AddFrame(menu);
menu.Set(THISBACK(TopMenus));
//use Add not AddFrame -in most cases. use Assistant to see the return values
Add(tabs.SizePos());
//status stuff
status.AddFrame(info1.Width(250));
AddFrame(status.Height(25));
info1="info1: Welcome to the Ultimate++ !";
}
GUI_APP_MAIN
{
App().Title("Forlano Menu, Tabs and Status -v1").Zoomable().Sizeable().Run();
}
Luigi, please study this example and ask questions immediately. Don't waste your time struggling alone!...
|
|
|
|
|
Re: How to combine two widget-class in the topwindow [message #2117 is a reply to message #2115] |
Sat, 01 April 2006 19:56   |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
One more question...
I'm working with the designer, then copy and past the code as Fudadmin pointed out. It seems easy. Now I have many labels. They are all passive and show some text. I would like to declare just one label widget like this:
Label label;
and the use 'label' everywhere (I used to do so with another GUI in C). So I believed that the following code:
label.SetLabel(t_("Label 1"));
label.SetAlign(ALIGN_CENTER);
label.LeftPosZ(236, 48);
label.TopPosZ(96, 19);
Add(label);
label.SetLabel(t_("Label 2"));
label.SetAlign(ALIGN_CENTER);
label.LeftPosZ(136, 48);
label.TopPosZ(46, 49);
Add(label);
could show two labels. Instead seems that 'Label 2' override the first one. So at the end I see only 1, the last.
This means that I have to use two separate variables (object):
Label label, label1;
label.SetLabel(t_("Label 1"));
label.SetAlign(ALIGN_CENTER);
label.LeftPosZ(236, 48);
label.TopPosZ(96, 19);
Add(label);
label1.SetLabel(t_("Label 2"));
label1.SetAlign(ALIGN_CENTER);
label1.LeftPosZ(136, 48);
label1.TopPosZ(46, 49);
Add(label1);
and both appear. I would like to know if there is some trick to use the same object or I must in any case declare each object I use.
Thank you
Luigi
|
|
|
Re: How to combine two widget-class in the topwindow [message #2120 is a reply to message #2117] |
Sat, 01 April 2006 20:27   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
forlano wrote on Sat, 01 April 2006 18:56 | Hello,
One more question...
I'm working with the designer, then copy and past the code as Fudadmin pointed out. It seems easy. Now I have many labels. They are all passive and show some text. I would like to declare just one label widget like this:
Label label;
and the use 'label' everywhere (I used to do so with another GUI in C). So I believed that the following code:
label.SetLabel(t_("Label 1"));
label.SetAlign(ALIGN_CENTER);
label.LeftPosZ(236, 48);
label.TopPosZ(96, 19);
Add(label);
label.SetLabel(t_("Label 2"));
label.SetAlign(ALIGN_CENTER);
label.LeftPosZ(136, 48);
label.TopPosZ(46, 49);
Add(label);
could show two labels. Instead seems that 'Label 2' override the first one. So at the end I see only 1, the last.
This means that I have to use two separate variables (object):
Label label, label1;
label.SetLabel(t_("Label 1"));
label.SetAlign(ALIGN_CENTER);
label.LeftPosZ(236, 48);
label.TopPosZ(96, 19);
Add(label);
label1.SetLabel(t_("Label 2"));
label1.SetAlign(ALIGN_CENTER);
label1.LeftPosZ(136, 48);
label1.TopPosZ(46, 49);
Add(label1);
and both appear. I would like to know if there is some trick to use the same object or I must in any case declare each object I use.
Thank you
Luigi
|
Label is a class (dead description, recipe, mold, pattern set of genes, etc.).
label1, label2 etc. are class instances (real live objects like someone's children).
By declareing:
Label label1, label2;
you instanciate them or make the very begining of life.
Then you shape them.
label1 - red hair, big ears...
label2 - yellow hair, small head...
etc...
Can you imagine the same child beeing a daughter and a son, having all green and red hair at the same time? 
...Unless you put some genes (methods) to do so at diferent times and positions.
E.g make a loop and make to display the same label with different params every 100ms. But this, I think, would create blinking and waste of computer power.
So maybe it's better to create a different label for different positions? 
Edit:
P.S. Btw, you can use an array of labels... and calculate their positions in a loop... 
[Updated on: Sat, 01 April 2006 20:31] Report message to a moderator
|
|
|
|
Re: How to combine two widget-class in the topwindow [message #2122 is a reply to message #2121] |
Sat, 01 April 2006 20:48   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
luzr wrote on Sat, 01 April 2006 19:36 | Well, each label has to have its own variable (in U++, those variables are actual GUI elements, not just some info that is placed to dialog definition).
However, you can do this:
Array<Label> label;
....
labels.Add();
label.Top().SetLabel(t_("Label 1"));
label.Top().SetAlign(ALIGN_CENTER);
label.Top().LeftPosZ(236, 48);
label.Top().TopPosZ(96, 19);
Add(label.Top());
labels.Add();
label.Top().SetLabel(t_("Label 2"));
label.Top().SetAlign(ALIGN_CENTER);
label.Top().LeftPosZ(136, 48);
label.Top().TopPosZ(46, 49);
Add(label.Top());
Mirek
|
Or, yes, like this. But in this case some strange symbols <..> come to help and instantiation of children(daughters-labels) is achieved by labels.Add() - each label is then created "inside".
|
|
|
Re: How to combine two widget-class in the topwindow [message #2123 is a reply to message #2121] |
Sat, 01 April 2006 21:03   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
luzr wrote on Sat, 01 April 2006 19:36 | Well, each label has to have its own variable (in U++, those variables are actual GUI elements, not just some info that is placed to dialog definition).
However, you can do this:
Array<Label> label;
....
labels.Add();
label.Top().SetLabel(t_("Label 1"));
label.Top().SetAlign(ALIGN_CENTER);
label.Top().LeftPosZ(236, 48);
label.Top().TopPosZ(96, 19);
Add(label.Top());
labels.Add();
label.Top().SetLabel(t_("Label 2"));
label.Top().SetAlign(ALIGN_CENTER);
label.Top().LeftPosZ(136, 48);
label.Top().TopPosZ(46, 49);
Add(label.Top());
Mirek
|
Btw, now I'm lost - what is labels?
|
|
|
Re: How to combine two widget-class in the topwindow [message #2124 is a reply to message #2123] |
Sat, 01 April 2006 21:09   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
fudadmin wrote on Sat, 01 April 2006 14:03 |
luzr wrote on Sat, 01 April 2006 19:36 | Well, each label has to have its own variable (in U++, those variables are actual GUI elements, not just some info that is placed to dialog definition).
However, you can do this:
Array<Label> label;
....
labels.Add();
label.Top().SetLabel(t_("Label 1"));
label.Top().SetAlign(ALIGN_CENTER);
label.Top().LeftPosZ(236, 48);
label.Top().TopPosZ(96, 19);
Add(label.Top());
labels.Add();
label.Top().SetLabel(t_("Label 2"));
label.Top().SetAlign(ALIGN_CENTER);
label.Top().LeftPosZ(136, 48);
label.Top().TopPosZ(46, 49);
Add(label.Top());
Mirek
|
Btw, now I'm lost - what is labels?
|
Ooops, should be "label".
Mirek
|
|
|
Re: How to combine two widget-class in the topwindow [message #2130 is a reply to message #2120] |
Sun, 02 April 2006 10:22   |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
fudadmin wrote on Sat, 01 April 2006 20:27 |
Label is a class (dead description, recipe, mold, pattern set of genes, etc.).
label1, label2 etc. are class instances (real live objects like someone's children).
By declareing:
Label label1, label2;
you instanciate them or make the very begining of life.
Then you shape them.
label1 - red hair, big ears...
label2 - yellow hair, small head...
etc...
Can you imagine the same child beeing a daughter and a son, having all green and red hair at the same time? 
|
Yes, I agree it's not confortable for the child... and maybe for the parents too .
Here is my new achievement. I used your method of copy and past from designer after CTRL+T. About Designer I will report later in the appropriate place of the forum. Below is the code I have modified being all the rest of the program remained the same.
//personalized tab (1 child) widget
class LuigiTab : public ParentCtrl {
Button btnAdd, btnDel, btnClear, btnModify;
DocEdit doc;
LabelBox lbox;
Label label[10];
EditString editName, editCountry, editBirth, editNatRat,
editNatId, editFIDEId, editFIDERat;
DropList editTitle;
Option tsex;
EditInt kcoeff;
ArrayCtrl arr;
public:
typedef LuigiTab CLASSNAME;
LuigiTab();
~LuigiTab(){;}
};
LuigiTab::LuigiTab() {
// label
lbox.SetLabel(t_("Edit Player")).LeftPosZ(16, 648).TopPosZ(16, 80);
Add(lbox);
label[0].SetLabel(t_("Name")).SetAlign(ALIGN_CENTER).LeftPosZ(28, 132).TopPosZ(32, 19);
Add(label[0]);
label[1].SetLabel(t_("Fed")).SetAlign(ALIGN_CENTER).LeftPosZ(168, 40).TopPosZ(32, 19);
Add(label[1]);
label[2].SetLabel(t_("Birthday")).SetAlign(ALIGN_CENTER).LeftPosZ(208, 56).TopPosZ(32, 19);
Add(label[2]);
label[3].SetLabel(t_("Gender")).SetAlign(ALIGN_CENTER).LeftPosZ(264, 56).TopPosZ(32, 19);
Add(label[3]);
label[4].SetLabel(t_("Title")).SetAlign(ALIGN_CENTER).LeftPosZ(324, 40).TopPosZ(32, 19);
Add(label[4]);
label[5].SetLabel(t_("ID FIDE")).SetAlign(ALIGN_CENTER).LeftPosZ(380, 48).TopPosZ(32, 19);
Add(label[5]);
label[6].SetLabel(t_("Rat FIDE")).SetAlign(ALIGN_CENTER).LeftPosZ(440, 48).TopPosZ(32, 19);
Add(label[6]);
label[7].SetLabel(t_("ID Nat")).SetAlign(ALIGN_CENTER).LeftPosZ(496, 48).TopPosZ(32, 19);
Add(label[7]);
label[8].SetLabel(t_("Rat Nat")).SetAlign(ALIGN_CENTER).LeftPosZ(558, 48).TopPosZ(32, 19);
Add(label[8]);
label[9].SetLabel(t_("K")).SetAlign(ALIGN_CENTER).LeftPosZ(616, 24).TopPosZ(32, 19);
Add(label[9]);
//active widget
editName.MaxLen(25).LeftPosZ(28, 136).TopPosZ(56, 19);
Add(editName);
editCountry.MaxLen(3).LeftPosZ(172, 32).TopPosZ(56, 19);
Add(editCountry);
editNatId.MaxLen(8).LeftPosZ(496, 48).TopPosZ(56, 19);
Add(editNatId);
editBirth.MaxLen(10).LeftPosZ(212, 56).TopPosZ(56, 19);
Add(editBirth);
editFIDERat.MaxLen(8).LeftPosZ(440, 48).TopPosZ(56, 19);
Add(editFIDERat);
tsex.SetLabel(t_("Male")).LeftPosZ(280, 42).TopPosZ(56, 20);
Add(tsex);
editTitle.DisplayAll(true).LeftPosZ(328, 42).TopPosZ(56, 20);
Add(editTitle);
editFIDEId.MaxLen(8).LeftPosZ(380, 48).TopPosZ(56, 19);
Add(editFIDEId);
editNatRat.MaxLen(8).LeftPosZ(554, 56).TopPosZ(56, 19);
Add(editNatRat);
kcoeff.Min(0).Max(100).LeftPosZ(620, 24).TopPosZ(56, 19);
Add(kcoeff);
// button
btnAdd.SetLabel(t_("Add Player")).LeftPosZ(24, 96).TopPosZ(116, 24);
Add(btnAdd);
btnModify.SetLabel(t_("Modify Player")).LeftPosZ(148, 96).TopPosZ(116, 24);
Add(btnModify);
btnDel.SetLabel(t_("Delete Player")).LeftPosZ(56, 96).TopPosZ(328, 24);
Add(btnDel);
btnClear.SetLabel(t_("Clear Data")).LeftPosZ(284, 96).TopPosZ(116, 24);
Add(btnClear);
// array ctrl
arr.Moving(true).Removing(true).AppendLine(true).Inserting(true).LeftPosZ(16, 648).TopPosZ(172, 148);
Add(arr);
arr.AddColumn("Name");
arr.AddColumn("Fed");
arr.AddColumn("Birthday");
arr.AddColumn("Gender");
arr.AddColumn("Title");
arr.AddColumn("ID FIDE");
arr.AddColumn("Rat FIDE");
arr.AddColumn("ID Nat");
arr.AddColumn("Rat Nat");
arr.AddColumn("K");
arr.AddColumn("Available");
At the moment this class is instancied in each tab while I want it stays only in tab 1. I believe I must realize a different class for each tab like:
class LuigiTab1 : public ParentCtrl // tab 1
class LuigiTab2 : public ParentCtrl // tab 2
class LuigiTab3 : public ParentCtrl // tab 3
and then create an instance for each of them.
I need to add data to the drop list button. Unfortunatly I have no example in the documentation and I do not know how to do.
In the coloumn available of the arrayctrl I would like to have a chekbox (checked means available, and unchecked unavailable). Any suggestion?
In the addressbook package there is an example similar to what I want to do: simply fill the fields and then push the data in then arrayctrl. This is my next task.
The geometry of the whole tab is not perfect but now it is important to learn how to dispatch the data between the object and how to retrieve them. The beauty can wait.
Thank you,
Luigi
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 21:22:20 CEST 2025
Total time taken to generate the page: 0.01394 seconds
|
|
|