展示:Shirei,一款原生 Go 语言开发的跨平台 GUI 框架
Show HN: Shirei, cross-platform GUI framework in native Go

原始链接: https://github.com/hasenj/go-shirei/

Shirei 是一个用于 Go 语言的跨平台 GUI 框架,使开发者能够使用纯 Go 语言(无需 HTML 或 JavaScript)构建 macOS、Windows 和 Linux 上的原生、自包含桌面应用程序。 Shirei 采用了真正的“即时模式”(Immediate Mode)API,并从 React 的设计哲学中汲取了灵感。通过在每一帧基于当前数据描述 UI,它消除了开发者手动管理组件状态或生命周期的需求。这种方法在简化开发的同时,也为布局和样式提供了高度的灵活性。 核心特性包括: * **原生性能:** 生成体积小(约 10MB)的可执行文件,且没有任何外部依赖。 * **强大的文本支持:** 处理复杂的字形渲染、双向布局、系统字体,以及东亚语言的输入法(IME)。 * **开发者友好:** 提供直观的 API,设计上兼顾人类和 AI 代理的可读性,从而实现快速原型开发。 * **极简样板代码:** 包含一个开箱即用的完整框架,只需极少的设置即可运行。 无论你是从零开始构建,还是利用 AI 生成代码,Shirei 都能为创建跨平台桌面软件提供精简且一致的开发体验。

抱歉。
相关文章

原文

Shirei is a Cross-Platform GUI framework for Go. You get to write the UI using Go, not HTML and Javascript.

Truely cross-platform: the same code base produces identical looking programs for MacOS, Windows, and Linux. Also happens to be the easiest way to produce a self-contained GUI program for Linux that does not require any dependencies.

※ "Shirei" is derived from the Japanese pronunciation of "Simple Layout": シンプル・レイアウト → シレイ

haystack

Experience has shown us that an immediate mode API is the only sane way to program GUI applications. Unfrotunately, there is not good library or framework that just works. Some of them require you to implement your own backend, some of them do not have a decent cross-platform story, some of them do not have proper support for non-latin text.

What is it that matters for "immediate mode"? Is it that the UI renders everything every frame? No. It's that you build the UI by describing what it should look like everyframe, based only (or mostly) on the data.

This is why React won: no need to maintain UI widgets yourself, no need to keep track of their states in order to update them. You just say "at this point in time, I want a button here, and I want the label on it to say so and so, and when it's clicked, I want to do this and that".

Did this button exist before? What happens to it when you no longer need it?

You never have to answer these questions. This is the best part about React, and this is what "immediate mode" is all about.

It is no good if you have an API that just lets you "draw" things but you are also responsible for maintaining the state of all the "things" that you "draw".

process monitor

  • Native: real executable programs, not web pages. Typical binary size ≈10MB.

  • Immediate mode API in the true sense: you never need to maintain UI widgets or sync your data with widget state.

  • Works out of the box: not just a layout engine, but a full fledged framework that you can start using right away without any boilerplate.

  • Full support for international text: complex shaping, bidirectional layout, access to system fonts, IME support (input method editor) for East Asian langauges.

  • Flexible layout and styling: one of the good things about the web is that you have alot of flexibilty in how you arrange the UI; you're not limited to just a standard set of widgets and containers. You can make your own.

  • Easy to learn API, for both humans and AI agents. If you have ideas for small programs you want to make but don't have the time for, try asking the latest AI engines to use shirei to build it. You'll be surprised how well they can use it.

Several example programs under examples/ — start with haystack if you only look at one.

Copy this into main.go in a new folder:

package main

import (
	"fmt"

	app "go.hasen.dev/shirei/app"

	. "go.hasen.dev/shirei"
	. "go.hasen.dev/shirei/widgets"
)

func main() {
	app.SetupWindow("My App", 300, 100)
	app.Run(RootView)
}

var count int

func RootView() {
	Container(Attrs(Viewport, Background(220, 10, 97, 1)), func() {
		Container(Attrs(Row, CrossMid, Pad(20), Gap(10)), func() {
			Label(fmt.Sprintf("Counter: %d", count))
			if Button(SymIPlus, "Increment") {
				count++
			}
		})
	})
}

Then type:

$ go mod init main
$ go mod tidy
$ go run .
联系我们 contact @ memedata.com