From b10a5dc662ebc9fcc8a2d758da0b4327db7d0824 Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Wed, 8 Apr 2026 20:13:57 +0200 Subject: [PATCH] feat: use icons in spreadsheet app toolbar --- programs/src/spreadsheet/main.cpp | 32 ++++++++++++++++++++++++++ programs/src/spreadsheet/render.cpp | 23 +++++++++++++----- programs/src/spreadsheet/spreadsheet.h | 14 +++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/programs/src/spreadsheet/main.cpp b/programs/src/spreadsheet/main.cpp index 7330a7b..d27e54b 100644 --- a/programs/src/spreadsheet/main.cpp +++ b/programs/src/spreadsheet/main.cpp @@ -7,6 +7,35 @@ #include "spreadsheet.h" #include #include +#include + +SvgIcon g_icon_folder = {}; +SvgIcon g_icon_save = {}; +SvgIcon g_icon_cut = {}; +SvgIcon g_icon_copy = {}; +SvgIcon g_icon_paste = {}; + +void ss_load_icons() { + Color def_color = HEADER_TEXT; + if (!g_icon_folder.pixels) + g_icon_folder = svg_load("0:/icons/folder.svg", 16, 16, def_color); + if (!g_icon_save.pixels) + g_icon_save = svg_load("0:/icons/document-save-symbolic.svg", 16, 16, def_color); + if (!g_icon_cut.pixels) + g_icon_cut = svg_load("0:/icons/edit-cut.svg", 16, 16, def_color); + if (!g_icon_copy.pixels) + g_icon_copy = svg_load("0:/icons/edit-copy.svg", 16, 16, def_color); + if (!g_icon_paste.pixels) + g_icon_paste = svg_load("0:/icons/edit-paste.svg", 16, 16, def_color); +} + +void ss_unload_icons() { + if (g_icon_folder.pixels) svg_free(g_icon_folder); + if (g_icon_save.pixels) svg_free(g_icon_save); + if (g_icon_cut.pixels) svg_free(g_icon_cut); + if (g_icon_copy.pixels) svg_free(g_icon_copy); + if (g_icon_paste.pixels) svg_free(g_icon_paste); +} // ============================================================================ // Global state definitions @@ -264,6 +293,8 @@ extern "C" void _start() { g_font = load_font("0:/fonts/Roboto-Medium.ttf"); g_font_bold = load_font("0:/fonts/Roboto-Bold.ttf"); + ss_load_icons(); + // Check for file argument char args[512] = {}; int arglen = montauk::getargs(args, sizeof(args)); @@ -799,5 +830,6 @@ extern "C" void _start() { } win.destroy(); + ss_unload_icons(); montauk::exit(0); } diff --git a/programs/src/spreadsheet/render.cpp b/programs/src/spreadsheet/render.cpp index cac01dd..80eb078 100644 --- a/programs/src/spreadsheet/render.cpp +++ b/programs/src/spreadsheet/render.cpp @@ -5,6 +5,8 @@ */ #include "spreadsheet.h" +#include +#include void render(uint32_t* pixels) { px_fill(pixels, g_win_w, g_win_h, 0, 0, g_win_w, g_win_h, BG_COLOR); @@ -15,6 +17,9 @@ void render(uint32_t* pixels) { Cell* cur_cell = &g_cells[g_sel_row][g_sel_col]; + // Canvas for icons + gui::Canvas c(pixels, g_win_w, g_win_h); + int bx = 4; auto tb_btn = [&](int w, bool active, const char* label) { Color bg = active ? TB_BTN_ACTIVE : TB_BTN_BG; @@ -28,20 +33,26 @@ void render(uint32_t* pixels) { } bx += w + 4; }; + auto tb_icon_btn = [&](const SvgIcon& icon) { + px_fill_rounded(pixels, g_win_w, g_win_h, bx, TB_BTN_Y, TB_BTN_SIZE, TB_BTN_SIZE, TB_BTN_RAD, TB_BTN_BG); + if (icon.pixels) + c.icon(bx + 4, TB_BTN_Y + 4, icon); + bx += TB_BTN_SIZE + 4; + }; auto tb_sep = [&]() { px_vline(pixels, g_win_w, g_win_h, bx, 6, TOOLBAR_H - 12, TB_SEP_COLOR); bx += 8; }; - // Open / Save - tb_btn(36, false, "Open"); - tb_btn(36, false, "Save"); + // Open / Save (icon buttons) + tb_icon_btn(g_icon_folder); + tb_icon_btn(g_icon_save); tb_sep(); // Cut/Copy/Paste - tb_btn(28, false, "Cut"); - tb_btn(36, false, "Copy"); - tb_btn(36, false, "Paste"); + tb_icon_btn(g_icon_cut); + tb_icon_btn(g_icon_copy); + tb_icon_btn(g_icon_paste); tb_sep(); // Bold diff --git a/programs/src/spreadsheet/spreadsheet.h b/programs/src/spreadsheet/spreadsheet.h index 27502c5..f847052 100644 --- a/programs/src/spreadsheet/spreadsheet.h +++ b/programs/src/spreadsheet/spreadsheet.h @@ -12,6 +12,7 @@ #include #include #include +#include extern "C" { #include @@ -266,6 +267,19 @@ void auto_fit_column(int col); void render(uint32_t* pixels); +// ============================================================================ +// Icons +// ============================================================================ + +extern SvgIcon g_icon_folder; +extern SvgIcon g_icon_save; +extern SvgIcon g_icon_cut; +extern SvgIcon g_icon_copy; +extern SvgIcon g_icon_paste; + +void ss_load_icons(); +void ss_unload_icons(); + // ============================================================================ // Function declarations — main.cpp // ============================================================================