CtrlLib, Doc: Added tutorial about using Key function to handle keyboard keys + alligning directory structure for tutorials.

This commit is contained in:
Zbigniew Rębacz 2026-01-09 00:28:03 +01:00
parent e6c0fc4f8e
commit 0ed253c70c
10 changed files with 207 additions and 83 deletions

View file

@ -29,6 +29,5 @@ struct MyAppWindow : TopWindow {
GUI_APP_MAIN GUI_APP_MAIN
{ {
MyAppWindow app; MyAppWindow().Run();
app.Run();
} }

View file

@ -1,11 +1,9 @@
description "Menu\377"; uses
CtrlLib;
uses
CtrlLib; file
main.cpp;
file
main.cpp; mainconfig
"" = "GUI";
mainconfig
"" = "GUI";

45
tutorial/Gui05b/main.cpp Normal file
View 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();
}

View file

@ -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();
}

View file

@ -1,4 +1,4 @@
description "Menu - as single lambda\377"; description "Menu\377";
uses uses
CtrlLib; CtrlLib;

View file

@ -1,32 +1,32 @@
#include <CtrlLib/CtrlLib.h> #include <CtrlLib/CtrlLib.h>
using namespace Upp; using namespace Upp;
struct MyAppWindow : TopWindow { struct MyAppWindow : TopWindow {
MenuBar menu; MenuBar menu;
MyAppWindow() { void Exit() {
Title("My application with menu").Sizeable(); if(PromptOKCancel("Exit MyApp?"))
AddFrame(menu); Break();
menu.Set( }
[=](Bar& bar) {
bar.Sub("Menu", void SubMenu(Bar& bar) {
[=](Bar& bar) { bar.Add("Exit", [=] { Exit(); });
bar.Add("Exit", }
[=] {
if(PromptOKCancel("Exit MyApp?")) void MainMenu(Bar& bar) {
Break(); 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 GUI_APP_MAIN
{ {
MyAppWindow app; MyAppWindow app;
app.Run(); app.Run();
} }

View 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
View 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