#include "ExampleHost.hpp"
#include <memory>
#include <string>
using namespace ZenitUI;
static constexpr const char *kStyle = R"zs(
:root {
font: inter, arabic, hebrew, cjk-jp, cjk-sc, cjk-kr;
font-size: 15px;
letter-spacing: 0px;
color: #E5E7EB;
}
.page {
width: 100%;
height: 100%;
background: #0D1017;
padding: 24px;
overflow-x: hidden;
overflow-y: auto;
}
.shell {
width: 100%;
max-width: 860px;
margin: auto;
gap: 16px;
}
.workspace {
width: 100%;
gap: 16px;
dir: ltr;
}
.workspace.rtl {
dir: rtl;
}
.title {
font: inter-bold, arabic-bold, hebrew-bold, cjk-jp, cjk-sc, cjk-kr;
font-size: 24px;
color: #F8FAFC;
}
.section-title {
font: inter-semibold, arabic-bold, hebrew-bold, cjk-jp, cjk-sc, cjk-kr;
font-size: 15px;
color: #F1F5F9;
}
.muted {
font-size: 13px;
color: #94A3B8;
}
.card {
width: 100%;
background: #151924;
border-width: 1px;
border-color: #262E42;
radius: 12px;
padding: 18px;
gap: 12px;
}
.toolbar {
width: 100%;
gap: 10px;
wrap: true;
align-items: center;
}
Button.lang-btn {
padding: 8px 14px;
radius: 8px;
background: #1F2638;
border-width: 1px;
border-color: #334155;
color: #CBD5E1;
cursor: pointer;
transition-time: 0.12;
}
Button.lang-btn:hover {
border-color: #38BDF8;
color: #FFFFFF;
}
Button.lang-btn.active {
background: #2563EB;
border-color: #3B82F6;
color: #FFFFFF;
}
.badge {
padding: 4px 10px;
radius: 999px;
background: #1E293B;
border-width: 1px;
border-color: #334155;
color: #7DD3FC;
font-size: 12px;
}
.step-row {
width: 100%;
gap: 10px;
wrap: true;
align-items: center;
}
.step-pill {
padding: 8px 14px;
radius: 8px;
background: #111624;
border-width: 1px;
border-color: #2A344D;
color: #E2E8F0;
font-size: 13px;
}
.align-box {
width: 100%;
padding: 12px 14px;
radius: 8px;
background: #10141F;
border-width: 1px;
border-color: #252D40;
gap: 8px;
}
.sample-start {
width: 100%;
text-align: start;
color: #F8FAFC;
}
.sample-end {
width: 100%;
text-align: end;
color: #7DD3FC;
}
TextInput, TextArea {
width: 100%;
background: #10141F;
border-width: 1px;
border-color: #2B3347;
radius: 8px;
padding: 10px 12px;
color: #F8FAFC;
}
TextInput:focus, TextArea:focus {
border-color: #38BDF8;
}
.info-bar {
width: 100%;
padding: 10px 14px;
radius: 8px;
background: #10141F;
border-left: 3px;
border-color: #38BDF8;
color: #CBD5E1;
font-size: 13px;
}
)zs";
static constexpr const char *kMarkup = R"zm(
ScrollView.page {
VStack.shell {
VStack.card {
HStack width="100%" justify="space-between" align-items="center" wrap="true" gap="8px" {
Text.section-title "Locale & Direction Switcher"
HStack gap="8px" wrap="true" align-items="center" {
Text.badge@backendBadge ""
Text.badge@cjkBadge ""
}
}
HStack.toolbar {
Button.lang-btn.active@btnEn "English (LTR)"
Button.lang-btn@btnAr "العربية (RTL)"
Button.lang-btn@btnHe "עברית (RTL)"
Button.lang-btn@btnCjk "日本語 / 中文 (CJK)"
}
}
VStack.workspace@workspace {
VStack.card {
Text.title@headline wrap="true" ""
Text.muted@subtitle wrap="true" ""
HStack.step-row {
Text.step-pill@step1 ""
Text.step-pill@step2 ""
Text.step-pill@step3 ""
}
}
VStack.card {
Text.section-title@bidiTitle wrap="true" ""
VStack.align-box {
Text.sample-start@bidiStart wrap="true" ""
Text.sample-end@bidiEnd wrap="true" ""
}
}
VStack.card {
Text.section-title@inputTitle wrap="true" ""
Text.muted@inputHint wrap="true" ""
TextInput@singleInput placeholder=""
TextArea@multiInput rows="3" placeholder=""
}
}
Text.info-bar@imeNote wrap="true" ""
}
}
)zm";
namespace
{
struct LocaleStrings
{
bool rtl{false};
const char *headline;
const char *subtitle;
const char *step1;
const char *step2;
const char *step3;
const char *bidiTitle;
const char *bidiStart;
const char *bidiEnd;
const char *inputTitle;
const char *inputHint;
const char *singleDefault;
const char *multiDefault;
};
constexpr LocaleStrings kEn = {
false,
"Internationalization, RTL & Unicode Bidi",
"Inherited dir: ltr keeps flow left-to-right; switch to Arabic or Hebrew to mirror the entire subtree.",
"1. Profile",
"2. Layout",
"3. Publish",
"Mixed Bidi Runs (SheenBidi UAX #9 + HarfBuzz)",
"text-align: start — Mixed script: Hello مرحبا שלום from ZenitUI 1.0!",
"text-align: end — Anchored to the logical trailing edge.",
"Bidi & IME Text Input",
"Click inside, drag-select across mixed scripts, or use your OS IME (CJK / Arabic / Hebrew).",
"ZenitUI 1.0 — مرحبا / שלום",
"Line 1: Left-to-right with Arabic (العربية) and Hebrew (עברית).\nLine 2: Switch to an OS IME to test pre-edit composition."};
constexpr LocaleStrings kAr = {
true,
"التدويل والتخطيط من اليمين إلى اليسار (RTL)",
"تنتقل خاصية dir: rtl بالوراثة فتعكس اتجاه HStack و VStack ومحاذاة النصوص تلقائياً.",
"١. الإعدادات",
"٢. التخطيط",
"٣. النشر",
"نصوص ثنائية الاتجاه (SheenBidi + HarfBuzz)",
"محاذاة البداية (start): مرحباً بك في إطار ZenitUI 1.0 بدقة 1280x720 بكسل.",
"محاذاة النهاية (end): هذا السطر محاذٍ للحافة المنطقية النهائية.",
"إدخال النصوص العربية وثنائية الاتجاه (IME)",
"جرّب التحديد بالماوس أو الأسهم عبر النص المختلط لتجربة التحديد المقسّم وموضع المؤشر.",
"مرحباً بالعالم — ZenitUI 1.0",
"السطر الأول: نص عربي مع مصطلحات إنجليزية مثل Layout و VirtualList.\nالسطر الثاني: يدعم المحرر الحافظة والتراجع والكتابة عبر IME."};
constexpr LocaleStrings kHe = {
true,
"בינאום, פריסת RTL וטקסט דו-כיווני (Bidi)",
"התכונה dir: rtl עוברת בירושה והופכת את כיוון HStack, VStack ויישור הטקסט באופן אוטומטי.",
"1. פרופיל",
"2. פריסה",
"3. פרסום",
"טקסט מעורב עברית ואנגלית (SheenBidi UAX #9)",
"יישור התחלה (start): שלום עולם מ-ZenitUI 1.0 עם תמיכה מלאה ב-UTF-8.",
"יישור סיום (end): שורה זו מיושרת לקצה הלוגי המסיים.",
"קלט טקסט RTL ותמיכת IME",
"נסה לסמן טקסט מעורב עם העכבר או עם Shift+חצים כדי לבדוק מלבני בחירה מפוצלים.",
"שלום מ-ZenitUI 1.0",
"שורה 1: טקסט בעברית משולב עם מילות מפתח כמו Flex ו-ScrollView.\nשורה 2: נסה להקליד או להדביק טקסט דו-כיווני."};
constexpr LocaleStrings kCjk = {
false,
"国際化・多言語テキストと IME (日本語 / 中文 / 한국어)",
"Font fallback chain (inter -> arabic -> hebrew -> cjk) renders CJK glyphs using the host OS font without bloating the repository.",
"1. フォント選択",
"2. 布局与换行",
"3. 한글 지원",
"Multi-Script CJK + Latin + RTL Fallback",
"start — 日本語: こんにちは ZenitUI 1.0 | 中文: 你好世界 | 한국어: 안녕하세요 | العربية: مرحبا",
"end — 論理終端に配置されたテキスト (Logical trailing edge).",
"IME Composition Playground (CJK / Kana / Pinyin / Hangul)",
"Focus the fields below and switch to a Japanese, Chinese, or Korean IME (SDL3 backend tracks the OS candidate window).",
"日本語入力テスト — ZenitUI 1.0",
"1行目: 日本語のひらがな・カタカナ・漢字と English の混在テスト。\n2行目: 中文简体测试与 한국어 텍스트 입력 (IME プレエディット対応)。"};
}
int main()
{
cfg.
title =
"ZenitUI 13 — i18n, RTL & Bidi";
return ZenitExample::runApp(cfg, [](
UIContext &ctx,
IBackend &backend) -> std::shared_ptr<Layout>
{
const bool hasCjk = ZenitExample::loadI18nFonts(ctx);
auto ui = ZMarkup::build(kMarkup, ctx);
ui.setTextRef(
"backendBadge", std::string(
"Backend: ") + std::string(backend.
name()));
ui.setTextRef("cjkBadge", hasCjk ? "System CJK Font: Loaded" : "System CJK Font: Not Found");
ui.setTextRef("imeNote",
"Font fallback stack: inter -> arabic -> hebrew -> cjk. "
"Full OS IME candidate-window tracking (SDL_EVENT_TEXT_EDITING + SDL_SetTextInputArea) "
"is active when running with BACKEND=sdl3.");
auto applyLocale = [uiWeak](int idx, const LocaleStrings &loc) {
auto locked = uiWeak.
lock();
if (!locked)
return;
locked->toggleClassRef("btnEn", "active", idx == 0);
locked->toggleClassRef("btnAr", "active", idx == 1);
locked->toggleClassRef("btnHe", "active", idx == 2);
locked->toggleClassRef("btnCjk", "active", idx == 3);
locked->toggleClassRef("workspace", "rtl", loc.rtl);
locked->setTextRef("headline", loc.headline);
locked->setTextRef("subtitle", loc.subtitle);
locked->setTextRef("step1", loc.step1);
locked->setTextRef("step2", loc.step2);
locked->setTextRef("step3", loc.step3);
locked->setTextRef("bidiTitle", loc.bidiTitle);
locked->setTextRef("bidiStart", loc.bidiStart);
locked->setTextRef("bidiEnd", loc.bidiEnd);
locked->setTextRef("inputTitle", loc.inputTitle);
locked->setTextRef("inputHint", loc.inputHint);
locked->setTextRef("singleInput", loc.singleDefault);
locked->setTextRef("multiInput", loc.multiDefault);
};
ui.onClickRef("btnEn", [applyLocale]() { applyLocale(0, kEn); });
ui.onClickRef("btnAr", [applyLocale]() { applyLocale(1, kAr); });
ui.onClickRef("btnHe", [applyLocale]() { applyLocale(2, kHe); });
ui.onClickRef("btnCjk", [applyLocale]() { applyLocale(3, kCjk); });
applyLocale(0, kEn);
return ui.root(); });
}
Unified window, frame-loop, and subsystem host for interchangeable backends.
Definition Backend.hpp:49
virtual std::string_view name() const =0
Short human-readable backend identifier (e.g.
Non-owning handle to a UINode, safe to capture inside child callbacks.
Definition ZMarkup.hpp:757
bool loadStyleString(std::string_view src, Theme &theme, const std::string &fileName="<string>", DiagnosticSink *sink=nullptr, bool strict=false, const Registry *registry=nullptr)
Parse src and apply it to theme.
Per-instance UI context: backends, theme, text engine, frame state, and routing.
Definition UIContext.hpp:725
Theme theme
Per-context stylesheet (rules, keyframes, and :root style).
Definition UIContext.hpp:911
Backend-agnostic window and graphics-context creation parameters.
Definition Backend.hpp:31