+
+void ui_register_icon_browser(void);
+
+ui_widget_t *ui_create_icon_browser(void);
+
+void icon_browser_update(ui_widget_t *w);
+
+void ui_load_icon_browser_resources(void);
diff --git a/examples/doc-viewer/app/components/icon-browser.tsx b/examples/doc-viewer/app/components/icon-browser.tsx
new file mode 100644
index 00000000..eef18e5c
--- /dev/null
+++ b/examples/doc-viewer/app/components/icon-browser.tsx
@@ -0,0 +1,128 @@
+import {
+ Button,
+ ScrollArea,
+ ScrollAreaContent,
+ Scrollbar,
+ Text,
+ TextInput,
+ Widget,
+} from "@lcui/react";
+import { Dismiss, DismissCircle, Icon, iconMap } from "@lcui/fluent-icons";
+import "./icon-browser.css";
+
+const iconNames = Object.keys(iconMap).sort();
+
+function getFilledPreviewSize(name: keyof typeof iconMap) {
+ const sizes = Object.keys(iconMap[name].filled).map(Number);
+ return sizes.reduce((best, size) => {
+ const distance = Math.abs(size - 24);
+ const bestDistance = Math.abs(best - 24);
+ return distance < bestDistance || (distance === bestDistance && size < best)
+ ? size
+ : best;
+ });
+}
+
+function getIconComponentName(name: keyof typeof iconMap) {
+ const componentName = name
+ .split("-")
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
+ .join("");
+ return Object.keys(iconMap[name].regular).length > 0
+ ? componentName
+ : `${componentName}Filled`;
+}
+
+function hasRegularStyle(name: keyof typeof iconMap) {
+ return Object.keys(iconMap[name].regular).length > 0;
+}
+
+interface IconBrowserProps {
+ locale?: "en" | "zh-CN";
+}
+
+export default function IconBrowser(_props: IconBrowserProps) {
+ return (
+
+
+
+
+
+ {iconNames.map((name) => (
+
+
+
+ ))}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 复制 C 代码
+
+
+ 复制 JSX
+
+
+ 复制 XML
+
+
+
+
+
+ );
+}
diff --git a/examples/doc-viewer/app/en/devtools/icon-library/page.tsx b/examples/doc-viewer/app/en/devtools/icon-library/page.tsx
index 0b6179a8..3be56ccc 100644
--- a/examples/doc-viewer/app/en/devtools/icon-library/page.tsx
+++ b/examples/doc-viewer/app/en/devtools/icon-library/page.tsx
@@ -1,5 +1,6 @@
import { Text, Widget } from "@lcui/react";
import CodeBlockCopy from "../../../components/code-block-copy";
+import IconBrowser from "../../../components/icon-browser";
export default function IconLibraryDocPage() {
return (
@@ -20,7 +21,9 @@ export default function IconLibraryDocPage() {
Choosing icons
- {`Search and select icons on flicon.io. For example, the zoom-in icon is typically named "Zoom In" in English.`}
+ {`Search and select icons in the browser below. For example, the zoom-in icon is typically named "Zoom In" in English.`}
+
+ {`Fluent UI System Icons provides direction-related metadata, but its icon data has no category field, so the detail panel does not show category tags.`}
{`fluentui-system-icons icons are available in sizes like 16, 20, and 24, named in the format "icon name + size + style". [bgcolor=#eee] @lcui/fluent-icons [/bgcolor] uses the naming format "icon name + style", and when the style is Regular it can be omitted.`}
@@ -36,7 +39,7 @@ export default function IconLibraryDocPage() {
{`[color=#116329]<[color=#0550ae]ZoomIn[/color] />[/color]`}
- {`The default size is 20. If the icon size is fixed and you want better rendering, specify the size parameter:`}
+ {`The default glyph is regular 24; when an icon has no regular 24 glyph, the closest available regular size is used (ties choose the smaller size). [bgcolor=#eee] size [/bgcolor] selects a design glyph size and, when explicitly set, also sets its display size. [bgcolor=#eee] fontSize [/bgcolor] changes only the rendered size without changing glyph selection. If neither is set, the icon inherits the surrounding text size, so [bgcolor=#eee] className [/bgcolor] or [bgcolor=#eee] style [/bgcolor] can also control the display size:`}
TypeScript
@@ -46,6 +49,25 @@ export default function IconLibraryDocPage() {
{`<[color=#8250df]ZoomIn[/color] size={[color=#0550ae]32[/color]} />`}
+ {`In C, create a Fluent icon with the convenience constructor. In XML, omitting [bgcolor=#eee] library [/bgcolor] defaults to Fluent; specify it only when using another icon library:`}
+
+
+ C
+
+
+
+ {`[color=#953800]ui_widget_t[/color] *icon = ui_create_fluent_icon([color=#0a3069]"dismiss"[/color]);`}
+
+
+
+
+ XML
+
+
+
+ {`[color=#116329]<[color=#0550ae]icon[/color] [color=#0550ae]name[/color]=[color=#0a3069]"dismiss"[/color] />[/color]`}
+
+
);
diff --git a/examples/doc-viewer/app/layout.tsx b/examples/doc-viewer/app/layout.tsx
index 755ebd74..48df30ec 100644
--- a/examples/doc-viewer/app/layout.tsx
+++ b/examples/doc-viewer/app/layout.tsx
@@ -1,7 +1,8 @@
import { PropsWithChildren, ScrollArea, ScrollAreaContent, Scrollbar } from "@lcui/react";
import Navbar from "./components/navbar";
import Sidebar from "./components/sidebar";
-import "@lcui/fluent-icons/dist/style.css";
+import "@lcui/fluent-icons/dist/icons.css";
+import "@lcui/fluent-icons/dist/icons-filled.css";
import "./global.css";
export default function AppLayout({ children }: PropsWithChildren) {
diff --git a/examples/doc-viewer/app/zh-CN/devtools/icon-library/page.tsx b/examples/doc-viewer/app/zh-CN/devtools/icon-library/page.tsx
index 93406113..838d4c7b 100644
--- a/examples/doc-viewer/app/zh-CN/devtools/icon-library/page.tsx
+++ b/examples/doc-viewer/app/zh-CN/devtools/icon-library/page.tsx
@@ -1,5 +1,6 @@
import { Text, Widget } from "@lcui/react";
import CodeBlockCopy from "../../../components/code-block-copy";
+import IconBrowser from "../../../components/icon-browser";
export default function IconLibraryDocPage() {
return (
@@ -20,7 +21,9 @@ export default function IconLibraryDocPage() {
选取图标
- {`在 flicon.io 网站中搜索和选取图标。以放大图标为例,英文名通常是 Zoom In。`}
+ {`你可以在下面的图标库视图中搜索并选择图标。以放大图标为例,英文名通常是 Zoom In。`}
+
+ {`Fluent UI System Icons 提供方向相关的元数据,但图标数据没有分类字段,因此详情面板不显示分类标签。`}
{`fluentui-system-icons 的图标有 16、20、24 等几种尺寸可选,命名方式是"图标名+尺寸+风格"。[bgcolor=#eee] @lcui/fluent-icons [/bgcolor] 的命名方式是"图标名+风格",当风格为 Regular 时可以省略它。`}
@@ -36,7 +39,7 @@ export default function IconLibraryDocPage() {
{`[color=#116329]<[color=#0550ae]ZoomIn[/color] />[/color]`}
- {`默认尺寸是 20。如果图标尺寸固定且希望更好的渲染效果,可以指定 size 参数:`}
+ {`默认选择 regular 24 字形;如果没有 24,则选择最接近的可用 regular 尺寸,距离相同时选较小尺寸。[bgcolor=#eee] size [/bgcolor] 选择设计字形尺寸,并在显式设置时同步设置显示字号;[bgcolor=#eee] fontSize [/bgcolor] 只改变显示字号、不改变字形选择。未显式设置时图标会继承周围的文字字号,因此也可以通过 [bgcolor=#eee] className [/bgcolor] 或 [bgcolor=#eee] style [/bgcolor] 调整显示大小:`}
TypeScript
@@ -46,6 +49,25 @@ export default function IconLibraryDocPage() {
{`<[color=#8250df]ZoomIn[/color] size={[color=#0550ae]32[/color]} />`}
+ {`C 代码可用 Fluent 快捷构造函数创建图标。XML 中省略 [bgcolor=#eee] library [/bgcolor] 时默认使用 Fluent;只有使用其它图标库时才需要指定该属性:`}
+
+
+ C
+
+
+
+ {`[color=#953800]ui_widget_t[/color] *icon = ui_create_fluent_icon([color=#0a3069]"dismiss"[/color]);`}
+
+
+
+
+ XML
+
+
+
+ {`[color=#116329]<[color=#0550ae]icon[/color] [color=#0550ae]name[/color]=[color=#0a3069]"dismiss"[/color] />[/color]`}
+
+
);
diff --git a/examples/doc-viewer/scripts/compiler/index.ts b/examples/doc-viewer/scripts/compiler/index.ts
index 6cd0717a..78380737 100644
--- a/examples/doc-viewer/scripts/compiler/index.ts
+++ b/examples/doc-viewer/scripts/compiler/index.ts
@@ -202,7 +202,7 @@ async function main(): Promise {
}
});
} else {
- console.log("\n[done] Build complete → tools/doc-viewer/app/");
+ console.log("\n[done] Build complete → examples/doc-viewer/app/");
}
}
diff --git a/examples/doc-viewer/scripts/compiler/page-generator.ts b/examples/doc-viewer/scripts/compiler/page-generator.ts
index 4012c7e8..60a26f75 100644
--- a/examples/doc-viewer/scripts/compiler/page-generator.ts
+++ b/examples/doc-viewer/scripts/compiler/page-generator.ts
@@ -486,6 +486,14 @@ function renderSectionContent(
continue;
}
+ if (trimmed === " ") {
+ out.push(
+ `${indent} `,
+ );
+ i++;
+ continue;
+ }
+
// ### heading inside section content
const h3Match = line.match(/^### (.+)$/);
if (h3Match) {
@@ -931,10 +939,15 @@ function buildContentPageTsx(
const allImports = [ftImportBlock].filter(Boolean).join("\n");
const importsBlock = allImports ? `${allImports}\n` : "";
+ const iconBrowserImport = parsed.sections.some((section) =>
+ section.content.includes(" "),
+ )
+ ? `import IconBrowser from "${relativeImport(pageDir, join(examplesOutDir, "..", "components", "icon-browser"))}";\n`
+ : "";
return `import { Text, Widget } from "@lcui/react";
import CodeBlockCopy from "${ccPath}";
-${importsBlock}
+${iconBrowserImport}${importsBlock}
export default function ${componentName}() {
return (
diff --git a/include/LCUI/widgets.h b/include/LCUI/widgets.h
index fbd0154e..e49ef2f2 100644
--- a/include/LCUI/widgets.h
+++ b/include/LCUI/widgets.h
@@ -24,3 +24,4 @@
#include "widgets/checkbox.h"
#include "widgets/radio_group.h"
#include "widgets/field.h"
+#include "widgets/icon.h"
diff --git a/include/LCUI/widgets/icon.h b/include/LCUI/widgets/icon.h
new file mode 100644
index 00000000..4d58358b
--- /dev/null
+++ b/include/LCUI/widgets/icon.h
@@ -0,0 +1,35 @@
+/*
+ * include/LCUI/widgets/icon.h: -- LCUI's Icon widget
+ *
+ * Copyright (c) 2026, Liu Chao All rights reserved.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * This file is part of LCUI, distributed under the MIT LICENSE file in the
+ * LICENSE.TXT file in the root directory of this source tree.
+ */
+
+#ifndef LCUI_INCLUDE_WIDGETS_ICON_H
+#define LCUI_INCLUDE_WIDGETS_ICON_H
+
+#include
+#include
+
+LCUI_BEGIN_HEADER
+
+typedef enum ui_icon_library {
+ UI_ICON_LIBRARY_FLUENT,
+ UI_ICON_LIBRARY_LUCIDE,
+} ui_icon_library_t;
+
+LCUI_API ui_widget_t *ui_create_icon(void);
+LCUI_API ui_widget_t *ui_create_fluent_icon(const char *name);
+LCUI_API void ui_icon_set_library(ui_widget_t *icon, ui_icon_library_t library);
+LCUI_API void ui_icon_set_name(ui_widget_t *icon, const char *name);
+LCUI_API void ui_icon_set_size(ui_widget_t *icon, int size);
+LCUI_API void ui_icon_set_filled(ui_widget_t *icon, bool filled);
+LCUI_API void ui_register_icon(void);
+
+LCUI_END_HEADER
+
+#endif
diff --git a/src/lcui_widgets.c b/src/lcui_widgets.c
index 4a17232d..cbbf3514 100644
--- a/src/lcui_widgets.c
+++ b/src/lcui_widgets.c
@@ -19,10 +19,11 @@ void lcui_widgets_init(void)
ui_register_canvas();
ui_register_anchor();
ui_register_button();
- ui_register_select();
- ui_register_progress();
+ ui_register_icon();
ui_register_scrollarea();
ui_register_scrollbar();
+ ui_register_select();
+ ui_register_progress();
ui_register_textcaret();
ui_register_textinput();
ui_register_router_link();
diff --git a/src/widgets/icon.c b/src/widgets/icon.c
new file mode 100644
index 00000000..42ca797c
--- /dev/null
+++ b/src/widgets/icon.c
@@ -0,0 +1,223 @@
+/*
+ * src/widgets/icon.c: -- Icon widget
+ *
+ * Copyright (c) 2026, Liu Chao All rights reserved.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * This file is part of LCUI, distributed under the MIT LICENSE file in the
+ * LICENSE.TXT file in the root directory of this source tree.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+typedef struct ui_icon {
+ char *name;
+ char *name_class;
+ char *filled_class;
+ char *size_class;
+ int size;
+ bool filled;
+ ui_icon_library_t library;
+} ui_icon_t;
+
+static ui_widget_prototype_t *ui_icon_prototype;
+
+/* Fluent icon glyphs have degenerate vertical metrics (hhea ascender = 1em,
+ * descender = 0), and pandagl centers the line box by the font ascent/descent
+ * box, so the ink renders slightly above the visual center (~0.5-2.5px
+ * depending on the font size). Nudge fluent icons down 1px rather than
+ * patching the font or the renderer. */
+static const char *ui_icon_css = "\
+icon,\
+icon.fui-icon {\
+ top: 1px;\
+ display: inline-block;\
+ position: relative;\
+ line-height: 1;\
+}";
+
+static const char *ui_icon_library_names[] = {
+ "fluent",
+ "lucide",
+};
+
+static const char *ui_icon_library_classes[] = {
+ "fui-icon",
+ "lucide-icon",
+};
+
+static bool ui_icon_parse_bool(const char *value)
+{
+ return value &&
+ (strcmp(value, "true") == 0 || strcmp(value, "yes") == 0 ||
+ strcmp(value, "on") == 0 || strcmp(value, "1") == 0);
+}
+
+static void ui_icon_remove_class(ui_widget_t *icon, char **class_name)
+{
+ if (*class_name) {
+ ui_widget_remove_class(icon, *class_name);
+ free(*class_name);
+ *class_name = NULL;
+ }
+}
+
+static char *ui_icon_create_class(const char *prefix, const char *name)
+{
+ size_t length = strlen(prefix) + strlen(name) + 1;
+ char *class_name = malloc(length);
+
+ snprintf(class_name, length, "%s%s", prefix, name);
+ return class_name;
+}
+
+static void ui_icon_update_classes(ui_widget_t *icon)
+{
+ ui_icon_t *that = ui_widget_get_data(icon, ui_icon_prototype);
+ const char *font_class = ui_icon_library_classes[that->library];
+ const char *name_prefix;
+ const char *size_prefix;
+ char size[16];
+
+ ui_widget_remove_class(icon, "fui-icon");
+ ui_widget_remove_class(icon, "lucide-icon");
+ ui_icon_remove_class(icon, &that->name_class);
+ ui_icon_remove_class(icon, &that->filled_class);
+ ui_icon_remove_class(icon, &that->size_class);
+ ui_widget_add_class(icon, font_class);
+ if (!that->name || !that->name[0]) {
+ return;
+ }
+
+ name_prefix = that->library == UI_ICON_LIBRARY_FLUENT ? "fui-icon-"
+ : "lucide-icon-";
+ size_prefix = that->library == UI_ICON_LIBRARY_FLUENT
+ ? "fui-icon-glyph-"
+ : "lucide-icon-glyph-";
+ that->name_class = ui_icon_create_class(name_prefix, that->name);
+ ui_widget_add_class(icon, that->name_class);
+ if (that->library == UI_ICON_LIBRARY_FLUENT && that->filled) {
+ that->filled_class = y_strdup("fui-icon-filled");
+ ui_widget_add_class(icon, that->filled_class);
+ }
+ if (that->size > 0 && that->size != 24) {
+ snprintf(size, sizeof(size), "%d", that->size);
+ that->size_class = ui_icon_create_class(size_prefix, size);
+ ui_widget_add_class(icon, that->size_class);
+ }
+}
+
+static void ui_icon_update_name(ui_widget_t *icon, const char *name)
+{
+ ui_icon_t *that = ui_widget_get_data(icon, ui_icon_prototype);
+
+ free(that->name);
+ that->name = name ? y_strdup(name) : NULL;
+ ui_icon_update_classes(icon);
+}
+
+static void ui_icon_on_set_attr(ui_widget_t *icon, const char *name,
+ const char *value)
+{
+ ui_icon_t *that = ui_widget_get_data(icon, ui_icon_prototype);
+
+ if (strcmp(name, "library") == 0) {
+ that->library = value && strcmp(value, "lucide") == 0
+ ? UI_ICON_LIBRARY_LUCIDE
+ : UI_ICON_LIBRARY_FLUENT;
+ ui_icon_update_classes(icon);
+ } else if (strcmp(name, "name") == 0) {
+ ui_icon_update_name(icon, value);
+ } else if (strcmp(name, "size") == 0) {
+ that->size = value ? atoi(value) : 0;
+ if (that->size < 1) {
+ that->size = 0;
+ }
+ ui_icon_update_classes(icon);
+ } else if (strcmp(name, "filled") == 0) {
+ that->filled = ui_icon_parse_bool(value);
+ ui_icon_update_classes(icon);
+ }
+}
+
+static void ui_icon_on_init(ui_widget_t *icon)
+{
+ ui_icon_t *that;
+
+ ui_icon_prototype->proto->init(icon);
+ that = ui_widget_add_data(icon, ui_icon_prototype, sizeof(ui_icon_t));
+ that->name = NULL;
+ that->name_class = NULL;
+ that->filled_class = NULL;
+ that->size_class = NULL;
+ that->size = 0;
+ that->filled = false;
+ that->library = UI_ICON_LIBRARY_FLUENT;
+ ui_icon_update_classes(icon);
+}
+
+static void ui_icon_on_destroy(ui_widget_t *icon)
+{
+ ui_icon_t *that = ui_widget_get_data(icon, ui_icon_prototype);
+
+ free(that->name);
+ free(that->name_class);
+ free(that->filled_class);
+ free(that->size_class);
+ ui_icon_prototype->proto->destroy(icon);
+}
+
+ui_widget_t *ui_create_icon(void)
+{
+ return ui_create_widget_with_prototype(ui_icon_prototype);
+}
+
+ui_widget_t *ui_create_fluent_icon(const char *name)
+{
+ ui_widget_t *icon = ui_create_icon();
+
+ ui_icon_set_name(icon, name);
+ return icon;
+}
+
+void ui_icon_set_library(ui_widget_t *icon, ui_icon_library_t library)
+{
+ if (library < UI_ICON_LIBRARY_FLUENT ||
+ library > UI_ICON_LIBRARY_LUCIDE) {
+ library = UI_ICON_LIBRARY_FLUENT;
+ }
+ ui_widget_set_attr(icon, "library", ui_icon_library_names[library]);
+}
+
+void ui_icon_set_name(ui_widget_t *icon, const char *name)
+{
+ ui_widget_set_attr(icon, "name", name ? name : "");
+}
+
+void ui_icon_set_size(ui_widget_t *icon, int size)
+{
+ char value[16];
+
+ snprintf(value, sizeof(value), "%d", size);
+ ui_widget_set_attr(icon, "size", value);
+}
+
+void ui_icon_set_filled(ui_widget_t *icon, bool filled)
+{
+ ui_widget_set_attr(icon, "filled", filled ? "true" : "false");
+}
+
+void ui_register_icon(void)
+{
+ ui_icon_prototype = ui_create_widget_prototype("icon", "text");
+ ui_icon_prototype->init = ui_icon_on_init;
+ ui_icon_prototype->destroy = ui_icon_on_destroy;
+ ui_icon_prototype->setattr = ui_icon_on_set_attr;
+ ui_load_css_string(ui_icon_css, __FILE__);
+}
diff --git a/tests/integration/test_icon.c b/tests/integration/test_icon.c
new file mode 100644
index 00000000..dd61d0b2
--- /dev/null
+++ b/tests/integration/test_icon.c
@@ -0,0 +1,205 @@
+/*
+ * tests/integration/test_icon.c: -- Icon widget tests
+ *
+ * Copyright (c) 2026, Liu Chao All rights reserved.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include
+#include
+
+static void test_defaults(void)
+{
+ ui_widget_t *icon = ui_create_icon();
+
+ ctest_equal_bool("should inherit the text prototype",
+ ui_check_widget_type(icon, "text"), true);
+ ctest_equal_bool("should use the shared Fluent font class",
+ ui_widget_has_class(icon, "fui-icon"), true);
+ ctest_equal_bool("should omit the old Fluent regular font class",
+ ui_widget_has_class(icon, "fui-icon-regular"), false);
+
+ ui_widget_destroy(icon);
+}
+
+static void test_fluent_factory(void)
+{
+ ui_widget_t *icon = ui_create_fluent_icon("checkmark");
+
+ ctest_equal_bool("should create a Fluent icon with its name class",
+ ui_widget_has_class(icon, "fui-icon-checkmark"), true);
+ ctest_equal_bool("should use the shared Fluent font class",
+ ui_widget_has_class(icon, "fui-icon"), true);
+ ctest_equal_bool("should use automatic design size by default",
+ ui_widget_has_class(icon, "fui-icon-glyph-0"), false);
+ ui_widget_destroy(icon);
+}
+
+static void test_glyph_class(void)
+{
+ ui_widget_t *icon = ui_create_icon();
+
+ ui_icon_set_name(icon, "access-time");
+ ctest_equal_bool("should add the namespaced Fluent icon class",
+ ui_widget_has_class(icon, "fui-icon-access-time"),
+ true);
+ ctest_equal_bool("should omit a glyph size class for the default size",
+ ui_widget_has_class(icon, "fui-icon-glyph-24"), false);
+ ctest_equal_bool("should omit the unnamespaced icon name class",
+ ui_widget_has_class(icon, "access-time"), false);
+ ctest_equal_bool("should omit the legacy regular glyph class",
+ ui_widget_has_class(icon, "access-time-24-regular"),
+ false);
+
+ ui_icon_set_size(icon, 20);
+ ctest_equal_bool("should remove the previous glyph class",
+ ui_widget_has_class(icon, "access-time-24-regular"),
+ false);
+ ctest_equal_bool("should omit the legacy size glyph class",
+ ui_widget_has_class(icon, "access-time-20-regular"),
+ false);
+ ctest_equal_bool("should add the requested glyph size class",
+ ui_widget_has_class(icon, "fui-icon-glyph-20"), true);
+ ctest_equal_bool("should omit the unnamespaced glyph size class",
+ ui_widget_has_class(icon, "size-20"), false);
+
+ ui_icon_set_size(icon, 0);
+ ctest_equal_bool(
+ "should remove the glyph size class when size is automatic",
+ ui_widget_has_class(icon, "fui-icon-glyph-20"), false);
+ ctest_equal_bool("should omit a zero glyph size class",
+ ui_widget_has_class(icon, "fui-icon-glyph-0"), false);
+
+ ui_widget_destroy(icon);
+}
+
+static void test_library_and_fill(void)
+{
+ ui_widget_t *icon = ui_create_icon();
+
+ ui_icon_set_name(icon, "access-time");
+ ui_icon_set_filled(icon, true);
+ ctest_equal_bool("should keep the namespaced Fluent icon class",
+ ui_widget_has_class(icon, "fui-icon-access-time"),
+ true);
+ ctest_equal_bool("should add the namespaced filled modifier",
+ ui_widget_has_class(icon, "fui-icon-filled"), true);
+ ctest_equal_bool("should omit the unnamespaced filled modifier",
+ ui_widget_has_class(icon, "filled"), false);
+ ctest_equal_bool("should keep the shared Fluent font class",
+ ui_widget_has_class(icon, "fui-icon"), true);
+ ctest_equal_bool("should omit the old Fluent regular font class",
+ ui_widget_has_class(icon, "fui-icon-regular"), false);
+ ctest_equal_bool("should replace the regular glyph class",
+ ui_widget_has_class(icon, "access-time-24-regular"),
+ false);
+ ctest_equal_bool("should omit the legacy filled glyph class",
+ ui_widget_has_class(icon, "access-time-24-filled"),
+ false);
+ ui_icon_set_size(icon, 20);
+ ctest_equal_bool("should add glyph size class while filled",
+ ui_widget_has_class(icon, "fui-icon-glyph-20"), true);
+ ctest_equal_bool("should omit the legacy filled size glyph class",
+ ui_widget_has_class(icon, "access-time-20-filled"),
+ false);
+
+ ui_widget_destroy(icon);
+}
+
+static void test_lucide_class(void)
+{
+ ui_widget_t *icon = ui_create_icon();
+
+ ui_icon_set_library(icon, UI_ICON_LIBRARY_LUCIDE);
+ ui_icon_set_name(icon, "access-time");
+ ui_icon_set_size(icon, 20);
+ ui_icon_set_filled(icon, true);
+
+ ctest_equal_bool("should use the Lucide base class",
+ ui_widget_has_class(icon, "lucide-icon"), true);
+ ctest_equal_bool("should use a namespaced Lucide icon class",
+ ui_widget_has_class(icon, "lucide-icon-access-time"),
+ true);
+ ctest_equal_bool("should use a namespaced Lucide glyph size class",
+ ui_widget_has_class(icon, "lucide-icon-glyph-20"),
+ true);
+ ctest_equal_bool("should omit the old Lucide base class",
+ ui_widget_has_class(icon, "lui-icon-regular"), false);
+ ctest_equal_bool("should ignore filled for Lucide",
+ ui_widget_has_class(icon, "filled"), false);
+ ctest_equal_bool("should omit the old Lucide glyph class",
+ ui_widget_has_class(icon, "access-time-20-regular"),
+ false);
+ ctest_equal_bool("should omit a filled Lucide glyph class",
+ ui_widget_has_class(icon, "access-time-20-filled"),
+ false);
+
+ ui_widget_destroy(icon);
+}
+
+static wchar_t get_icon_content(ui_widget_t *icon)
+{
+ wchar_t content[16] = { 0 };
+
+ ui_text_get_content_w(icon, content, 16);
+ return content[0];
+}
+
+static void test_content_selection(void)
+{
+ static const char css[] =
+ ".fui-icon { content: \"\\e000\"; }\n"
+ ".fui-icon.fui-icon-checkmark { content: \"\\e001\"; }\n"
+ ".fui-icon.fui-icon-checkmark.fui-icon-filled { content: "
+ "\"\\e101\"; }\n"
+ ".fui-icon.fui-icon-checkmark.fui-icon-glyph-48 { content: "
+ "\"\\e002\"; }\n"
+ ".fui-icon.fui-icon-checkmark.fui-icon-filled.fui-icon-glyph-48 { "
+ "content: \"\\e102\"; }\n";
+ ui_widget_t *icon = ui_create_icon();
+
+ ui_icon_set_name(icon, "checkmark");
+ ui_root_append(icon);
+ ui_load_css_string(css, "fluent-icon.css");
+ ui_update();
+ ctest_equal_int("should use the base regular content",
+ get_icon_content(icon), 0xe001);
+
+ ui_icon_set_filled(icon, true);
+ ui_update();
+ ctest_equal_int("should switch content with the filled class",
+ get_icon_content(icon), 0xe101);
+
+ ui_icon_set_size(icon, 48);
+ ui_update();
+ ctest_equal_int("should select the filled size glyph",
+ get_icon_content(icon), 0xe102);
+
+ ui_icon_set_filled(icon, false);
+ ui_update();
+ ctest_equal_int("should select the regular size glyph",
+ get_icon_content(icon), 0xe002);
+
+ ui_icon_set_size(icon, 0);
+ ui_update();
+ ctest_equal_bool("should omit a glyph size class in automatic mode",
+ ui_widget_has_class(icon, "fui-icon-glyph-0"), false);
+ ctest_equal_int("should use the base glyph in automatic size mode",
+ get_icon_content(icon), 0xe001);
+ ui_widget_destroy(icon);
+}
+
+void test_icon(void)
+{
+ lcui_init();
+
+ ctest_describe("icon defaults", test_defaults);
+ ctest_describe("fluent icon factory", test_fluent_factory);
+ ctest_describe("icon glyph class", test_glyph_class);
+ ctest_describe("icon library and fill", test_library_and_fill);
+ ctest_describe("icon Lucide classes", test_lucide_class);
+ ctest_describe("icon CSS content", test_content_selection);
+
+ lcui_destroy();
+}
diff --git a/tests/main.c b/tests/main.c
index a94c1e60..e131728d 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -36,6 +36,7 @@ extern void test_radio_group(void);
extern void test_portal(void);
extern void test_select(void);
extern void test_cursor(void);
+extern void test_icon(void);
static const ctest_suite_t suites[] = {
{ "settings", test_settings },
@@ -62,6 +63,7 @@ static const ctest_suite_t suites[] = {
{ "portal", test_portal },
{ "select", test_select },
{ "cursor", test_cursor },
+ { "icon", test_icon },
{ NULL, NULL }
};