.tutorial

git-svn-id: svn://ultimatepp.org/upp/trunk@15651 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2021-01-07 10:56:31 +00:00
parent d18b121a38
commit 70d8b6d67a
20 changed files with 60 additions and 77 deletions

View file

@ -1,4 +1,4 @@
description " Application window\377"; description "Application window\377";
uses uses
CtrlLib; CtrlLib;

View file

@ -5,7 +5,7 @@ using namespace Upp;
GUI_APP_MAIN GUI_APP_MAIN
{ {
TopWindow w; TopWindow w;
w.Title("My application").MinimizeBox().Sizeable(); w.Title("My application").Zoomable().Sizeable();
w.SetRect(0, 0, 200, 300); w.SetRect(0, 0, 200, 300);
w.Run(); w.Run();
} }

View file

@ -4,7 +4,7 @@ using namespace Upp;
struct MyAppWindow : TopWindow { struct MyAppWindow : TopWindow {
virtual void Paint(Draw& w) override { virtual void Paint(Draw& w) override {
w.DrawRect(GetSize(), SWhite); w.DrawRect(GetSize(), SWhite());
w.DrawText(20, 20, "Hello world!", Arial(30), Magenta); w.DrawText(20, 20, "Hello world!", Arial(30), Magenta);
} }
@ -16,6 +16,6 @@ struct MyAppWindow : TopWindow {
GUI_APP_MAIN GUI_APP_MAIN
{ {
MyAppWindow app; MyAppWindow app;
app.SetRect(0, 0, 200, 100); app.SetRect(0, 0, 400, 100);
app.Run(); app.Run();
} }

View file

@ -3,16 +3,16 @@
using namespace Upp; using namespace Upp;
struct MyAppWindow : TopWindow { struct MyAppWindow : TopWindow {
virtual void Close() override { void Close() override {
delete this; delete this;
} }
virtual void LeftDown(Point pos, dword flags) override { void LeftDown(Point pos, dword flags) override {
(new MyAppWindow)->OpenMain(); (new MyAppWindow)->OpenMain();
} }
virtual void Paint(Draw& w) override { void Paint(Draw& w) override {
w.DrawRect(GetSize(), SWhite); w.DrawRect(GetSize(), SWhite());
w.DrawText(0, 0, "Click the view area to open next window!", Arial(20)); w.DrawText(0, 0, "Click the view area to open next window!", Arial(20));
} }

View file

@ -12,7 +12,7 @@ struct MyAppWindow : TopWindow {
int result = Null; int result = Null;
MenuBar menu; MenuBar menu;
for(int i = 0; i < 10; i++) for(int i = 0; i < 10; i++)
menu.Add(AsString(i), [&, i] { result = i; }); menu.Add(AsString(i), [=, &result] { result = i; });
menu.Separator(); menu.Separator();
menu.Add("Exit", [=] { Exit(); }); menu.Add("Exit", [=] { Exit(); });
menu.Execute(); menu.Execute();

View file

@ -10,32 +10,24 @@ struct MyAppWindow : TopWindow {
MenuBar menu; MenuBar menu;
ToolBar tool; ToolBar tool;
StatusBar status; StatusBar status;
void MenuFn() { typedef MyAppWindow CLASSNAME; // so that we can use THISFN shortcut
PromptOK("Fn activated!");
}
void BarFn() {
PromptOK("Fn2 activated!");
}
void Exit() {
if(PromptOKCancel("Exit MyApp?"))
Break();
}
void SubBar(Bar& bar) { void SubBar(Bar& bar) {
bar.AddMenu("Function", TutorialImg::Fn(), [=] { MenuFn(); }) bar.AddMenu("Function", TutorialImg::Fn(), [=] { // AddMenu - only in menu
.Help("This invokes MenuFn method of tutorial example"); PromptOK("Fn activated!");
bar.Add(TutorialImg::Fn2(), [=] { BarFn(); }) }).Help("This invokes MenuFn method of tutorial example");
.Help("This invokes BarFn method of tutorial example"); bar.Add(TutorialImg::Fn2(), [=] { // does not have image - not in toolbar
bar.Add("Exit", TutorialImg::Exit(), [=] { Exit(); }); PromptOK("Fn2 activated!");
}).Help("This invokes BarFn method of tutorial example");
bar.Add("Exit", TutorialImg::Exit(), [=] { // in both toolbar and menu
if(PromptOKCancel("Exit MyApp?"))
Break();
});
} }
void MainMenu(Bar& bar) { void MainMenu(Bar& bar) {
bar.Sub("Menu", [=](Bar& bar) { bar.Sub("Menu", THISFN(SubBar));
SubBar(bar);
});
} }
MyAppWindow() { MyAppWindow() {
@ -45,10 +37,10 @@ struct MyAppWindow : TopWindow {
AddFrame(tool); AddFrame(tool);
AddFrame(status); AddFrame(status);
AddFrame(InsetFrame()); AddFrame(InsetFrame());
menu.Set([=](Bar& bar) { MainMenu(bar); }); menu.Set(THISFN(MainMenu));
menu.WhenHelp = status; // callback cast to fix it for older CLANG version in C++11 menu.WhenHelp = status;
tool.Set([=](Bar& bar) { SubBar(bar); }); tool.Set([=](Bar& bar) { SubBar(bar); }); // equivalent to THISFN(SubBar)
tool.WhenHelp = status; // callback cast to fix it for older CLANG version in C++11 tool.WhenHelp = status;
} }
}; };

View file

@ -7,7 +7,7 @@ struct MyAppWindow : TopWindow {
MyAppWindow() { MyAppWindow() {
Title("My application with button"); Title("My application with button");
Add(button.LeftPos(10, 100).TopPos(10, 30)); Add(button.LeftPos(10, 200).TopPos(10, 60));
button.SetLabel("Click me!"); button.SetLabel("Click me!");
button << [=] { button << [=] {
PromptOK("You have clicked the button!"); PromptOK("You have clicked the button!");

View file

@ -8,15 +8,15 @@ struct MyAppWindow : TopWindow {
MyAppWindow() { MyAppWindow() {
Title("My application with button").Sizeable(); Title("My application with button").Sizeable();
*this *this
<< lt.SetLabel("left-top").LeftPos(10, 100).TopPos(10, 20) << lt.SetLabel("left-top").LeftPos(10, 200).TopPos(10, 40)
<< rt.SetLabel("right-top").RightPos(10, 100).TopPos(10, 20) << rt.SetLabel("right-top").RightPos(10, 200).TopPos(10, 40)
<< lb.SetLabel("left-bottom").LeftPos(10, 100).BottomPos(10, 20) << lb.SetLabel("left-bottom").LeftPos(10, 200).BottomPos(10, 40)
<< rb.SetLabel("right-bottom").RightPos(10, 100).BottomPos(10, 20) << rb.SetLabel("right-bottom").RightPos(10, 200).BottomPos(10, 40)
<< lv.SetLabel("left-vsize").LeftPos(10, 100).VSizePos(40, 40) << lv.SetLabel("left-vsize").LeftPos(10, 200).VSizePos(60, 60)
<< ht.SetLabel("hsize-pos").HSizePos(120, 120).TopPos(10, 20) << ht.SetLabel("hsize-pos").HSizePos(220, 220).TopPos(10, 40)
<< hv.SetLabel("hsize-vsize").HSizePos(120, 120).VSizePos(40, 40) << hv.SetLabel("hsize-vsize").HSizePos(220, 220).VSizePos(60, 60)
<< cb.SetLabel("hcenter-bottom").HCenterPos(90).BottomPos(10, 20) << cb.SetLabel("hcenter-bottom").HCenterPos(200).BottomPos(10, 40)
<< rc.SetLabel("right-vcenter").RightPos(10, 100).VCenterPos(40) << rc.SetLabel("right-vcenter").RightPos(10, 200).VCenterPos(40)
; ;
} }
}; };

View file

@ -7,7 +7,7 @@ struct MyAppWindow : TopWindow {
MyAppWindow() { MyAppWindow() {
Title("My application with font-zoomed button").Sizeable(); Title("My application with font-zoomed button").Sizeable();
*this << button.SetLabel("Button").LeftPosZ(10, 64).TopPosZ(10, 24); *this << button.SetLabel("Button").LeftPos(Zx(10), Zy(64)).TopPosZ(10, 24);
} }
}; };

View file

@ -1,6 +1,6 @@
LAYOUT(DlgLayout, 208, 64) LAYOUT(DlgLayout, 208, 64)
ITEM(Label, dv___0, SetLabel(t_("Label")).LeftPosZ(8, 36).TopPosZ(8, 19)) ITEM(Upp::Label, dv___0, SetLabel(t_("Label")).LeftPosZ(8, 36).TopPosZ(8, 19))
ITEM(EditString, text, LeftPosZ(48, 92).TopPosZ(8, 19)) ITEM(Upp::EditString, text, LeftPosZ(48, 92).TopPosZ(8, 19))
ITEM(Option, option, SetLabel(t_("Option")).LeftPosZ(8, 108).TopPosZ(32, 15)) ITEM(Upp::Option, option, SetLabel(t_("Option")).LeftPosZ(8, 108).TopPosZ(32, 15))
END_LAYOUT END_LAYOUT

View file

@ -5,7 +5,7 @@ using namespace Upp;
GUI_APP_MAIN GUI_APP_MAIN
{ {
TopWindow app; TopWindow app;
app.SetRect(0, 0, 200, 20); app.SetRect(0, 0, Zx(200), Zy(20));
EditString text; EditString text;
app.Add(text.TopPosZ(0, 20).HSizePos()); app.Add(text.TopPosZ(0, 20).HSizePos());

View file

@ -5,7 +5,7 @@ using namespace Upp;
GUI_APP_MAIN GUI_APP_MAIN
{ {
TopWindow app; TopWindow app;
app.SetRect(0, 0, 200, 20); app.SetRect(0, 0, Zx(200), Zy(20));
EditString text; EditString text;
app.Add(text.TopPosZ(0, 20).HSizePos()); app.Add(text.TopPosZ(0, 20).HSizePos());

View file

@ -5,7 +5,7 @@ using namespace Upp;
GUI_APP_MAIN GUI_APP_MAIN
{ {
TopWindow app; TopWindow app;
app.SetRect(0, 0, 200, 20); app.SetRect(0, 0, Zx(200), Zy(20));
EditDate date; EditDate date;
app.Add(date.TopPosZ(0, 20).HSizePos()); app.Add(date.TopPosZ(0, 20).HSizePos());
app.Run(); app.Run();

View file

@ -5,7 +5,7 @@ using namespace Upp;
GUI_APP_MAIN GUI_APP_MAIN
{ {
TopWindow app; TopWindow app;
app.SetRect(0, 0, 200, 60); app.SetRect(0, 0, Zx(200), Zy(60));
EditDate date1, date2, date3; EditDate date1, date2, date3;
date1 <<= date2 <<= date3 <<= GetSysDate(); date1 <<= date2 <<= date3 <<= GetSysDate();
date1.ClearModify(); date1.ClearModify();

View file

@ -5,14 +5,10 @@ using namespace Upp;
struct MyAppWindow : TopWindow { struct MyAppWindow : TopWindow {
Button exit; Button exit;
void Exit() {
Break(999);
}
MyAppWindow() { MyAppWindow() {
SetRect(0, 0, 100, 100); SetRect(0, 0, Zx(100), Zy(100));
Add(exit.SetLabel("exit").LeftPosZ(10, 64).TopPosZ(10, 24)); Add(exit.SetLabel("exit").LeftPosZ(10, 64).TopPosZ(10, 24));
exit << [=] { Exit(); }; exit << [=] { Break(999); };
} }
}; };

View file

@ -6,9 +6,9 @@ struct MyAppWindow : TopWindow {
Button exit; Button exit;
MyAppWindow() { MyAppWindow() {
SetRect(0, 0, 100, 100); SetRect(0, 0, Zx(100), Zy(100));
Add(exit.SetLabel("exit").LeftPosZ(10, 64).TopPosZ(10, 24)); Add(exit.SetLabel("exit").LeftPosZ(10, 64).TopPosZ(10, 24));
exit <<= Breaker(999); exit << Breaker(999);
} }
}; };

View file

@ -7,7 +7,7 @@ struct MyAppWindow : TopWindow {
EditDate date; EditDate date;
MyAppWindow() { MyAppWindow() {
SetRect(0, 0, 200, 90); SetRect(0, 0, Zx(200), Zy(90));
Add(date.LeftPosZ(10, 80).TopPosZ(10, 20)); Add(date.LeftPosZ(10, 80).TopPosZ(10, 20));
Add(ok.SetLabel("OK").LeftPosZ(10, 64).TopPosZ(40, 24)); Add(ok.SetLabel("OK").LeftPosZ(10, 64).TopPosZ(40, 24));
Add(cancel.SetLabel("Cancel").LeftPosZ(100, 64).TopPosZ(40, 24)); Add(cancel.SetLabel("Cancel").LeftPosZ(100, 64).TopPosZ(40, 24));

View file

@ -1,3 +1,4 @@
LAYOUT(Gui21Layout, 200, 100) LAYOUT(Gui21Layout, 200, 100)
ITEM(MyCtrl, myctrl, LeftPosZ(44, 120).TopPosZ(36, 28)) ITEM(MyCtrl, myctrl, LeftPosZ(44, 120).TopPosZ(36, 28))
END_LAYOUT END_LAYOUT

View file

@ -5,14 +5,10 @@ using namespace Upp;
struct NonModalDialog : public TopWindow { struct NonModalDialog : public TopWindow {
Button b; Button b;
void DoClose() {
Close();
}
NonModalDialog() { NonModalDialog() {
SetRect(0, 0, 200, 50); SetRect(0, 0, Zx(200), Zy(50));
Add(b.SetLabel("Close non-modal dialog").SizePos()); Add(b.SetLabel("Close non-modal dialog").SizePos());
b << [=] { DoClose(); }; b << [=] { Close(); };
} }
}; };
@ -20,17 +16,15 @@ struct MainWindow : public TopWindow {
NonModalDialog dlg; NonModalDialog dlg;
Button b; Button b;
void DoOpen() {
if(dlg.IsOpen())
dlg.Close();
else
dlg.Open(this);
}
MainWindow() { MainWindow() {
SetRect(0, 0, 400, 100); SetRect(0, 0, Zx(400), Zy(100));
Add(b.SetLabel("Open/close non-modal dialog").SizePos()); Add(b.SetLabel("Open/close non-modal dialog").SizePos());
b << [=] { DoOpen(); }; b << [=] {
if(dlg.IsOpen())
dlg.Close();
else
dlg.Open(this);
};
} }
}; };

View file

@ -17,7 +17,7 @@ trTR("Benim ba\305\237vurum")
zhCN("\346\210\221\347\232\204\346\207\211\347\224\250\347\250\213\345\272\217") zhCN("\346\210\221\347\232\204\346\207\211\347\224\250\347\250\213\345\272\217")
T_("Hello translation engine!") T_("Hello translation engine!")
csCZ("Ahoj p\305\231eklada\304\215!") csCZ("Ahoj p\305\231eklada\304\215i!")
deDE("Hallo \303\234bersetzungsmaschine!") deDE("Hallo \303\234bersetzungsmaschine!")
esES("\302\241Hola motor de traducci\303\263n!") esES("\302\241Hola motor de traducci\303\263n!")
frFR("Bonjour le moteur de traduction!") frFR("Bonjour le moteur de traduction!")