Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:78 Xiaozhi esp32 Display UI Framework

From Leeroopedia
Knowledge Sources
Domains Display, UI_Framework, Embedded_Systems
Last Updated 2026-10-17 00:00 GMT

Overview

Principle of abstracting display hardware behind a polymorphic Display interface with a reusable LVGL-based rendering layer that supports multiple panel types (SPI LCD, RGB LCD, MIPI, OLED, E-Paper) and a non-LVGL animation-based path, unified by a theme system with dynamic server-pushed glyph rendering.

Description

XiaoZhi's display framework solves the problem of supporting diverse display hardware (color LCD, monochrome OLED, E-Paper, addressable emote displays) while maintaining a consistent UI contract (emotion, chat message, status, notification, preview image).

The architecture uses polymorphic inheritance from the abstract Display interface:

  • LvglDisplay is the base for all LVGL-driven displays (LCD, OLED, E-Paper)
  • LcdDisplay provides the full color UI (top bar, status bar, content, chat, emoji, preview)
  • OledDisplay provides a compact monochrome UI
  • EpdDisplay adds E-Paper waveform management
  • EmoteDisplay bypasses LVGL entirely for animation-based displays

A theme system (LvglTheme, LvglThemeManager) decouples visual appearance from layout: colors, fonts, background images, and emoji collections are registered as named themes.

A dynamic glyph cache enables server-pushed font rendering: the server sends glyph bitmap data for characters not in the device's font, and DynamicGlyphCache builds a runtime lv_font_t with LRU eviction (256 glyphs max, 64KB bitmap budget).

Usage

Use this principle when:

  • Designing display support for a new panel type
  • Understanding the display class hierarchy
  • Implementing server-pushed text rendering with dynamic glyph fonts
  • Customizing themes for different device aesthetics

Theoretical Basis

The framework follows three key design patterns:

  • Strategy Pattern: Display interface defines the contract; concrete subclasses implement rendering for specific hardware.
  • Template Method: LvglDisplay provides the common LVGL setup, status bar, notification, and glyph cache; subclasses override SetupUI() for board-specific layouts.
  • Decorator Pattern: LcdDisplay adds UI elements (chat, emoji, preview) on top of LvglDisplay's base infrastructure.

The dynamic glyph cache uses a bounded LRU eviction policy:

Failed to parse (syntax error): {\displaystyle \text{evict} \iff |\text{entries}| > 256 \lor |\text{bitmap\_blob}| > 64\text{KB} }

Glyphs are stored in a contiguous bitmap blob with per-glyph descriptors (lv_font_fmt_txt_glyph_dsc_t) and a Unicode list for cmap mapping, rebuilt atomically when glyphs are added or evicted.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment