返回排行榜

AllenDang/giu

Go

Cross platform rapid GUI framework for golang based on Dear ImGui.

cross-platformguigolangimguidear-imguiuiuikit
Star 增长趋势
Star
2.8k
Forks
156
周增长
Issues
28
1k2k
2019年12月2022年2月2024年5月2026年7月
制品库Go Modulesgo get github.com/AllenDang/giu
README

giu

Build Status Go Reference Discord Shield

A rapid cross-platform GUI framework for Go based on Dear ImGui and the great Go binding cimgui-go.

Any contribution (features, widgets, tutorials, documents, etc...) is appreciated!

(This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If you are using giu, please consider reaching out.)

Businesses: support continued development and maintenance via invoiced technical support, maintenance, sponsoring contracts:

E-mail: allengnr@gmail.com

Individuals: support continued development and maintenance here.

Documentation

For documentation refer to our wiki, examples, GoDoc, or just take a look at comments in code.

Supported Platforms

giu is built upon GLFW v3.3, so ideally giu could support all platforms that GLFW v3.3 supports. It is also restricted by cimgui-go (which at the moment builds only for linux, windows and mac).

  • Windows (Windows 10 x64 and Windows 11 x64)
  • macOS (macOS v10.15 and macOS Big Sur)
  • Linux (thanks remeh for testing it)
  • Raspberry Pi 3B (thanks sndvaps for testing it)

[!note] Because giu relays on C++ code, you need to have C/C++ compiler set up.

Features

Compared to other Dear ImGui golang bindings, giu has the following features:

  • Small executable file size (<3MB after UPX compression for the example/helloworld demo).
  • Live-updating during the resizing of the OS window (implemented on GLFW 3.3 and OpenGL 3.2).
  • Support for displaying various languages without any font setting. Giu will rebuild font atlas incrementally according to texts in UI between frames.
  • Redraws only when user event occurs. Costs only 0.5% CPU usage with 60FPS.
  • Declarative UI (see examples for more details).
  • DPI awareness (auto scaling font and UI to adapt to high DPI monitors).
  • Drop in usage; no need to implement render and platform.
  • OS clipboard support.

Screenshot

Screenshot1

Screenshot2

Hello world

package main

import (
        "fmt"

        g "github.com/AllenDang/giu"
)

func onClickMe() {
        fmt.Println("Hello world!")
}

func onImSoCute() {
        fmt.Println("Im sooooooo cute!!")
}

func loop() {
        g.SingleWindow().Layout(
                g.Label("Hello world from giu"),
                g.Row(
                        g.Button("Click Me").OnClick(onClickMe),
                        g.Button("I'm so cute").OnClick(onImSoCute),
                ),
        )
}

func main() {
        wnd := g.NewMasterWindow("Hello world", 400, 200, g.MasterWindowFlagsNotResizable)
        wnd.Run(loop)
}

Here is the result:

Helloworld

Quick introduction

What is immediate mode GUI?

Immediate mode GUI system means the UI control doesn't retain its state and value. For example, calling giu.InputText(&str) will display a input text box on screen, and the user entered value will be stored in &str. Input text box doesn't know anything about it.

And the loop method in the Hello world example is in charge of drawing all widgets based on the parameters passed into them. This method will be invoked 30 times per second to reflect interactive states (like clicked, hovered, value-changed, etc.). It will be the place you define the UI structure.

The layout and sizing system

By default, any widget placed inside a container's Layout will be placed vertically.

To create a row of widgets (i.e. place widgets one by one horizontally), use the Row() method. For example giu.Row(Label(...), Button(...)) will create a Label next to a Button.

To create a column of widgets (i.e. place widgets one by one vertically) inside a row, use the Column() method.

Any widget that has a Size() method, can set its size explicitly. Note that you can pass a negative value to Size(), which will fill the remaining width/height value. For example, InputText(...).Size(giu.Auto) will create an input text box with the longest width that its container has left.

Containers

MasterWindow

A MasterWindow means the platform native window implemented by the OS. All subwindows and widgets will be placed inside it.

Window

A Window is a container with a title bar, and can be collapsed. SingleWindow is a special kind of window that will occupy all the available space of MasterWindow.

Child

A Child is like a panel in other GUI frameworks - it can have a background color and border.

Widgets

Check examples/widgets for all kinds of widgets.

Install

The backend of giu depends on OpenGL 3.3, make sure your environment supports it (as far as I know, some Virtual Machines like VirtualBox doesn't support it).

MacOS

xcode-select --install
go get github.com/AllenDang/giu

Windows

  1. Install mingw download here. Thanks @alchem1ster!
  2. Add the binaries folder of mingw to the path (usually is \mingw64\bin).
  3. go get github.com/AllenDang/giu in your project

Linux

First you need to install the required dependencies:

Debian/Ubuntu
sudo apt install libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libglx-dev libgl1-mesa-dev libxxf86vm-dev
Fedora/Red Hat/CentOS
sudo dnf install libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel libXi-devel libGL-devel libXxf86vm-devel
Arch Linux
sudo pacman -Sy glfw

you may also need to install C/C++ compiler (like g++) if it isn't already installed. Follow go compiler prompts.

Then, a simple go build will work.

Cross-compiling is a bit more complicated. Let's say that you want to build for arm64. This is what you would need to do:

sudo dpkg --add-architecture arm64
sudo apt update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
    libx11-dev:arm64 libxcursor-dev:arm64 libxrandr-dev:arm64 libxinerama-dev:arm64 libxi-dev:arm64 libglx-dev:arm64 libgl1-mesa-dev:arm64 libxxf86vm-dev:arm64
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ HOST=aarch64-linux-gnu go build -v

Deploying

MacOS -> MacOS

go build -ldflags "-s -w" .

Windows -> Windows

go build -ldflags "-s -w -H=windowsgui -extldflags=-static" .

MacOS/Linux -> Windows

Install mingw-64.

[!warning] You must use mingw32-w64 version v12.0.0 or later!

Otherwise you'll get

undefined reference to `__imp_isblank'
Explaination

From https://www.mingw-w64.org/changelog/:

Important: UCRT is now the default CRT runtime instead of MSVCRT, check the mingw-w64-doc/howto-build/ucrt-vs-msvcrt.txt document for details. Both header set and CRT must be configured and built with the same settings consistently for proper functionality. Switching runtimes requires all libraries to be rebuilt, including GCC.

Currently, it is tested, that the following linux distros ship with the right version:

  • Fedora (>= 42)
  • Arch Linux

Generally if you have gcc 14+, it should work fine.

More details and discussion in #992.

Mac
brew install mingw-w64
Fedora/RHEL/CentOS
sudo dnf install mingw64-gcc mingw64-gcc-c++ mingw64-winpthreads-static
Arch Linux
pacman -Sy mingw-w64-gcc
  1. Prepare and embed the application icon into the executable and build.
cat > YourExeName.rc << EOL
id ICON "./res/app_win.ico"
GLFW_ICON ICON "./res/app_win.ico"
EOL

x86_64-w64-mingw32-windres YourExeName.rc -O coff -o YourExeName.syso
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ HOST=x86_64-w64-mingw32 go build -ldflags "-s -w -H=windowsgui -extldflags=-static" -p 4 -v -o YourExeName.exe

rm YourExeName.syso
rm YourExeName.rc

Contribution

All kinds of pull requests (document, demo, screenshots, code, etc.) are more than welcome!

Star History

Star History Chart

相关仓库
flutter/flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond

DartBSD 3-Clause "New" or "Revised" Licensemobileandroid
flutter.dev
177.9k30.7k
react/react-native

A framework for building native applications using React

C++MIT Licenseandroidapp-framework
reactnative.dev
126.2k25.2k
facebook/react-native

A framework for building native applications using React

C++MIT Licenseandroidapp-framework
reactnative.dev
120.9k24.5k
ChatGPTNextWeb/NextChat

✨ Light and Fast AI Assistant. Support: Web | iOS | MacOS | Android | Linux | Windows

TypeScriptnpmMIT Licensechatgptnextjs
nextchat.club
88.5k59.4k
ChatGPTNextWeb/ChatGPT-Next-Web

A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini/Claude LLM 应用。

TypeScriptnpmchatgptnextjs
nextchat.dev/chat
78.5k60k
Solido/awesome-flutter

An awesome list that curates the best Flutter libraries, tools, tutorials, articles and more.

Dartflutterawesome-list
60.7k6.9k
dcloudio/uni-app

A cross-platform framework using Vue.js

Objective-CApache License 2.0uni-appvue
uniapp.dcloud.io
41.6k3.7k
vim/vim

The official Vim repository

Vim ScriptVim Licensevimc
vim.org
40.7k6.1k
sxyazi/yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.

Rustcrates.ioMIT Licenseasyncioconcurrency
yazi-rs.github.io
40.6k945
spacedriveapp/spacedrive

Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.

Rustcrates.ioOtherfile-managerdistributed-systems
spacedrive.com
38.6k1.3k
balena-io/etcher

Flash OS images to SD cards & USB drives, safely and easily.

TypeScriptnpmApache License 2.0etchersd-cards
etcher.io
34k2.4k
DevToys-app/DevToys

A Swiss Army knife for developers.

C#MIT Licensesyntax-highlightingdeveloper-tools
devtoys.app
31.8k1.8k