|
Operator SDK
Build MIDI processing and UI modes for the Operator device
|
Text measurement and layout helpers for mode UIs. More...
Functions | |
| void | format_uint (uint32_t v, char *out, uint8_t out_size) |
| Overwrite out with the decimal digits of v, NUL-terminated. | |
| void | format_int (int32_t v, char *out, uint8_t out_size, bool force_plus=false) |
| Overwrite out with the signed decimal of v, NUL-terminated. | |
| void | append_uint (char *buf, uint8_t buf_size, uint32_t v) |
| Append the decimal digits of v at the existing NUL of buf. | |
| void | append_int (char *buf, uint8_t buf_size, int32_t v, bool force_plus=false) |
| Append the signed decimal of v at the existing NUL of buf. | |
| void | format_str (const char *s, char *out, uint8_t out_size) |
| Overwrite out with a bounded copy of s (freestanding strlcpy). | |
| void | append_str (char *buf, uint8_t buf_size, const char *s) |
| Append a bounded copy of s at the existing NUL of buf (freestanding strcat). | |
| void | append_enum (char *buf, uint8_t buf_size, uint32_t idx, const char *const *labels, uint32_t count, const char *fallback="?") |
| Append labels[idx] at the existing NUL of buf, bounds-checked. | |
| void | append_fixed (char *buf, uint8_t buf_size, int32_t value, uint8_t decimals) |
| Append value as a fixed-point decimal with decimals fractional digits at the existing NUL of buf. | |
| uint16_t | strlen_chars (const char *s) |
| Count the characters in a NUL-terminated string. | |
| uint16_t | text_width (const char *s) |
| Pixel width of a string rendered in the standard 5x7 font. | |
| uint16_t | large_text_width (const char *s) |
| Pixel width of a string rendered in the large 8x12 font. | |
| uint16_t | align_center_x (const char *s, uint16_t total_w) |
| X-offset that horizontally centers a standard-font string inside a box. | |
| uint16_t | large_align_center_x (const char *s, uint16_t total_w) |
| X-offset that horizontally centers a large-font string inside a box. | |
| void | truncate_with_ellipsis (const char *s, uint16_t max_chars, char *out, uint16_t out_size) |
| Copy s into out, appending "..." when it exceeds max_chars. | |
| uint8_t | word_wrap (const char *s, uint16_t width_px, const char **line_starts, uint8_t max_lines) |
| Greedy word-wrap a NUL-terminated string into lines no wider than width_px pixels (standard font). | |
Variables | |
| constexpr uint8_t | kFontStdAdvance = 6 |
| Horizontal advance (pixels) of one standard-font glyph. | |
| constexpr uint8_t | kFontStdSpaceAdvance = 4 |
| Horizontal advance (pixels) of the standard-font space glyph. | |
| constexpr uint8_t | kFontStdHeight = 8 |
| Line height (pixels) of the standard font. | |
| constexpr uint8_t | kFontLargeAdvance = 8 |
| Horizontal advance (pixels) of one large-font glyph. | |
| constexpr uint8_t | kFontLargeSpaceAdvance = 6 |
| Horizontal advance (pixels) of the large-font space glyph. | |
| constexpr uint8_t | kFontLargeHeight = 13 |
| Line height (pixels) of the large font. | |
Text measurement and layout helpers for mode UIs.
|
inline |
X-offset that horizontally centers a standard-font string inside a box.
| s | Text to measure. |
| total_w | Width of the containing box in pixels. |
|
inline |
Append labels[idx] at the existing NUL of buf, bounds-checked.
| buf | NUL-terminated buffer to extend in place. Non-null. |
| buf_size | Total capacity of buf in bytes. The appended label truncates to fit; buf stays NUL-terminated. |
| idx | Index into labels. If idx >= count the fallback string is appended instead (no out-of-range read). |
| labels | Caller-owned label table (count entries). This helper only indexes it safely. The mode owns the storage. |
| count | Number of entries in labels. |
| fallback | Appended when idx is out of range (default "?"). |
Composes e.g. char b[24] = "Rate: "; append_enum(b, sizeof b, r, kRateLabels, kRateCount); -> "Rate: 1/4". Implemented via append_str. Freestanding: no libc, no double.
|
inline |
Append value as a fixed-point decimal with decimals fractional digits at the existing NUL of buf.
| buf | NUL-terminated buffer to extend in place. Non-null. |
| buf_size | Total capacity of buf in bytes. truncates to fit; buf stays NUL-terminated. |
| value | Integer carrying decimals fractional digits, the same fixed-point convention as a Numeric param's decimal_places. |
| decimals | Number of fractional digits. 0 appends a plain integer. |
Composes e.g. append_fixed(buf, size, 1250, 2) -> "12.50" and append_fixed(buf, size, -5, 2) -> "-0.05". Freestanding: no libc, no double, 32-bit division only.
|
inline |
Append the signed decimal of v at the existing NUL of buf.
| buf | NUL-terminated buffer to extend in place. Non-null. |
| buf_size | Total capacity in bytes. Appended text truncates to fit; buf stays NUL-terminated. |
| v | Value to append (INT32_MIN .. INT32_MAX); INT32_MIN-safe. |
| force_plus | When true, non-negative v appends a leading '+'. |
Freestanding: no libc, no double, 32-bit division only.
|
inline |
Append a bounded copy of s at the existing NUL of buf (freestanding strcat).
| buf | NUL-terminated buffer to extend in place (compose "Label: " + value without a libc strcat). Non-null. |
| buf_size | Total capacity of buf in bytes. The appended text truncates to fit the remaining space; buf stays NUL-terminated. |
| s | Source string to append (nullptr is treated as the empty string). |
Freestanding: no libc, no double.
|
inline |
Append the decimal digits of v at the existing NUL of buf.
| buf | NUL-terminated buffer to extend in place (compose "Label: " + number without a libc strcat). Non-null. |
| buf_size | Total capacity of buf in bytes. The appended digits truncate to fit the remaining space; buf stays NUL-terminated. |
| v | Value to append (0 .. 4294967295). |
Freestanding: no libc, no double, 32-bit division only.
|
inline |
Overwrite out with the signed decimal of v, NUL-terminated.
| v | Value to format (INT32_MIN .. INT32_MAX). INT32_MIN is handled correctly (magnitude taken via negation of an int64 temporary, then narrowed, no 64-bit divide). |
| out | Destination buffer, overwritten and NUL-terminated. Non-null, out_size >= 1. |
| out_size | Capacity in bytes. Result truncates to fit. Size for the widest output: 12 bytes holds "-2147483648" + NUL (or "+2147483647" with force_plus). |
| force_plus | When true, non-negative values get a leading '+' (+5 / -3). When false, non-negative values are bare (5 / -3). Negative values always get '-'. |
Freestanding: no libc, no double, 32-bit division only.
|
inline |
Overwrite out with a bounded copy of s (freestanding strlcpy).
| s | Source string (nullptr is treated as the empty string ""). |
| out | Destination buffer; out[0] is overwritten, NUL-terminated on return. Non-null with out_size >= 1. |
| out_size | Capacity of out in bytes. The copy truncates to fit (out_size - 1 characters max) and out is always NUL-terminated. |
Freestanding: no libc, no double. Use for the runtime-string overwrite primitive (filenames, resolved labels).
|
inline |
Overwrite out with the decimal digits of v, NUL-terminated.
| v | Value to format (0 .. 4294967295). |
| out | Destination buffer. out[0] is overwritten, NUL-terminated on return. Must be non-null with out_size >= 1. |
| out_size | Capacity of out in bytes. The result is truncated to fit (the least-significant digits are dropped if the buffer is too small), so size out for the widest value: 11 bytes holds any uint32 ("4294967295" + NUL). |
Freestanding: no libc, no double, 32-bit division only. v == 0 yields "0".
|
inline |
X-offset that horizontally centers a large-font string inside a box.
| s | Text to measure. |
| total_w | Width of the containing box in pixels. |
|
inline |
Pixel width of a string rendered in the large 8x12 font.
| s | NUL-terminated string (nullptr is treated as empty). |
|
inline |
Count the characters in a NUL-terminated string.
| s | NUL-terminated string (may be nullptr, in which case 0 is returned). |
|
inline |
Pixel width of a string rendered in the standard 5x7 font.
| s | NUL-terminated string (nullptr is treated as empty). |
|
inline |
Copy s into out, appending "..." when it exceeds max_chars.
| s | Source string (nullptr treated as empty). |
| max_chars | Maximum number of visible characters (including the ellipsis). Values below 4 behave like a plain truncate (no ellipsis). |
| out | Destination buffer; NUL-terminated on return. |
| out_size | Size of out in bytes (must be >= 1). |
|
inline |
Greedy word-wrap a NUL-terminated string into lines no wider than width_px pixels (standard font).
| s | Source string. |
| width_px | Maximum pixel width of a single line. |
| line_starts | Output array. Entry i points to the first character of line i inside the original buffer. |
| max_lines | Capacity of line_starts. |
Note: the input string is not modified, so callers treat line_starts[i] as the start of a line whose length extends until the next line's start or end-of-string (space trimmed on line breaks). For destructive wrapping use your own routine. This implementation keeps the helper allocation-free.
|
inlineconstexpr |
Horizontal advance (pixels) of the large-font space glyph.
Space renders narrower (6px advance), matching the device's large-font renderer.
|
inlineconstexpr |
Horizontal advance (pixels) of the standard-font space glyph.
Space renders narrower than other glyphs (4px advance), matching the device's standard-font renderer.