Holy shit it actually worked lol

This commit is contained in:
Rasmus Rasmussen 2025-12-16 19:50:53 +01:00
parent f56a7fa9f2
commit 526ba71d57
2 changed files with 26 additions and 7 deletions

View File

@ -67,7 +67,7 @@ void setup() {
.y_offset = 5,
.width = 25,
.height = 25,
.action = WindowAction::CLOSE,
.action = WindowAction::MINIMIZE,
};
std::vector<WindowDecoration> wdec;

View File

@ -1,3 +1,4 @@
#include "window.h"
#include "GLOBALS.h"
#include "window_manager.h"
#include <algorithm>
@ -56,12 +57,19 @@ void WindowManager::draw_window(const Window& window) {
// Decorations
tft->draw_box(window.x + 3, window.y + 3, window.width - 6, 30, window.foreground_color);
// Close button
tft->draw_box(window.x + 6, window.y + 5, 25, 25, COL_RED);
// Minimize button
tft->draw_box(window.x + 6 + 30, window.y + 5, 25, 25, COL_LIGHT_GREY);
for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) {
if (it->action == WindowAction::CLOSE) {
// Close button
tft->draw_box(window.x + it->x_offset, window.y + it->y_offset, it->height, it->width, COL_RED);
}
if (it->action == WindowAction::MINIMIZE) {
// Minimize button
tft->draw_box(window.x + it->x_offset, window.y + it->y_offset, it->height, it->width, COL_LIGHT_GREY);
}
}
// Window title
tft->draw_text(window.x + 6 + 65, window.y + 10, window.title.c_str());
@ -86,9 +94,20 @@ int WindowManager::handle_window_click(const CLICK_EVENT& event) {
if (event.x >= window.x && event.x <= (window.x + window.width) &&
event.y >= window.y && event.y <= (window.y + window.height)) {
if (window.focused) return -1;
Serial.println("lol");
for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) {
int x = window.x + it->x_offset;
int y = window.y + it->y_offset;
Serial.printf("x: %i y: %i\n", x, y);
if (event.x >= x && event.x <= (x + it->width) && event.y >= y && event.y <= (y + it->height) && it->action == WindowAction::CLOSE) {
Serial.println("lollllll");
close_window(window.id);
return window.id;
}
}
if (window.focused) return -1;
// Unfocus all windows
for (auto& win : windows) {