Files
kryon/include/kry_backend.h
T
waozi 84bd26de20 krb v2: text input — TEXTINPUT node + typed-codepoint vtable path
New node type 13: bounded field drawing the mounted CSTR with a
blinking caret when focused (click to focus). Typed input flows through
the new optional KryBackend.text_key (codepoints, 0x08 backspace):
kry_sw queues via KrySwText (drained per frame by Advance), the raylib
surface backend maps GetCharPressed, SDL maps SDL_TEXTINPUT/BACKSPACE,
krb-web exports krb_web_text from keypress events. UTF-8 runes append
and strip correctly. k2b compiles TextField(x,y,w,h,&state.field).

Verified: click-focus, typing with backspace, and that unfocused
fields ignore keys.
2026-08-16 22:06:53 -03:00

66 lines
2.2 KiB
C

#ifndef KRY_BACKEND_H
#define KRY_BACKEND_H
/*
* Small draw/input table for cartridges and non-raylib hosts.
* The public app API (DrawRectangle, GetMousePosition, ...) stays as it is.
* A .krb walker only calls this table so raylib, the null backend, a
* framebuffer, or /dev/draw can host the same image.
*/
enum {
KRY_THEME_BACKGROUND = 0,
KRY_THEME_TEXT = 1,
KRY_THEME_ICON = 2,
KRY_THEME_SURFACE = 3,
KRY_THEME_BUTTON = 4,
KRY_THEME_COUNT
};
enum {
KRY_MOUSE_LEFT = 0,
KRY_MOUSE_RIGHT = 1,
KRY_MOUSE_MIDDLE = 2
};
typedef struct KryBackend {
void (*clear)(unsigned color);
void (*rect)(int x, int y, int w, int h, unsigned color);
void (*text)(const char *s, int x, int y, int size, unsigned color);
int (*measure_text)(const char *s, int size);
void (*clip_push)(int x, int y, int w, int h);
void (*clip_pop)(void);
void (*mouse)(int *x, int *y);
int (*mouse_down)(int button);
int (*mouse_pressed)(int button);
int (*width)(void);
int (*height)(void);
float (*time)(void);
int (*scale_px)(int px);
unsigned (*theme_color)(int slot);
void (*texture)(const char *asset_path, int x, int y, int w, int h,
unsigned tint, int fit);
/* Added in the v2 cartridge format. Older engines may leave these NULL;
* drawers must check before calling. */
void (*circle)(int cx, int cy, int radius, unsigned color);
void (*ring)(int cx, int cy, int inner, int outer, unsigned color);
/* Draw in-memory RGBA8 pixels (cartridge-embedded assets) scaled into
* the given destination rect. Optional like circle/ring. */
void (*texture_rgba)(const unsigned char *rgba, int sw, int sh,
int x, int y, int dw, int dh, unsigned tint);
/* Mouse-wheel delta (pixels) accumulated since the last poll; positive
* scrolls up. Optional. */
int (*wheel)(void);
/* Pop one typed codepoint from this frame's queue; 0 when empty.
* 0x08 = backspace. Optional. */
unsigned (*text_key)(void);
} KryBackend;
extern const KryBackend KryBackendDraw;
extern const KryBackend KryBackendNull;
const KryBackend *KryBackendCurrent(void);
void KryBackendSelect(const KryBackend *backend);
#endif