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
|
GUI_APP_MAIN
|
||||||
{
|
{
|
||||||
MyAppWindow app;
|
MyAppWindow().Run();
|
||||||
app.Run();
|
|
||||||
}
|
}
|
||||||
|
|
@ -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
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
|
uses
|
||||||
CtrlLib;
|
CtrlLib;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
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