framer
Slide-show application for nerds ☝️🤓
Name | Size | Mode | |
.. | |||
src/text.h | 1133B | -rw-r--r-- |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#ifndef TEXT_H_ #define TEXT_H_ #include <stddef.h> #include "raylib.h" #define NOB_IMPLEMENTATION #include "nob.h" typedef struct { const char* text; Color color; size_t width; size_t x_offset; } Span; typedef struct { Span* items; size_t count; size_t capacity; size_t width; int font_size; } LineBuilder; void lb_append(LineBuilder *lb, const char *text, Color color) { size_t text_width = MeasureText(text, lb->font_size); Span le = { .text = text, .color = color, .width = text_width, .x_offset = lb->width, }; nob_da_append(lb, le); lb->width += text_width; } LineBuilder lb_line(const char *text, Color color, int font_size) { LineBuilder lb = {0}; lb.font_size = font_size; lb_append(&lb, text, color); return lb; } void lb_draw(LineBuilder *lb, int x, int y) { for (size_t i = 0; i < lb->count; i++) { Span le = lb->items[i]; DrawText(le.text, x + le.x_offset, y, lb->font_size, le.color); } } void lb_draw_centered(LineBuilder *lb, int y) { int x = (GetScreenWidth() - lb->width)/2; lb_draw(lb, x, y); } #endif // TEXT_H_