mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
CtrlLib, Doc: Added tutorial about using Key function to handle keyboard keys + alligning directory structure for tutorials.
This commit is contained in:
parent
e6c0fc4f8e
commit
0ed253c70c
10 changed files with 207 additions and 83 deletions
|
|
@ -29,6 +29,5 @@ struct MyAppWindow : TopWindow {
|
|||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyAppWindow app;
|
||||
app.Run();
|
||||
MyAppWindow().Run();
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
description "Menu\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
45
tutorial/Gui05b/main.cpp
Normal file
45
tutorial/Gui05b/main.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct MyAppWindow : TopWindow {
|
||||
String text = "Press any arrow key...";
|
||||
|
||||
bool Key(dword key, int count) override {
|
||||
switch(key) {
|
||||
case K_UP:
|
||||
text = "Up ⬆";
|
||||
Refresh();
|
||||
return true;
|
||||
case K_DOWN:
|
||||
text = "Down ⬇";
|
||||
Refresh();
|
||||
return true;
|
||||
case K_LEFT:
|
||||
text = "Left ⬅";
|
||||
Refresh();
|
||||
return true;
|
||||
case K_RIGHT:
|
||||
text = "Right ⮕";
|
||||
Refresh();
|
||||
return true;
|
||||
default:
|
||||
return TopWindow::Key(key, count);
|
||||
}
|
||||
}
|
||||
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), SWhite);
|
||||
w.DrawText(45, 20, text, Arial(20), Magenta);
|
||||
}
|
||||
|
||||
MyAppWindow() {
|
||||
Title("My application").Zoomable();
|
||||
SetRect(0, 0, 400, 100);
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyAppWindow().Run();
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct MyAppWindow : TopWindow {
|
||||
MenuBar menu;
|
||||
|
||||
void Exit() {
|
||||
if(PromptOKCancel("Exit MyApp?"))
|
||||
Break();
|
||||
}
|
||||
|
||||
void SubMenu(Bar& bar) {
|
||||
bar.Add("Exit", [=] { Exit(); });
|
||||
}
|
||||
|
||||
void MainMenu(Bar& bar) {
|
||||
bar.Sub("Menu", [=](Bar& bar) { SubMenu(bar); });
|
||||
}
|
||||
|
||||
MyAppWindow() {
|
||||
Title("My application with menu").Sizeable();
|
||||
AddFrame(menu);
|
||||
menu.Set([=](Bar& bar) { MainMenu(bar); });
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyAppWindow app;
|
||||
app.Run();
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
description "Menu - as single lambda\377";
|
||||
description "Menu\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
|
|
|||
|
|
@ -5,23 +5,23 @@ using namespace Upp;
|
|||
struct MyAppWindow : TopWindow {
|
||||
MenuBar menu;
|
||||
|
||||
MyAppWindow() {
|
||||
Title("My application with menu").Sizeable();
|
||||
AddFrame(menu);
|
||||
menu.Set(
|
||||
[=](Bar& bar) {
|
||||
bar.Sub("Menu",
|
||||
[=](Bar& bar) {
|
||||
bar.Add("Exit",
|
||||
[=] {
|
||||
void Exit() {
|
||||
if(PromptOKCancel("Exit MyApp?"))
|
||||
Break();
|
||||
}
|
||||
);
|
||||
|
||||
void SubMenu(Bar& bar) {
|
||||
bar.Add("Exit", [=] { Exit(); });
|
||||
}
|
||||
);
|
||||
|
||||
void MainMenu(Bar& bar) {
|
||||
bar.Sub("Menu", [=](Bar& bar) { SubMenu(bar); });
|
||||
}
|
||||
);
|
||||
|
||||
MyAppWindow() {
|
||||
Title("My application with menu").Sizeable();
|
||||
AddFrame(menu);
|
||||
menu.Set([=](Bar& bar) { MainMenu(bar); });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
11
tutorial/Gui07b/Gui07b.upp
Normal file
11
tutorial/Gui07b/Gui07b.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
description "Menu - as single lambda\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
32
tutorial/Gui07b/main.cpp
Normal file
32
tutorial/Gui07b/main.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct MyAppWindow : TopWindow {
|
||||
MenuBar menu;
|
||||
|
||||
MyAppWindow() {
|
||||
Title("My application with menu").Sizeable();
|
||||
AddFrame(menu);
|
||||
menu.Set(
|
||||
[=](Bar& bar) {
|
||||
bar.Sub("Menu",
|
||||
[=](Bar& bar) {
|
||||
bar.Add("Exit",
|
||||
[=] {
|
||||
if(PromptOKCancel("Exit MyApp?"))
|
||||
Break();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyAppWindow app;
|
||||
app.Run();
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue