Tutorial: small rework of Gui23.

This commit is contained in:
Zbigniew Rębacz 2023-10-28 21:20:29 +02:00
parent 80a3237686
commit 21816d69e7
4 changed files with 117 additions and 48 deletions

View file

@ -4,6 +4,7 @@ uses
CtrlLib;
file
myapp.lay,
main.cpp;
mainconfig

View file

@ -2,31 +2,17 @@
using namespace Upp;
struct MyAppWindow : TopWindow {
struct RandomRectCtrl : public Ctrl {
Rect rect;
Color color;
MyAppWindow() {
Zoomable().SetRect(0, 0, 200, 200);
RandomizeRect();
SetTimeCallback(-2000, [=] { OnTimer(); });
}
~MyAppWindow() {
KillTimeCallback();
}
void Paint(Draw& w) override {
Size sz = GetSize();
w.DrawRect(sz, White());
w.DrawRect(rect, color);
}
void OnTimer() {
RandomizeRect();
Refresh();
if (!rect.IsEmpty()) {
w.DrawRect(rect, color);
}
}
void RandomizeRect() {
@ -41,6 +27,41 @@ struct MyAppWindow : TopWindow {
}
};
#define LAYOUTFILE <Gui23/myapp.lay>
#include <CtrlCore/lay.h>
struct MyAppWindow : public WithMyAppLayout<TopWindow> {
MyAppWindow() {
CtrlLayout(*this, "MyApp");
start_stop_btn << [=] { OnStartStop(); };
}
~MyAppWindow() {
// Not needed will be automatically call upon Ctrl destruction.
// KillTimeCallback();
}
void OnStartStop() {
if (random_rect_ctrl.rect.IsEmpty()) {
start_stop_btn.SetLabel("Stop!");
SetTimeCallback(-2000, [=] { OnTimer(); });
} else {
KillTimeCallback();
start_stop_btn.SetLabel("Start!");
random_rect_ctrl.rect = {};
random_rect_ctrl.Refresh();
}
}
void OnTimer() {
random_rect_ctrl.RandomizeRect();
random_rect_ctrl.Refresh();
}
};
GUI_APP_MAIN
{
MyAppWindow().Run();

5
tutorial/Gui23/myapp.lay Normal file
View file

@ -0,0 +1,5 @@
LAYOUT(MyAppLayout, 200, 200)
ITEM(Upp::Button, start_stop_btn, SetLabel(t_("Start!")).HSizePosZ(8, 8).BottomPosZ(4, 20))
ITEM(RandomRectCtrl, random_rect_ctrl, HSizePosZ(8, 8).VSizePosZ(8, 28))
END_LAYOUT

File diff suppressed because one or more lines are too long