Doc, Tutorial: Fixed bug in GUI23 caused by uninitialized value.

This commit is contained in:
Zbigniew Rębacz 2025-06-18 10:03:47 +02:00
parent 9c0dd92628
commit 157bb81739
2 changed files with 17 additions and 3 deletions

View file

@ -3,7 +3,7 @@
using namespace Upp;
struct RandomRectCtrl : public Ctrl {
Rect rect;
Rect rect = Rect(Size(0, 0));
Color color;
void Paint(Draw& w) override {
@ -46,12 +46,17 @@ struct MyAppWindow : public WithMyAppLayout<TopWindow> {
if (random_rect_ctrl.rect.IsEmpty()) {
start_stop_btn.SetLabel("Stop!");
// When the user clicks the "Start" button, OnTimer() is immediately executed after
// all related events have been processed, to generate and display a random rectangle.
SetTimeCallback(0, [=] { OnTimer(); });
// Calls OnTimer() every two seconds to update the random position of a rectangle.
SetTimeCallback(-2000, [=] { OnTimer(); });
} else {
KillTimeCallback();
start_stop_btn.SetLabel("Start!");
random_rect_ctrl.rect = {};
random_rect_ctrl.rect.Clear();
random_rect_ctrl.Refresh();
}
}