跳到主要内容

Components 概览

UltimateUI.Components 是运行在 Core DOM API 之上的声明式层。默认入口是 UltimateAppBuilderWindow 和函数式组件;底层仍然使用 UltimateUiApp、 opcode 协议和 WebKit host。

  • UltimateUI.Components:运行时包,包含 ComponentApp、hooks 和 CSS-in-CS。
  • UltimateUI.Components.SourceGen:Roslyn analyzer 包,读取 *.uui.csx 文件并生成 C#。
  • UltimateUI meta-package 会引用 Components 运行时;使用 CSX 时需要显式添加 analyzer 引用。
<ProjectReference Include="..\..\src\UltimateUI.Components.SourceGen\UltimateUI.Components.SourceGen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<AdditionalFiles Include="App.uui.csx" />

最小组件

var builder = UltimateAppBuilder.CreateDefaultBuilder();
var app = builder.Build();

var window = app.MainWindow = new Window();
window.Render(ctx =>
{
var count = ctx.UseState(0);
var button = new Button($"Clicked {count.Value}");
button.OnClick += (_, _) => count.Update(static value => value + 1);
return button;
});

return await app.RunAsync();

RunAsync 会创建 WebKitGTK render host、加载窗口样式、执行首次 render 并进入窗口 事件循环。之后 hook state setter 会请求一次 render,当前实现会替换宿主节点下的旧子树。 这个策略优先保证开发体验闭环;后续可在相同 contract 下接入 keyed diff。

与 Core API 的关系

组件 render 函数返回普通 UltimateUI.Element。这意味着你仍然可以使用现有元素、 属性、事件和 Style

var root = new Div { Class = "panel" };
root.Children.Add(new H1("Dashboard"));
root.Children.Add(new Button("Refresh"));
return root;

真实 renderer 使用 MountAsync;示例项目都绑定 WebKitGTK。