Theme
主题配色与样式管理。
include/XBase/Theme.h · XBase::Theme
Theme 模块通过 XBase 自有值类型管理配色与字体。ImGui 类型和字体指针只存在于 XBase 私有实现。
初始化与预设
void Init();
void Shutdown();
void ApplyPreset(Preset preset);
void ApplyStyle(const Style& style);
void ConfigureInteraction(bool keyboardNavigation, bool mouseEnabled);Init()— 应用 Dark 预设;Shutdown()释放字体缓存与 Context 绑定。Preset枚举:Dark、Light、ClassicBlue、Custom。ApplyPreset(Preset::Custom)会重新应用最近一次ApplyCustom()保存的ColorSet。ApplyStyle()接收完整的Style结构体(文本/背景/按钮/边框/圆角/内边距等),一次应用全部字段;ChildRounding、PopupRounding、ScrollbarRounding、GrabRounding复用frameRounding,不会更新Custom预设保存的ColorSet。ConfigureInteraction()控制键盘导航与鼠标输入:keyboardNavigation=false时关闭 ImGui 导航,mouseEnabled=false时屏蔽鼠标。
自定义配色
struct ColorSet {
ColorF primary; // 主色(勾选、滑块)
ColorF accent; // 强调色(按钮激活)
ColorF background; // 窗口背景
ColorF surface; // 控件背景
ColorF text; // 文字
ColorF textDisabled; // 禁用文字
ColorF border; // 边框
ColorF highlight; // 高亮
};
void ApplyCustom(const ColorSet& colors);
ColorSet GetColors();字体
FontId LoadFont(const char* path, float size);
bool SetDefaultFont(FontId font);LoadFont— 从 TTF 文件加载字体;成功返回不透明FontId,失败返回无效 IDSetDefaultFont— 按 ID 选择默认字体;XBase 在内部验证 ID,不向宿主暴露ImFont*
预设持久化
void SavePreset(const std::string& name);
bool LoadPreset(const std::string& name);SavePreset— 将当前ColorSet保存到Config系统,调用Config::Save()持久化到磁盘LoadPreset— 从Config加载指定名称的主题并应用;如不存在返回false
保存的键格式为 theme.<name>.*,例如 theme.myBlue.primary.r。