From cc37e170462c55316338945deb79e9841d143fb1 Mon Sep 17 00:00:00 2001 From: Mid <> Date: Sun, 27 Jul 2025 16:18:23 +0300 Subject: [PATCH] immdraw.h --- src/immdraw.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/immdraw.h diff --git a/src/immdraw.h b/src/immdraw.h new file mode 100644 index 0000000..528146a --- /dev/null +++ b/src/immdraw.h @@ -0,0 +1,27 @@ +#pragma once + +#include"k3batch.h" +#include"k3font.h" +#include"k3menu.h" + +static inline void immdraw_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, float r, float g, float b, float a, float borderRadius) { + k3BatchAdd(NULL, (struct k3RectF) {0, 0, 1, 1}, (struct k3RectF) { + x, y, + w, h + }, 0, (vec4) {r, g, b, a}, borderRadius); +} + +static inline void immdraw_font_draw(struct k3Font *font, int16_t x, int16_t y, int16_t w, float sz, size_t len, const char *txt, int alignment, float r, float g, float b, float a) { + if(alignment != k3M_ALIGN_LEFT) { + struct k3RectF txtsz; + k3FontSz(font, sz, txt, &txtsz); + + if(alignment == k3M_ALIGN_CENTER) { + x += w / 2.0f - txtsz.w / 2.0f; + } else { + x += w - txtsz.w; + } + } + + k3FontDraw(font, x, y, sz, txt, (vec4) {r, g, b, a}); +}