Skip to content

wuldas/Square

Repository files navigation

Square

Square 是一个纯 C#、编译优先、NativeAOT 友好的实验性跨平台桌面 UI 框架。

它借鉴 Vue、HTML 与 CSS 的开发体验,但不是浏览器,也不引入 Vue 运行时或 JavaScript 引擎。.sqv / .sqx 模板会在编译期由 Roslyn Source Generator 生成普通 C# 组件。

项目仍处于早期开发阶段,API 与模板语法可能调整。目前主要验证 Windows / Win32 与 Linux / X11 桌面宿主。

截图

Square sample screenshot

Square sample screenshot

Square sample screenshot

示例

Main.sqv

<template>
  <View class="page">
    <Text class="title">Hello {{ Name.Value }}</Text>

    <Input :value="Name" @input="OnNameChanged" />

    <Button ref="SaveButton" @click="OnSave">
      Save
    </Button>

    <Text v-if="Saved.Value">Saved</Text>
  </View>
</template>

<script lang="csharp">
  public ObservableValue<string> Name = new("Square");
  public ObservableValue<bool> Saved = new(false);

  private void OnNameChanged(Event e)
  {
      Name.Value = ((Input)e.Target!).Value;
  }

  private void OnSave()
  {
      Saved.Value = true;
  }
</script>

<style>
  .page {
      display: flex;
      flex-direction: column;
      gap: 12px;
      padding: 16px;
  }

  .title {
      font-size: 20px;
  }
</style>

Program.cs

using Square.Hosting;

var window = new AppWindow("My App", 800, 600);
window.Load(new Main());

new DesktopApplication(window).Run();

运行示例

dotnet restore Square.slnx
dotnet build Square.slnx
dotnet run --project samples/Square.Sample.Vue/Square.Sample.Vue.csproj

主示例可选择 CPU Skia 后端:

dotnet run --project samples/Square.Sample/Square.Sample.csproj -- --backend Skia

运行 RichText 示例:

dotnet run --project samples/Square.Sample.RichText/Square.Sample.RichText.csproj

运行测试:

dotnet test Square.slnx

NativeAOT 发布

Windows x64:

dotnet publish samples/Square.Sample.Vue/Square.Sample.Vue.csproj \
  -c Release \
  -r win-x64 \
  -p:SquareSamplePublishAot=true \
  --self-contained true

Linux x64 / X11:

dotnet publish samples/Square.Sample.Vue/Square.Sample.Vue.csproj \
  -c Release \
  -r linux-x64 \
  -p:SquareSamplePublishAot=true \
  -p:SquareTargetPlatform=X11 \
  --self-contained true

文档

项目状态

Square 适合框架设计验证、实验和贡献开发,暂不建议用于生产项目。

贡献流程见 CONTRIBUTING.md。安全问题请按 SECURITY.md 私下报告。

License

MIT

About

一个纯 C#、编译优先、NativeAOT 友好的实验性跨平台桌面 UI 框架,支持 SQX/SQV 模板、CSS 风格样式、保留模式渲染,以及 Win32/X11 平台宿主。An experimental compile-first cross-platform desktop UI framework in pure C#, designed for NativeAOT, with SQX/SQV templates, CSS-like styling, retained-mode rendering, and Win32/X11 platform hosts.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages