ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
Backends, TextEngine, UTF-8 & Debugging

Pluggable backend implementations, FreeType/HarfBuzz/SheenBidi TextEngine, Unicode utilities (Utf8), logging, and debug dumps. More...

Classes

struct  ZenitUI::WindowConfig
 Backend-agnostic window and graphics-context creation parameters. More...
class  ZenitUI::IBackend
 Unified window, frame-loop, and subsystem host for interchangeable backends. More...
struct  ZenitUI::Geometry2D::StaticMesh< MaxVertices, MaxIndices >
 Fixed-capacity stack mesh returned by Geometry2D builders. More...
struct  ZenitUI::Geometry2D::RoundedBorderRing
 Outer and inner vertex loops of a CSS border-box rounded stroke. More...
class  ZenitUI::InputAccumulator
 Buffers asynchronous OS mouse/keyboard/text events and drains them once per frame into PointerState and InputEvents. More...
struct  ZenitUI::LogMessage
 A single log record passed to ILogger::log. More...
class  ZenitUI::ILogger
 Abstract sink for LogMessage records. More...
class  ZenitUI::ConsoleLogger
 Default ILogger that prints to stderr. More...
class  ZenitUI::Logger
 Global registry for the active logger. More...
class  ZenitUI::CodepointSet
 Composable set of Unicode codepoints for static font-atlas baking. More...
class  ZenitUI::Test::MockAssetProvider
 In-memory IAssetProvider that mints synthetic texture and shader handles without touching the filesystem or GPU. More...
struct  ZenitUI::Test::Env
 Scoped test fixture that binds MockRenderer, MockPlatform, and MockAssetProvider into UIContext and restores clean state on destruction. More...
class  ZenitUI::Test::MockBackend
 Headless IBackend host wrapping MockPlatform, MockRenderer, and MockAssetProvider. More...
class  ZenitUI::Test::MockPlatform
 Programmable IPlatform for injecting deterministic pointer, keyboard, IME, viewport, and clipboard state in tests. More...
class  ZenitUI::Test::MockRenderer
 Recording IRenderer that tracks draw counts, clip stacks, render targets, dynamic textures, and shader uniforms without a GPU. More...
class  ZenitUI::RaylibAssetProvider
 Reference IAssetProvider for loading and caching Raylib textures and shaders through IRenderer. More...
class  ZenitUI::RaylibBackend
 Unified IBackend host wrapping Raylib windowing, rendering, and assets. More...
class  ZenitUI::RaylibPlatform
 Reference IPlatform backed by Raylib window, input, and clipboard APIs. More...
class  ZenitUI::RaylibRenderer
 Reference IRenderer backed by Raylib / rlgl. More...
class  ZenitUI::SDL3AssetProvider
 Reference IAssetProvider loading textures (stb_image) and GLSL 330 shaders through IRenderer. More...
class  ZenitUI::SDL3Backend
 Unified IBackend host managing an SDL3 window, OpenGL 3.3 Core context, and SDL3Platform / SDL3Renderer / SDL3AssetProvider. More...
class  ZenitUI::SDL3Platform
 Reference IPlatform backed by SDL3 window, input, IME, and clipboard APIs. More...
class  ZenitUI::SDL3Renderer
 Reference IRenderer backed by a batched OpenGL 3.3 Core 2D pipeline. More...

Typedefs

using ZenitUI::Geometry2D::QuadMesh = StaticMesh<4, 6>
using ZenitUI::Geometry2D::RectStrokeMesh = StaticMesh<8, 24>
using ZenitUI::Geometry2D::BorderMesh = StaticMesh<16, 24>
using ZenitUI::Geometry2D::NineSliceMesh = StaticMesh<16, 54>
using ZenitUI::Geometry2D::CircleMesh = StaticMesh<kCircleMaxSegments + 1, kCircleMaxSegments * 3>
using ZenitUI::Geometry2D::RoundedFillMesh = StaticMesh<kRoundedRingPoints + 1, kRoundedRingPoints * 3>
using ZenitUI::Geometry2D::RoundedStrokeMesh = StaticMesh<kRoundedRingPoints * 2, kRoundedRingPoints * 6>

Enumerations

enum class  ZenitUI::LogLevel { Debug , Info , Warning , Error }
 Severity level attached to a LogMessage.

Functions

RoundedBorderRing ZenitUI::Geometry2D::buildRoundedBorderRing (Rect r, float radiusPx, float thickness)
 Build the inward-extruded rounded ring for IRenderer::strokeRoundedRect.
QuadMesh ZenitUI::Geometry2D::buildQuad (Rect r, Color c)
 Build a solid-color axis-aligned quad.
QuadMesh ZenitUI::Geometry2D::buildTexturedQuad (TextureHandle t, Rect src, Rect dst, Color tint)
 Build a textured quad mapping pixel sub-rect src onto logical dst.
NineSliceMesh ZenitUI::Geometry2D::buildNineSlice (TextureHandle t, NineSlice s, Rect dst, Color tint)
 Build a 9-slice mesh (up to 9 quads, single indexed draw call).
RectStrokeMesh ZenitUI::Geometry2D::buildRectStroke (Rect r, float thickness, Color c)
 Build a CSS border-box rectangular stroke strictly inside r without corner overdraw.
BorderMesh ZenitUI::Geometry2D::buildBorder (Rect r, EdgeInsets sides, Color c)
 Build per-edge rectangular borders in a single indexed draw call.
RoundedFillMesh ZenitUI::Geometry2D::buildRoundedRectFill (Rect r, float radiusPx, Color c)
 Build a filled rounded rectangle (fast-paths to a 4-vertex quad when radiusPx <= 0.01).
RoundedStrokeMesh ZenitUI::Geometry2D::buildRoundedRectStroke (Rect r, float radiusPx, float thickness, Color c)
 Build a CSS border-box rounded stroke mesh strictly inside r.
CircleMesh ZenitUI::Geometry2D::buildCircle (Vec2 center, float radius, Color c)
 Build a filled circle with adaptive segment count (16..kCircleMaxSegments).
void ZenitUI::logImpl (LogLevel level, const std::string &cat, const std::string &file, int line, int col, const std::string &text)
 Internal dispatch: build a LogMessage and forward it to the active logger.
void ZenitUI::logDebug (const std::string &c, const std::string &f, int l, int col, const std::string &t)
void ZenitUI::logInfo (const std::string &c, const std::string &f, int l, int col, const std::string &t)
void ZenitUI::logWarn (const std::string &c, const std::string &f, int l, int col, const std::string &t)
void ZenitUI::logError (const std::string &c, const std::string &f, int l, int col, const std::string &t)
constexpr bool ZenitUI::Utf8::isContinuation (unsigned char b) noexcept
 true if b is a UTF-8 continuation byte (10xxxxxx).
constexpr bool ZenitUI::Utf8::isValidCodepoint (uint32_t cp) noexcept
 true if cp is a valid Unicode scalar value (excludes UTF-16 surrogates).
constexpr size_t ZenitUI::Utf8::seqLenFromLead (unsigned char b) noexcept
 Expected UTF-8 byte length from a leading byte (1..4).
size_t ZenitUI::Utf8::encode (uint32_t cp, std::string &out)
 Append the UTF-8 encoding of cp to out.
std::string ZenitUI::Utf8::encode (uint32_t cp)
 Encode cp into a new UTF-8 std::string (empty if invalid).
size_t ZenitUI::Utf8::decode (std::string_view s, size_t pos, uint32_t &outCp) noexcept
 Decode one UTF-8 codepoint starting at byte offset pos.
uint32_t ZenitUI::Utf8::next (std::string_view s, size_t &pos) noexcept
 Decode one UTF-8 codepoint at pos and advance pos past it.
size_t ZenitUI::Utf8::snapFloor (std::string_view s, size_t pos) noexcept
 Clamp pos to s.size() and snap down to the nearest codepoint boundary.
size_t ZenitUI::Utf8::snapCeil (std::string_view s, size_t pos) noexcept
 Clamp pos to s.size() and snap up to the nearest codepoint boundary.
size_t ZenitUI::Utf8::nextCodepoint (std::string_view s, size_t pos) noexcept
 Advance pos by one UTF-8 codepoint.
size_t ZenitUI::Utf8::prevCodepoint (std::string_view s, size_t pos) noexcept
 Move pos back by one UTF-8 codepoint.
size_t ZenitUI::Utf8::codepointCount (std::string_view s) noexcept
 Count the number of UTF-8 codepoints in s.
constexpr bool ZenitUI::Utf8::isClusterExtend (uint32_t cp) noexcept
 true if cp extends the preceding grapheme cluster.
constexpr bool ZenitUI::Utf8::isRegionalIndicator (uint32_t cp) noexcept
 true if cp is a Regional Indicator symbol (U+1F1E6..U+1F1FF).
size_t ZenitUI::Utf8::nextCluster (std::string_view s, size_t pos) noexcept
 Advance pos by one grapheme cluster.
size_t ZenitUI::Utf8::prevCluster (std::string_view s, size_t pos) noexcept
 Move pos back by one grapheme cluster.
std::vector< size_t > ZenitUI::Utf8::clusterBoundaries (std::string_view s)
 Return all grapheme-cluster byte boundaries in s, starting at 0 and ending at s.size().
constexpr bool ZenitUI::Utf8::isPrintable (uint32_t cp) noexcept
 true if cp is a printable Unicode scalar value accepted by text inputs.
constexpr bool ZenitUI::Utf8::isWordChar (uint32_t cp) noexcept
 true if cp belongs to a word (for double-click selection and Ctrl+Arrow).
size_t ZenitUI::Utf8::prevWordBoundary (std::string_view s, size_t pos) noexcept
 Move backward to the start of the previous word (Ctrl+Left / Ctrl+Backspace).
size_t ZenitUI::Utf8::nextWordBoundary (std::string_view s, size_t pos) noexcept
 Move forward past the current/next word (Ctrl+Right / Ctrl+Delete).
std::string ZenitUI::Utf8::sanitizeSingleLine (std::string_view src)
 Sanitize a pasted string for single-line text fields.
std::string ZenitUI::Utf8::sanitizeMultiLine (std::string_view src)
 Sanitize a pasted string for multi-line text fields.

Variables

constexpr int ZenitUI::Geometry2D::kRoundedCornerSegments = 12
constexpr int ZenitUI::Geometry2D::kRoundedRingPoints = 4 * (kRoundedCornerSegments + 1)
constexpr int ZenitUI::Geometry2D::kCircleMaxSegments = 48

Detailed Description

Pluggable backend implementations, FreeType/HarfBuzz/SheenBidi TextEngine, Unicode utilities (Utf8), logging, and debug dumps.

The core library depends solely on IPlatform, IRenderer, and IAssetProvider (optionally wrapped by IBackend for multi-backend apps and auto-discovered in CMake via zenitui_register_backend()). Browse Available Backends for all built-in implementations, or follow Writing a Custom Backend to port ZenitUI to your own engine.

Fonts, textures, and shaders are loaded per context through the unified UIContext asset facade (ctx.loadFont, ctx.loadTexture, ctx.loadEffectAsset). TextEngine combines HarfBuzz OpenType shaping, SheenBidi UAX #9 Bidi reordering, and a FreeType on-demand HiDPI glyph atlas, while ZenitUI::Debug (ZENITUI_DEBUG) inspects live layout trees, styles, and render stats.

Live examples: 01_hello_markup · 12_effects_canvas · 13_i18n_rtl · 00_demo

Live examples
  • 00_demo — Flagship ZenitUI showcase: live Dark/Light theming, ZMarkup prefabs & keyed Each, Bindable<T>, UTF-8 TextArea, 10k-row VirtualView, portals, filters, and CanvasLayout.
Available Backends
Backend CMake Target Role Optional Features Classes
Mock (Headless) (mock) ZenitUI::MockBackend Deterministic headless backend & test fixture (no GPU/window) Configurable (Effects, NestedTargets, TargetSubRect) ZenitUI::Test::MockBackend, ZenitUI::Test::MockPlatform, ZenitUI::Test::MockRenderer, ZenitUI::Test::MockAssetProvider, ZenitUI::Test::Env
Raylib (raylib) ZenitUI::RaylibBackend Reference desktop GPU backend (Raylib / rlgl) Effects, NestedTargets, TargetSubRect ZenitUI::RaylibBackend, ZenitUI::RaylibPlatform, ZenitUI::RaylibRenderer, ZenitUI::RaylibAssetProvider
SDL3 + OpenGL 3.3 (sdl3) ZenitUI::SDL3Backend Desktop GPU backend with HiDPI (SDL3 + batched GL 3.3 Core) Effects, NestedTargets, TargetSubRect ZenitUI::SDL3Backend, ZenitUI::SDL3Platform, ZenitUI::SDL3Renderer, ZenitUI::SDL3AssetProvider

Function Documentation

◆ clusterBoundaries()

std::vector< size_t > ZenitUI::Utf8::clusterBoundaries ( std::string_view s)
inline

Return all grapheme-cluster byte boundaries in s, starting at 0 and ending at s.size().

Ideal for binary searching prefix lengths (wrapping, ellipsis, hit-testing) without ever splitting a UTF-8 codepoint or grapheme cluster.

◆ decode()

size_t ZenitUI::Utf8::decode ( std::string_view s,
size_t pos,
uint32_t & outCp )
inlinenoexcept

Decode one UTF-8 codepoint starting at byte offset pos.

On malformed bytes, writes U+FFFD (replacement character) and advances by 1 byte so iteration is always safe and terminates.

Parameters
sUTF-8 string view.
posStarting byte offset.
outCpReceives the decoded Unicode scalar value.
Returns
Byte offset immediately after the decoded sequence.

◆ encode()

size_t ZenitUI::Utf8::encode ( uint32_t cp,
std::string & out )
inline

Append the UTF-8 encoding of cp to out.

Returns
Number of bytes written (1..4), or 0 if cp is invalid.

◆ isClusterExtend()

bool ZenitUI::Utf8::isClusterExtend ( uint32_t cp)
inlineconstexprnoexcept

true if cp extends the preceding grapheme cluster.

Covers combining diacritical marks, variation selectors, and emoji skin-tone modifiers.

◆ isPrintable()

bool ZenitUI::Utf8::isPrintable ( uint32_t cp)
inlineconstexprnoexcept

true if cp is a printable Unicode scalar value accepted by text inputs.

Rejects C0 controls (< 0x20), DEL (0x7F), C1 controls (0x80..0x9F), surrogates, and out-of-range values.

◆ isWordChar()

bool ZenitUI::Utf8::isWordChar ( uint32_t cp)
inlineconstexprnoexcept

true if cp belongs to a word (for double-click selection and Ctrl+Arrow).

Covers ASCII alphanumerics + _, accented Latin-1 / Latin Extended letters, combining marks, Greek, Cyrillic, and CJK / Hangul blocks.

◆ next()

uint32_t ZenitUI::Utf8::next ( std::string_view s,
size_t & pos )
inlinenoexcept

Decode one UTF-8 codepoint at pos and advance pos past it.

Returns
Decoded Unicode scalar value (0 at end-of-string, U+FFFD on malformed bytes).

◆ nextCluster()

size_t ZenitUI::Utf8::nextCluster ( std::string_view s,
size_t pos )
inlinenoexcept

Advance pos by one grapheme cluster.

Keeps \r\n, base + combining marks / variation selectors / skin-tone modifiers, Regional Indicator flag pairs, and ZWJ (U+200D) emoji sequences intact as single cursor steps.

◆ prevCluster()

size_t ZenitUI::Utf8::prevCluster ( std::string_view s,
size_t pos )
inlinenoexcept

Move pos back by one grapheme cluster.

Mirror of nextCluster: never lands inside a multi-byte UTF-8 sequence, combining mark sequence, ZWJ emoji sequence, Regional Indicator pair, or \r\n.

◆ sanitizeMultiLine()

std::string ZenitUI::Utf8::sanitizeMultiLine ( std::string_view src)
inline

Sanitize a pasted string for multi-line text fields.

Normalizes \r\n and \r to \n, preserves all valid printable UTF-8 codepoints, and drops other control characters and malformed bytes.

◆ sanitizeSingleLine()

std::string ZenitUI::Utf8::sanitizeSingleLine ( std::string_view src)
inline

Sanitize a pasted string for single-line text fields.

Keeps all valid printable UTF-8 codepoints and drops control characters (including \r, \n, \t) and malformed byte sequences.

◆ seqLenFromLead()

size_t ZenitUI::Utf8::seqLenFromLead ( unsigned char b)
inlineconstexprnoexcept

Expected UTF-8 byte length from a leading byte (1..4).

Invalid leading bytes return 1 so callers always make forward progress.