You can now have in-window buttons and they work.
This commit is contained in:
parent
59b8c3ce3c
commit
1cb93af0bc
@ -98,11 +98,42 @@ private:
|
|||||||
bool showing_buttons = false;
|
bool showing_buttons = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void on_click_event(CLICK_EVENT event) override {
|
void on_click_event(CLICK_EVENT event) {
|
||||||
if (_window->minimized) return;
|
if (_window->minimized) return;
|
||||||
|
|
||||||
|
for (short i = 0; i < _window->content_buttons.size(); ++i) {
|
||||||
|
auto c_button = _window->content_buttons[i];
|
||||||
|
if (event.x >= c_button.x && event.x <= (c_button.x + c_button.width) && event.y >= c_button.y && event.y <= (c_button.y + c_button.height)) {
|
||||||
|
if (c_button.action == "show resources") {
|
||||||
|
for (short j = 0; j < _window->content_buttons.size(); ++j) {
|
||||||
|
_window->content_buttons[j].pressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("I'm tired, boss...");
|
||||||
|
|
||||||
|
_window->content_buttons[i].pressed = true;
|
||||||
|
_display_state->update_display.store(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c_button.action == "show tasks") {
|
||||||
|
for (short j = 0; j < _window->content_buttons.size(); ++j) {
|
||||||
|
_window->content_buttons[j].pressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("ok...");
|
||||||
|
|
||||||
|
_window->content_buttons[i].pressed = true;
|
||||||
|
_display_state->update_display.store(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() override {
|
void run() override {
|
||||||
|
EventManager::getInstance().subscribe(this);
|
||||||
|
|
||||||
_window->x += 150;
|
_window->x += 150;
|
||||||
_window->width -= 50;
|
_window->width -= 50;
|
||||||
|
|
||||||
@ -154,11 +185,20 @@ public:
|
|||||||
show_resources.action = "show resources";
|
show_resources.action = "show resources";
|
||||||
show_resources.x = _window->x + 7;
|
show_resources.x = _window->x + 7;
|
||||||
show_resources.y = _window->y + 40;
|
show_resources.y = _window->y + 40;
|
||||||
show_resources.width = 70;
|
show_resources.width = 80;
|
||||||
show_resources.height = 10;
|
show_resources.height = 10;
|
||||||
show_resources.pressed = true;
|
show_resources.pressed = true;
|
||||||
|
|
||||||
|
ContentButton show_tasks;
|
||||||
|
show_tasks.action = "show tasks";
|
||||||
|
show_tasks.x = _window->x + show_resources.width + 13;
|
||||||
|
show_tasks.y = _window->y + 40;
|
||||||
|
show_tasks.width = 70;
|
||||||
|
show_tasks.height = 10;
|
||||||
|
show_tasks.pressed = false;
|
||||||
|
|
||||||
_window->content_buttons.push_back(show_resources);
|
_window->content_buttons.push_back(show_resources);
|
||||||
|
_window->content_buttons.push_back(show_tasks);
|
||||||
|
|
||||||
// Variables for metrics
|
// Variables for metrics
|
||||||
size_t total_ram;
|
size_t total_ram;
|
||||||
@ -223,7 +263,7 @@ public:
|
|||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1));
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
if (counter == 1000) {
|
if (counter == 1000) {
|
||||||
Serial.printf("internal_total %i\n", internal_total);
|
/*Serial.printf("internal_total %i\n", internal_total);
|
||||||
Serial.printf("internal_free %i\n", internal_free);
|
Serial.printf("internal_free %i\n", internal_free);
|
||||||
Serial.printf("psram_total %i\n", psram_total);
|
Serial.printf("psram_total %i\n", psram_total);
|
||||||
Serial.printf("psram_free %i\n", psram_free);
|
Serial.printf("psram_free %i\n", psram_free);
|
||||||
@ -232,7 +272,7 @@ public:
|
|||||||
Serial.printf("used_ram %i\n", used_ram);
|
Serial.printf("used_ram %i\n", used_ram);
|
||||||
Serial.printf("ram_percent %f.2\n", ram_percent);
|
Serial.printf("ram_percent %f.2\n", ram_percent);
|
||||||
Serial.printf("cpu_percent %f.2\n", cpu_percent);
|
Serial.printf("cpu_percent %f.2\n", cpu_percent);
|
||||||
Serial.println("===============");
|
Serial.println("===============");*/
|
||||||
_display_state->update_display.store(true);
|
_display_state->update_display.store(true);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,10 @@ void Program::task_wrapper(void* pvParameters) {
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Program::on_click_event(CLICK_EVENT event) {
|
||||||
|
// Default implementation, do nothing
|
||||||
|
}
|
||||||
|
|
||||||
void Program::close() {
|
void Program::close() {
|
||||||
_running = false;
|
_running = false;
|
||||||
if (_task_handle) {
|
if (_task_handle) {
|
||||||
|
|||||||
@ -107,7 +107,7 @@ public:
|
|||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
// listen to click events
|
// listen to click events
|
||||||
void on_click_event(CLICK_EVENT event) override {}
|
void on_click_event(CLICK_EVENT event) override;
|
||||||
|
|
||||||
// Called when the program should stop
|
// Called when the program should stop
|
||||||
virtual void close();
|
virtual void close();
|
||||||
|
|||||||
@ -37,15 +37,17 @@ void TFT_Handler::draw_button(short x, short y, short size_x, short size_y, int
|
|||||||
if (pressed) {
|
if (pressed) {
|
||||||
sprite.fillRect(x - 2, y - 2, size_x + 2, size_y + 2, COL_BLACK);
|
sprite.fillRect(x - 2, y - 2, size_x + 2, size_y + 2, COL_BLACK);
|
||||||
sprite.fillRect(x - 1, y - 1, size_x + 1, size_y + 1, COL_DARK_GREY);
|
sprite.fillRect(x - 1, y - 1, size_x + 1, size_y + 1, COL_DARK_GREY);
|
||||||
sprite.fillRect(x + 2, y + 2, size_x + 2, size_y + 2, COL_WHITE);
|
|
||||||
sprite.fillRect(x, y, size_x, size_y, color);
|
sprite.fillRect(x, y, size_x, size_y, color);
|
||||||
sprite.setTextColor(COL_BLACK);
|
sprite.setTextColor(COL_BLACK);
|
||||||
sprite.setTextSize(1);
|
sprite.setTextSize(1);
|
||||||
sprite.drawString(str.c_str(), x, y);
|
sprite.drawString(str.c_str(), x, y);
|
||||||
} else {
|
} else {
|
||||||
|
sprite.fillRect(x, y, size_x + 2, size_y + 2, COL_BLACK);
|
||||||
|
sprite.fillRect(x, y, size_x + 1, size_y + 1, COL_DARK_GREY);
|
||||||
sprite.fillRect(x, y, size_x, size_y, color);
|
sprite.fillRect(x, y, size_x, size_y, color);
|
||||||
sprite.fillRect(x, y, size_x, size_y, color);
|
sprite.setTextColor(COL_BLACK);
|
||||||
sprite.fillRect(x, y, size_x, size_y, color);
|
sprite.setTextSize(1);
|
||||||
|
sprite.drawString(str.c_str(), x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user