Skip to content
/ giu Public
forked from AllenDang/giu

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

License

Notifications You must be signed in to change notification settings

ddisisto/giu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

giu

Join the chat at https://gitter.im/AllenDang-giu/community Go Report Card Build Status Godoc Card

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

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

Supported Platforms

giu is built upon GLFW v3.3, so ideally giu could support all platforms that GLFW v3.3 supports.

  • Windows (only tested on Windows 10 x64)
  • MacOS (only tested on MacOS v10.15)
  • Linux (thanks remeh to test it)
  • Raspberry Pi 3B (thanks sndvaps to test it)

Features

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

  • Small executable file size (<3MB after UPX compression for the example/helloworld demo).
  • Live-updating during the resizing of 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. Below is the list of languages currently supported:
    • macOS
    1. English
    2. Simplified Chinese
    3. Japanese
    4. Korean
    • Windows
    1. English
    2. Simplified Chinese
    3. Japanese
    • Kali Linux
    1. English
    • Need your help to add more language support by creating a PR or telling me the OS default font name for your language.
  • Redraws only when user event occurred. Costs only 0.5% CPU usage with 60FPS.
  • Declarative UI (see examples for more detail).
  • DPI awareness (auto scaling font and UI to adapt high DPI monitor).
  • 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, nil)
	wnd.Run(loop)
}

Here is result:

Helloworld

Quick intruduction

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("ID", &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 (aka 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 creata a column of widgets (aka place widgets one by one vertically) inside a row, use the Column() method.

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

Containers

MasterWindow

A MasterWindow means the platform native window implemented by 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 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 (so far as I known some Virtual Machines like VirualBox 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

Or, install TDM-GCC.

Linux

First you need to install required dependencies:

# apt install libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libglx-dev libgl1-mesa-dev libxxf86vm-dev

Then, a simple go build will work.

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

# dpkg --add-architecture arm64
# apt update
# 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

Build MacOS version on MacOS.

go build -ldflags "-s -w" .

Build Windows version on Windows.

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

Build Windows version on MacOS.

  1. Install mingw-64.
brew install mingw-w64
  1. Prepare and embed application icon to 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

Documentation

Check Wiki

Contribution

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

Projects using giu

PipeIt is a text transformation, conversion, cleansing and extraction tool.

PipeIt Demo

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%