Pre-commit before it all goes down the drain

This commit is contained in:
Rasmus Rasmussen 2025-12-16 19:18:08 +01:00
parent 6a77bacb7e
commit f56a7fa9f2
5 changed files with 48 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#include "tft_handler.h" #include "tft_handler.h"
#include "event_manager.h" #include "event_manager.h"
#include "GLOBALS.h" #include "GLOBALS.h"
#include <vector>
WindowManager* wm; WindowManager* wm;
Desktop_Hander* dh; Desktop_Hander* dh;
@ -52,6 +53,27 @@ void setup() {
delay(100); delay(100);
// Create test windows // Create test windows
WindowDecoration dec1 = {
.x_offset = 6,
.y_offset = 5,
.width = 25,
.height = 25,
.action = WindowAction::CLOSE,
};
WindowDecoration dec2 = {
.x_offset = 36,
.y_offset = 5,
.width = 25,
.height = 25,
.action = WindowAction::CLOSE,
};
std::vector<WindowDecoration> wdec;
wdec.push_back(dec1);
wdec.push_back(dec2);
Window win1 = { Window win1 = {
.id = 0, .id = 0,
.x = 170, .x = 170,
@ -62,7 +84,7 @@ void setup() {
.foreground_color = COL_DARK_BLUE, .foreground_color = COL_DARK_BLUE,
.focused = false, .focused = false,
.title = "Hello World!", .title = "Hello World!",
.window_actions = {}, .window_decorations = wdec,
}; };
wm->create_window(win1); wm->create_window(win1);
@ -76,7 +98,7 @@ void setup() {
.foreground_color = COL_DARK_BLUE, .foreground_color = COL_DARK_BLUE,
.focused = true, .focused = true,
.title = "Second Window", .title = "Second Window",
.window_actions = {}, .window_decorations = wdec,
}; };
wm->create_window(win2); wm->create_window(win2);

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#define MAX_SCREEN_WIDTH 480
#define MAX_SCREEN_HEIGHT 320
enum CLICK_EVENTS { enum CLICK_EVENTS {
NONE = 0, NONE = 0,
LEFT_CLICK = 1, LEFT_CLICK = 1,

View File

@ -59,9 +59,7 @@ void Desktop_Hander::draw_desktop_Item(const Desktop_Item& desktop_item) {
} }
void Desktop_Hander::on_click_event(const CLICK_EVENT& event) { void Desktop_Hander::on_click_event(const CLICK_EVENT& event) {
if (event.event != CLICK_EVENTS::LEFT_CLICK) { if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
return;
}
int id = handle_desktop_click(event); int id = handle_desktop_click(event);
bool task_bar_clicked = handle_taskbar_click(event); bool task_bar_clicked = handle_taskbar_click(event);

View File

@ -6,6 +6,16 @@ enum class WindowAction {
EXIT = 1, EXIT = 1,
FILE = 2, FILE = 2,
HELP = 3, HELP = 3,
MINIMIZE = 4,
CLOSE = 5,
};
struct WindowDecoration {
int x_offset;
int y_offset;
int width;
int height;
WindowAction action;
}; };
struct Window { struct Window {
@ -18,5 +28,5 @@ struct Window {
int foreground_color; int foreground_color;
bool focused; bool focused;
std::string title; std::string title;
std::vector<WindowAction> window_actions; std::vector<WindowDecoration> window_decorations;
}; };

View File

@ -1,3 +1,4 @@
#include "GLOBALS.h"
#include "window_manager.h" #include "window_manager.h"
#include <algorithm> #include <algorithm>
@ -13,8 +14,9 @@ void WindowManager::create_window(Window window) {
int total_pos_x = window.x + window.width; int total_pos_x = window.x + window.width;
int total_pos_y = window.y + window.height; int total_pos_y = window.y + window.height;
if (total_pos_x > 480) window.x = total_pos_x - 480; // Clamp window within the screen size AND taskbar
if (total_pos_y > 320) window.y = total_pos_y - 320; if (total_pos_x > MAX_SCREEN_WIDTH) window.x = MAX_SCREEN_WIDTH - window.width;
if (total_pos_y > MAX_SCREEN_HEIGHT) window.y = MAX_SCREEN_HEIGHT - window.height - 29;
windows.push_back(window); windows.push_back(window);
display_state->update_display.store(true); display_state->update_display.store(true);
@ -68,15 +70,11 @@ void WindowManager::draw_window(const Window& window) {
} }
void WindowManager::on_click_event(const CLICK_EVENT& event) { void WindowManager::on_click_event(const CLICK_EVENT& event) {
if (event.event != CLICK_EVENTS::LEFT_CLICK) { if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
return;
}
int clicked_id = handle_window_click(event); int clicked_id = handle_window_click(event);
if (clicked_id >= 0) { if (clicked_id >= 0) display_state->update_display.store(true);
display_state->update_display.store(true);
}
} }
int WindowManager::handle_window_click(const CLICK_EVENT& event) { int WindowManager::handle_window_click(const CLICK_EVENT& event) {
@ -88,9 +86,9 @@ int WindowManager::handle_window_click(const CLICK_EVENT& event) {
if (event.x >= window.x && event.x <= (window.x + window.width) && if (event.x >= window.x && event.x <= (window.x + window.width) &&
event.y >= window.y && event.y <= (window.y + window.height)) { event.y >= window.y && event.y <= (window.y + window.height)) {
if (window.focused) { if (window.focused) return -1;
return -1;
}
// Unfocus all windows // Unfocus all windows
for (auto& win : windows) { for (auto& win : windows) {