feat: port Disks app to MTK

This commit is contained in:
2026-04-15 18:51:42 +02:00
parent ca954517e9
commit 825777e7a7
3 changed files with 378 additions and 374 deletions
+74 -3
View File
@@ -10,7 +10,7 @@
#include <montauk/string.h>
#include <montauk/heap.h>
#include <gui/gui.hpp>
#include <gui/truetype.hpp>
#include <gui/font.hpp>
extern "C" {
#include <string.h>
@@ -33,7 +33,6 @@ static constexpr int MAP_PAD = 16;
static constexpr int MAX_PARTS = 32;
static constexpr int MAX_DISKS = 8;
static constexpr int STATUS_H = 26;
static constexpr int FONT_SIZE = 16;
static constexpr int TB_BTN_Y = 7;
static constexpr int TB_BTN_H = 26;
@@ -120,7 +119,6 @@ struct DiskToolState {
extern int g_win_w, g_win_h;
extern DiskToolState g_state;
extern TrueTypeFont* g_font;
// ============================================================================
// Partition colors
@@ -128,6 +126,79 @@ extern TrueTypeFont* g_font;
extern const Color part_colors[NUM_PART_COLORS];
// ============================================================================
// Shared layout helpers
// ============================================================================
inline int disk_button_width(int idx) {
char label[8];
snprintf(label, sizeof(label), "Disk %d", idx);
return text_width(label) + 16;
}
inline Rect toolbar_disk_button_rect(int idx) {
int bx = 8;
for (int i = 0; i < idx; i++)
bx += disk_button_width(i) + 6;
return {bx, TB_BTN_Y, disk_button_width(idx), TB_BTN_H};
}
inline Rect toolbar_refresh_button_rect() {
return {g_win_w - 8 - 64, TB_BTN_Y, 64, TB_BTN_H};
}
inline Rect toolbar_mount_button_rect() {
Rect refresh = toolbar_refresh_button_rect();
return {refresh.x - 6 - 60, TB_BTN_Y, 60, TB_BTN_H};
}
inline Rect toolbar_format_button_rect() {
Rect mount = toolbar_mount_button_rect();
return {mount.x - 6 - 64, TB_BTN_Y, 64, TB_BTN_H};
}
inline Rect toolbar_newpart_button_rect() {
Rect format = toolbar_format_button_rect();
return {format.x - 6 - 74, TB_BTN_Y, 74, TB_BTN_H};
}
inline int content_title_y() {
return TOOLBAR_H + 8;
}
inline int partition_map_y() {
return content_title_y() + system_font_height() + 8;
}
inline int partition_header_y() {
return partition_map_y() + MAP_H + 8;
}
inline int partition_list_y() {
return partition_header_y() + HEADER_H;
}
inline Rect format_option_rect(int dialog_w, int index) {
int fh = system_font_height();
int sel_y = 12 + fh * 2 + 18;
int opt_y = sel_y + fh + 8;
return {24, opt_y + index * 32, dialog_w - 48, 28};
}
inline Rect dialog_primary_button_rect(int dialog_w, int dialog_h) {
int btn_w = 90;
int btn_h = 30;
int gap = 16;
int total_w = btn_w * 2 + gap;
int bx = (dialog_w - total_w) / 2;
return {bx, dialog_h - btn_h - 16, btn_w, btn_h};
}
inline Rect dialog_secondary_button_rect(int dialog_w, int dialog_h) {
Rect primary = dialog_primary_button_rect(dialog_w, dialog_h);
return {primary.x + primary.w + 16, primary.y, primary.w, primary.h};
}
// ============================================================================
// Function declarations — helpers (main.cpp)
// ============================================================================