feat: use icons in spreadsheet app toolbar

This commit is contained in:
2026-04-08 20:13:57 +02:00
parent ac23989e47
commit b10a5dc662
3 changed files with 63 additions and 6 deletions
+32
View File
@@ -7,6 +7,35 @@
#include "spreadsheet.h"
#include <gui/dialogs.hpp>
#include <gui/standalone.hpp>
#include <gui/svg.hpp>
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);
}
+17 -6
View File
@@ -5,6 +5,8 @@
*/
#include "spreadsheet.h"
#include <gui/canvas.hpp>
#include <gui/svg.hpp>
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
+14
View File
@@ -12,6 +12,7 @@
#include <gui/gui.hpp>
#include <gui/truetype.hpp>
#include <gui/stb_math.h>
#include <gui/svg.hpp>
extern "C" {
#include <string.h>
@@ -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
// ============================================================================