feat(sdk): 控件库第一批通用基座(agent-150) + launcher/hello 重链

- meow_widget 基座收敛(尾部追加 Options+状态机位+自定义回调+布局子项), W_CUSTOM/W_LAYOUT/W_SPACER
- meow_theme 尾部追加 MD3 语义色+风格参数(旧字段 bg/fg/accent/dim 映射兼容), g_theme[2][2](style×mode×明暗), display.background 背景源深浅成对, 图片路径回退
- meow_widget_opts(Modifier式, 不改create签名)/MEOW_WS_*状态机(enabled阻断hit,pressed)/meow_widget_custom_create(render/hit_cb)/meow_row/column/box+arrange(算绝对坐标兼容)
- meow_ui_set_style/style/meow_theme_get 完整主题(MD3默认/MIUIx占位)
- meow_ui.a=29c5078d hello=24116e6b(向后兼容外观零变化) launcher重链=626546f9;build_sdk 0warning; 宿主 test_sdk_controls T1-T10 PASS + test_sb_statusbar ALL PASS
- 未做(第二批/后续): Material子集/实时按压刷新扩展/物理键焦点移动运行时(留草案)
This commit is contained in:
MeowOS committed 2026-08-30 21:57:46 +08:00
1 parent e6f0b665e3
commit 2cb6a7c16f
5 files changed
+527 -49

No files matched your search

+121 -14
View File
@@ -14,17 +14,17 @@
#include "meow_ui_internal.h" /* meow_theme_reload() 定义(供 launcher 逼重读 settings) */
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <time.h>
#define MEOW_SETTINGS_FILE "/usr/data/meow/settings.conf"
static meow_theme g_light = {
0xE8EAF0, 0x1A1A2A, 0x2A5A8A, 0x4A4F5A, 28, 20
};
static meow_theme g_dark = {
0x141824, 0xFFFFFF, 0x4A6A9A, 0x9AA4C8, 28, 20
};
/* ---- 主题表(§5.8.4 + §8.1.3):[style][dark] ———
* 0=MEOW_STYLE_MD3, 1=MEOW_STYLE_MIUIX;dark 0=light, 1=dark。
* 旧字段 bg/fg/accent/dim = surface/onSurface/primary/onSurfaceVariant(映射见 meow_ui.h)。
* bg/surface 随后由「背景全局源」(display.background,§8.1.4)按 style×mode 覆写。 */
static meow_theme g_theme[2][2];
static meow_theme_mode g_mode = MEOW_THEME_DARK; /* 配置生效的判定模式(默认深色,与 launcher 默认一致) */
static meow_theme_mode g_manual = MEOW_THEME_DARK; /* display.theme 解析出的手动深浅;auto 未配置时段时回退用之 */
@@ -32,6 +32,7 @@ static int g_dark_start = 0; /* 深色时段开始(分
static int g_dark_end = 0; /* 深色时段结束(分钟 0-1439) */
static int g_loaded = 0;
static int g_style = MEOW_STYLE_MD3; /* 顶级主题风格族(§8.1.2):默认 MD3 */
static char g_background[64] = ""; /* display.background(black/blue/green/white/… 或图片路径) */
static meow_theme_listener g_listeners[8];
static int g_nlisteners = 0;
@@ -85,6 +86,95 @@ static meow_theme_mode parse_manual(const char *v)
return MEOW_THEME_DARK; /* "dark" / 未知 → 深色 */
}
/* ---- 填充 4 张主题表的内建色板(草案值,MD3 默认;MIUIx 用 MD3 基础做占位)----
* bg/surface 本函数填默认面;随后 apply_background() 按 display.background 覆写。 */
static void init_defaults(void)
{
meow_theme *t;
/* MD3 light */
t = &g_theme[MEOW_STYLE_MD3][0];
t->bg = 0xE8EAF0; t->fg = 0x1A1A2A; t->accent = 0x2A5A8A; t->dim = 0x4A4F5A;
t->font_title = 28; t->font_body = 20;
t->primary = 0x2A5A8A; t->onPrimary = 0xFFFFFF; t->primaryContainer = 0xC9E2F5; t->onPrimaryContainer = 0x0A2B46;
t->secondary = 0x53626E; t->onSecondary = 0xFFFFFF; t->secondaryContainer = 0xD6E5F2; t->onSecondaryContainer = 0x101E28;
t->tertiary = 0x635B78; t->onTertiary = 0xFFFFFF; t->tertiaryContainer = 0xE9DEFB; t->onTertiaryContainer = 0x1E1734;
t->surface = 0xE8EAF0; t->onSurface = 0x1A1A2A; t->surfaceVariant = 0xDDE1EA; t->onSurfaceVariant = 0x4A4F5A;
t->surfaceContainerLowest = 0xFFFFFF; t->surfaceContainerLow = 0xF2F3F7; t->surfaceContainer = 0xECEEF3;
t->surfaceContainerHigh = 0xE6E8EE; t->surfaceContainerHighest = 0xE1E3E9;
t->surfaceDim = 0xD8DAE0; t->surfaceBright = 0xFFFFFF; t->surfaceTint = 0x2A5A8A;
t->outline = 0x74777F; t->outlineVariant = 0xC4C6D0; t->scrim = 0x000000;
t->error = 0xBA1A1A; t->onError = 0xFFFFFF; t->errorContainer = 0xFFDAD6; t->onErrorContainer = 0x410002;
t->inverseSurface = 0x2F3036; t->inverseOnSurface = 0xF0F0F5; t->inversePrimary = 0xA6C8EE;
t->shadow = 0x000000;
t->radius = 12; t->radius_card = 16; t->spacing = 8; t->stroke_w = 0;
/* MD3 dark */
t = &g_theme[MEOW_STYLE_MD3][1];
t->bg = 0x141824; t->fg = 0xFFFFFF; t->accent = 0x4A6A9A; t->dim = 0x9AA4C8;
t->font_title = 28; t->font_body = 20;
t->primary = 0x4A6A9A; t->onPrimary = 0xFFFFFF; t->primaryContainer = 0x2A3A5C; t->onPrimaryContainer = 0xD5E4F5;
t->secondary = 0xB8C6D2; t->onSecondary = 0x27323B; t->secondaryContainer = 0x3A4650; t->onSecondaryContainer = 0xD6E5F2;
t->tertiary = 0xCDC2E6; t->onTertiary = 0x372C52; t->tertiaryContainer = 0x4E4269; t->onTertiaryContainer = 0xE9DEFB;
t->surface = 0x141824; t->onSurface = 0xFFFFFF; t->surfaceVariant = 0x2A2F3C; t->onSurfaceVariant = 0x9AA4C8;
t->surfaceContainerLowest = 0x0F121C; t->surfaceContainerLow = 0x1C2030; t->surfaceContainer = 0x20253A;
t->surfaceContainerHigh = 0x262C44; t->surfaceContainerHighest = 0x2C334E;
t->surfaceDim = 0x12151E; t->surfaceBright = 0x3A3E50; t->surfaceTint = 0x4A6A9A;
t->outline = 0x8B93A3; t->outlineVariant = 0x3E4450; t->scrim = 0x000000;
t->error = 0xFFB4AB; t->onError = 0x690005; t->errorContainer = 0x93000A; t->onErrorContainer = 0xFFDAD6;
t->inverseSurface = 0xF0F0F5; t->inverseOnSurface = 0x2F3036; t->inversePrimary = 0xA6C8EE;
t->shadow = 0x000000;
t->radius = 12; t->radius_card = 16; t->spacing = 8; t->stroke_w = 0;
/* MIUIx = MD3 基础(占位),primary 更饱和、圆角/间距更大、细描边(§8.1.3 可感知差异)。
* 先整表复制 MD3,再覆写差异字段。 */
g_theme[MEOW_STYLE_MIUIX][0] = g_theme[MEOW_STYLE_MD3][0];
g_theme[MEOW_STYLE_MIUIX][0].primary = 0x2A5AC8; g_theme[MEOW_STYLE_MIUIX][0].accent = 0x2A5AC8;
g_theme[MEOW_STYLE_MIUIX][0].primaryContainer = 0xD6E1FA; g_theme[MEOW_STYLE_MIUIX][0].surfaceTint = 0x2A5AC8;
g_theme[MEOW_STYLE_MIUIX][0].radius = 18; g_theme[MEOW_STYLE_MIUIX][0].radius_card = 24;
g_theme[MEOW_STYLE_MIUIX][0].spacing = 10; g_theme[MEOW_STYLE_MIUIX][0].stroke_w = 1;
g_theme[MEOW_STYLE_MIUIX][1] = g_theme[MEOW_STYLE_MD3][1];
g_theme[MEOW_STYLE_MIUIX][1].primary = 0x4A7AE8; g_theme[MEOW_STYLE_MIUIX][1].accent = 0x4A7AE8;
g_theme[MEOW_STYLE_MIUIX][1].primaryContainer = 0x2A3A6C; g_theme[MEOW_STYLE_MIUIX][1].surfaceTint = 0x4A7AE8;
g_theme[MEOW_STYLE_MIUIX][1].radius = 18; g_theme[MEOW_STYLE_MIUIX][1].radius_card = 24;
g_theme[MEOW_STYLE_MIUIX][1].spacing = 10; g_theme[MEOW_STYLE_MIUIX][1].stroke_w = 1;
}
/* ---- 背景全局源(§8.1.4):display.background 是「style×mode 下背景底选项集」的当前值,
* 决定主题 surface/bg(深浅成对)。按名映射 (dark_surface, light_surface):
* dark 默认/black → 0x141824 / light 默认/white → 0xE8EAF0(既有默认,保证 App 无回归);
* dark blue → 0x0A1428 / light blue → 0xE5EEFB;green → 0x0A2814 / 0xE6F6E8。
* 图片路径(*.png/jpg/jpeg):背景图即观感 → 用默认 surface(本批草案)。 */
static int bg_is_image(const char *v)
{
while (*v == ' ' || *v == '\t') v++;
const char *dot = strrchr(v, '.');
if (!dot || dot == v) return 0;
return !strncasecmp(dot, ".png", 4) || !strncasecmp(dot, ".jpg", 4) || !strncasecmp(dot, ".jpeg", 5);
}
static void bg_surfaces(const char *v, uint32_t *dark, uint32_t *light)
{
*dark = 0x141824; *light = 0xE8EAF0; /* 默认(未知/图片/空)→ 既有默认面 */
while (*v == ' ' || *v == '\t') v++;
if (bg_is_image(v)) return; /* 背景图:用默认 */
if (!strncmp(v, "blue", 4)) { *dark = 0x0A1428; *light = 0xE5EEFB; return; }
if (!strncmp(v, "green", 5)) { *dark = 0x0A2814; *light = 0xE6F6E8; return; }
if (!strncmp(v, "white", 5)) { *dark = 0x141824; *light = 0xFFFFFF; return; }
if (!strncmp(v, "lightblue", 9)) { *dark = 0x0A1428; *light = 0xE5EEFB; return; }
if (!strncmp(v, "lightgreen", 10)) { *dark = 0x0A2814; *light = 0xE6F6E8; return; }
/* black / 其它未知 → 默认面 */
}
static void apply_background(void)
{
uint32_t ds, ls;
bg_surfaces(g_background, &ds, &ls);
for (int s = 0; s < 2; s++) {
g_theme[s][0].bg = g_theme[s][0].surface = ls; /* light 行 */
g_theme[s][1].bg = g_theme[s][1].surface = ds; /* dark 行 */
}
}
static void load_settings(void)
{
char buf[64];
@@ -117,6 +207,16 @@ static void load_settings(void)
while (*v == ' ' || *v == '\t') v++;
if (!strncmp(v, "miuix", 5) || !strncmp(v, "miui", 4)) g_style = MEOW_STYLE_MIUIX;
}
/* 背景全局源(§8.1.4):display.background 为 style×mode 下背景底选项集的当前值。
* 读取缺失/未知 → ""(默认面)。 */
g_background[0] = 0;
if (get_setting_str("display.background", g_background, sizeof g_background) != 0)
g_background[0] = 0;
/* 载入/覆写 4 张主题表(色板 + style×mode 背景 surface/bg) */
init_defaults();
apply_background();
}
/* 当前本地时刻的「当天第几分钟」(tm_hour*60+tm_min);供时段判定用(与 launcher s_now_min_of_day 一致)。 */
@@ -155,13 +255,21 @@ static void broadcast(void)
if (g_listeners[i]) g_listeners[i](g_mode);
}
/* 当前「style×mode」主题:style=0/1(MD3/MIUIX),dark=0(light)/1(dark)。 */
static const meow_theme *theme_current(int style, int dark)
{
if (style < MEOW_STYLE_MD3) style = MEOW_STYLE_MD3;
if (style > MEOW_STYLE_MIUIX) style = MEOW_STYLE_MIUIX;
return &g_theme[style][dark ? 1 : 0];
}
const meow_theme *meow_theme_get(void)
{
if (!g_loaded) {
load_settings();
g_loaded = 1;
}
return resolve_mode(g_mode) == MEOW_THEME_DARK ? &g_dark : &g_light;
return theme_current(g_style, resolve_mode(g_mode) == MEOW_THEME_DARK);
}
meow_theme_mode meow_theme_get_mode(void)
@@ -189,11 +297,9 @@ void meow_theme_reload(void)
meow_theme meow_theme_defaults(meow_theme_mode m)
{
switch (resolve_mode(m)) {
case MEOW_THEME_DARK: return g_dark;
case MEOW_THEME_LIGHT:
default: return g_light;
}
if (!g_loaded) { load_settings(); g_loaded = 1; }
/* 脱机取内置板:返回 MD3(默认)style 下解析出的模式表。 */
return g_theme[MEOW_STYLE_MD3][resolve_mode(m) == MEOW_THEME_DARK ? 1 : 0];
}
/* ---- §8.1.2 顶级主题风格族(minimal)----
@@ -213,8 +319,9 @@ void meow_ui_set_style(int style)
if (style > MEOW_STYLE_MIUIX) style = MEOW_STYLE_MIUIX;
if (style == g_style) return;
g_style = style;
/* 触发下一帧按新 style 重绘:清 settings 缓存(下次 get 重读)不必要(style 已记录),
* 仅广播主题 listener(沿用 theme 广播机制,让控件/状态栏下一帧用新 style 重绘)。 */
/* 触发下一帧按新 style 重绘(§8.1.2):g_theme[s][*] 是独立表(不随 g_style 重算),
* g_style 记录后 meow_theme_get() 立即可取新 style×mode 表;只需广播主题 listener,
* 让 App/状态栏/控件下一帧用新 style 重绘/换图标集。不清 settings 缓存(避免覆盖程序化 style)。 */
broadcast();
}