Drawing
The draw calls emit glyph records into a gfx_list for a font bound with gfx_font_bind, and return the pen advance.
text_font_drawplaces a run at a baseline. Every widget inui.hends up here.text_font_draw_inlays the run out once and aligns it inside a width withtext_font_left,text_font_centreortext_font_right.text_font_startandtext_font_endread as left and right here, and only swap in the direction aware calls. See direction and bidi.text_font_draw_fitdoes the same, and cuts the run with a mark when it does not fit. The mark lands wheretext_font_elidewould put it, and no byte count caps the run.
Each call asks gfx_glyphs_tail for room, lays the glyphs straight into the free tail of the list and then commits them. A full list flushes or grows first, so a run is only cut when memory runs out.
text_drawing.cpp
#include "isolenui/text/text_font.h"
// draw emits glyph records at a baseline and returns the pen advance, the
// call every widget in ui.h bottoms out on
static float draw_label(const text_font* f, gfx_list* out, gfx_font handle,
const char* label, float x, float baseline)
{
return text_font_draw(f, out, handle, 0u, label, TEXT_FONT_TERMINATED, x,
baseline, 14.0f, 0.0f, 0xffe6e6e6u);
}
// draw_in lays the run out once and aligns it inside a width, a column of
// numbers that share a right edge
static float draw_right_aligned(const text_font* f, gfx_list* out,
gfx_font handle, const char* value, float x,
float width, float baseline)
{
return text_font_draw_in(f, out, handle, 2u, value, TEXT_FONT_TERMINATED,
x, width, baseline, 14.0f, 0.0f, 0xffe6e6e6u,
text_font_right);
}
// draw_fit cuts the run with a mark when it does not fit, the mark lands
// where text_font_elide would put it, with no buffer to size
static float draw_file_name(const text_font* f, gfx_list* out, gfx_font handle,
const char* path, float x, float width, float baseline)
{
return text_font_draw_fit(f, out, handle, 0u, path, TEXT_FONT_TERMINATED, x,
width, baseline, 13.0f, 0.0f, 0xff999999u,
text_font_left);
}
// wrapped lines drawn one by one from the offsets text_font_wrap returns
static void draw_paragraph(const text_font* f, gfx_list* out, gfx_font handle,
const char* utf8, float x, float y, float width)
{
const float px = 16.0f;
text_line lines[16];
uint32_t n = text_font_wrap(f, 0u, utf8, TEXT_FONT_TERMINATED, px, 0.0f,
width, lines, 16u);
n = n < 16u ? n : 16u;
float baseline = y + text_font_ascent(f, px);
for (uint32_t i = 0; i < n; ++i) {
text_font_draw_in(f, out, handle, 0u, utf8 + lines[i].start, lines[i].len,
x, width, baseline, px, 0.0f, 0xffe6e6e6u,
text_font_centre);
baseline += text_font_line_height(f, px);
}
}