Convert Figma logo to code with AI

andlabs logoui

Platform-native GUI library for Go.

8,335
651
8,335
124

Top Related Projects

24,481

Cross platform GUI toolkit in Go inspired by Material Design

10,376

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly

2,197

Cross-platform Go/Golang GUI library.

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

7,997

Build cross-platform modern desktop apps in Go + HTML5

Quick Overview

andlabs/ui is a cross-platform GUI toolkit for Go, providing native user interface controls on Windows, macOS, and Linux. It aims to offer a simple and consistent API for creating native-looking applications across different operating systems.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux)
  • Native look and feel on each supported platform
  • Simple and straightforward API
  • Lightweight with minimal dependencies

Cons

  • Limited set of UI controls compared to more mature GUI frameworks
  • Less frequent updates and maintenance
  • Lack of advanced features like custom styling or theming
  • Limited community support and resources

Code Examples

  1. Creating a basic window with a button:
package main

import "github.com/andlabs/ui"

func main() {
    ui.Main(func() {
        window := ui.NewWindow("Hello", 200, 100, false)
        window.OnClosing(func(*ui.Window) bool {
            ui.Quit()
            return true
        })
        window.SetMargined(true)

        button := ui.NewButton("Click Me")
        button.OnClicked(func(*ui.Button) {
            ui.MsgBox(window, "Hello", "Button clicked!")
        })

        window.SetChild(button)
        window.Show()
    })
}
  1. Creating a form with input fields:
package main

import "github.com/andlabs/ui"

func main() {
    ui.Main(func() {
        window := ui.NewWindow("Form Example", 300, 200, false)
        window.OnClosing(func(*ui.Window) bool {
            ui.Quit()
            return true
        })
        window.SetMargined(true)

        form := ui.NewForm()
        form.SetPadded(true)
        
        nameEntry := ui.NewEntry()
        form.Append("Name:", nameEntry, false)
        
        ageEntry := ui.NewEntry()
        form.Append("Age:", ageEntry, false)

        window.SetChild(form)
        window.Show()
    })
}
  1. Creating a simple menu:
package main

import "github.com/andlabs/ui"

func main() {
    ui.Main(func() {
        window := ui.NewWindow("Menu Example", 300, 200, true)
        window.OnClosing(func(*ui.Window) bool {
            ui.Quit()
            return true
        })

        menu := ui.NewMenu("File")
        menu.AppendItem("Open")
        menu.AppendSeparator()
        menu.AppendQuitItem()

        window.Show()
    })
}

Getting Started

To use andlabs/ui in your Go project:

  1. Install the library:

    go get github.com/andlabs/ui
    
  2. Import the package in your Go file:

    import "github.com/andlabs/ui"
    
  3. Use the ui.Main() function as the entry point for your application:

    func main() {
        ui.Main(func() {
            // Your UI code here
        })
    }
    
  4. Build and run your application:

    go build
    ./your_app_name
    

Competitor Comparisons

24,481

Cross platform GUI toolkit in Go inspired by Material Design

Pros of Fyne

  • More active development and larger community
  • Cross-platform support for mobile (iOS and Android)
  • Rich set of widgets and layout options

Cons of Fyne

  • Larger binary size due to bundled dependencies
  • Steeper learning curve for developers new to Go

Code Comparison

ui:

button := ui.NewButton("Click Me")
button.OnClicked(func(*ui.Button) {
    ui.MsgBox(mainwin, "Information", "You clicked the button!")
})

Fyne:

button := widget.NewButton("Click Me", func() {
    dialog.ShowInformation("Information", "You clicked the button!", myWindow)
})

Summary

Fyne offers a more comprehensive and actively maintained solution for cross-platform GUI development in Go, including mobile support. It provides a rich set of widgets and layout options but comes with a larger binary size and a steeper learning curve. ui, on the other hand, is simpler and more lightweight but has limited features and platform support. The code comparison shows that both libraries have similar syntax for creating buttons and handling events, with Fyne using a more modern, closure-based approach for event handling.

10,376

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly

Pros of qt

  • More comprehensive and feature-rich GUI toolkit
  • Better cross-platform support, including mobile platforms
  • Larger community and ecosystem

Cons of qt

  • Steeper learning curve due to its complexity
  • Larger binary size and resource footprint
  • Requires C++ knowledge for advanced features

Code Comparison

ui:

window := ui.NewWindow("Hello", 200, 100, false)
button := ui.NewButton("Click Me")
window.SetChild(button)
window.OnClosing(func(*ui.Window) bool {
    ui.Quit()
    return true
})

qt:

app := widgets.NewQApplication(len(os.Args), os.Args)
window := widgets.NewQMainWindow(nil, 0)
button := widgets.NewQPushButton2("Click Me", nil)
window.SetCentralWidget(button)
window.SetFixedSize2(200, 100)
window.Show()
app.Exec()

Both libraries provide similar functionality for creating basic GUI applications, but qt offers more advanced features and customization options. ui focuses on simplicity and ease of use, while qt provides a more comprehensive toolkit at the cost of increased complexity.

2,197

Cross-platform Go/Golang GUI library.

Pros of govcl

  • Offers a wider range of UI components and controls
  • Provides better support for Windows-specific features
  • Allows for more detailed customization of UI elements

Cons of govcl

  • Less cross-platform compatibility compared to ui
  • Steeper learning curve due to more complex API
  • Larger dependency footprint

Code Comparison

ui:

window := ui.NewWindow("Hello", 200, 100, false)
button := ui.NewButton("Click Me")
window.SetChild(button)
window.OnClosing(func(*ui.Window) bool {
    ui.Quit()
    return true
})

govcl:

form := vcl.Application.CreateForm()
form.SetCaption("Hello")
form.SetWidth(200)
form.SetHeight(100)
button := vcl.NewButton(form)
button.SetParent(form)
button.SetCaption("Click Me")

Both libraries aim to provide GUI capabilities for Go applications, but they differ in their approach and feature set. ui focuses on simplicity and cross-platform compatibility, while govcl offers more extensive Windows-specific features and customization options. The code comparison demonstrates that ui has a more concise syntax, while govcl provides more granular control over UI elements. Developers should choose based on their specific requirements, target platforms, and desired level of customization.

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Pros of go-sciter

  • Rich set of UI controls and styling options using HTML/CSS
  • Supports multiple platforms (Windows, macOS, Linux) with native look and feel
  • Smaller executable size due to embedded rendering engine

Cons of go-sciter

  • Requires learning Sciter-specific markup and scripting
  • Less native integration with Go compared to pure Go solutions
  • Potential licensing concerns for commercial applications

Code Comparison

go-sciter example:

w, _ := sciter.CreateWindow(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE, nil)
w.LoadFile("hello.html")
w.SetTitle("Hello")
w.Show()
w.Run()

ui example:

window := ui.NewWindow("Hello", 200, 100, false)
button := ui.NewButton("Click Me")
window.SetChild(button)
window.OnClosing(func(*ui.Window) bool {
    ui.Quit()
    return true
})
ui.Main(window)

Summary

go-sciter offers a more feature-rich UI development experience with HTML/CSS styling, while ui provides a simpler, pure Go approach. go-sciter is better suited for complex UIs with custom styling, whereas ui is ideal for straightforward, native-looking applications. The choice between them depends on the project's requirements, desired look and feel, and the developer's preference for working with HTML/CSS versus pure Go code.

7,997

Build cross-platform modern desktop apps in Go + HTML5

Pros of Lorca

  • Uses web technologies (HTML, CSS, JavaScript) for UI, allowing for more flexible and familiar design
  • Lightweight and doesn't require CGo, making it easier to cross-compile
  • Supports two-way JavaScript bindings for seamless integration between Go and JavaScript

Cons of Lorca

  • Requires a Chrome/Chromium installation on the user's system
  • Limited to platforms where Chrome is available
  • May have larger memory footprint due to using a full browser engine

Code Comparison

Lorca:

ui, _ := lorca.New("", "", 480, 320)
defer ui.Close()
ui.Bind("add", func(a, b int) int { return a + b })
ui.Load("data:text/html,<html><body><h1>Hello World</h1></body></html>")
<-ui.Done()

UI:

window := ui.NewWindow("Hello", 200, 100, false)
button := ui.NewButton("Click Me")
window.SetChild(button)
window.OnClosing(func(*ui.Window) bool {
    ui.Quit()
    return true
})
ui.Main(window)

The Lorca example demonstrates its web-based approach and JavaScript binding, while the UI example shows its native widget-based design. Lorca offers more flexibility in UI design but requires Chrome, whereas UI provides a more native look and feel without external dependencies.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ui: platform-native GUI library for Go

This is a library that aims to provide simple GUI software development in Go. It is based on my libui, a simple cross-platform library that does the same thing, but written in C.

It runs on/requires:

  • Windows: cgo, Windows Vista SP2 with Platform Update and newer
  • Mac OS X: cgo, Mac OS X 10.8 and newer
  • other Unixes: cgo, GTK+ 3.10 and newer
    • Debian, Ubuntu, etc.: sudo apt-get install libgtk-3-dev
    • Red Hat/Fedora, etc.: sudo dnf install gtk3-devel

It also requires Go 1.8 or newer.

It currently aligns to libui's Alpha 4.1, with only a small handful of functions not available.

Status

Package ui is currently mid-alpha software. Much of what is currently present runs stabily enough for the examples and perhaps some small programs to work, but the stability is still a work-in-progress, much of what is already there is not feature-complete, some of it will be buggy on certain platforms, and there's a lot of stuff missing. The libui README has more information.

Installation

Once you have the dependencies installed, a simple

go get github.com/andlabs/ui/...

should suffice.

Documentation

The in-code documentation is sufficient to get started, but needs improvement.

Some simple example programs are in the examples directory. You can go build each of them individually.

Windows manifests

Package ui requires a manifest that specifies Common Controls v6 to run on Windows. It should at least also state as supported Windows Vista and Windows 7, though to avoid surprises with other packages (or with Go itself; see this issue) you should state compatibility with higher versions of Windows too.

The simplest option is provided as a subpackage winmanifest; you can simply import it without a name, and it'll set things up properly:

import _ "github.com/andlabs/ui/winmanifest"

You do not have to worry about importing this in non-Windows-only files; it does nothing on non-Windows platforms.

If you wish to use your own manifest instead, you can use the one in winmanifest as a template to see what's required and how. You'll need to specify the template in a .rc file and use windres in MinGW-w64 to generate a .syso file as follows:

windres -i resources.rc -o winmanifest_windows_GOARCH.syso -O coff

You may also be interested in the github.com/akavel/rsrc and github.com/josephspurrier/goversioninfo packages, which provide other Go-like options for embedding the manifest.

Note that if you choose to ship a manifest as a separate .exe.manifest file instead of embedding it in your binary, and you use Cygwin or MSYS2 as the source of your MinGW-w64, Cygwin and MSYS2 instruct gcc to embed a default manifest of its own if none is specified. This default will override your manifest file! See this issue for more details, including workaround instructions.

macOS program execution

If you run a macOS program binary directly from the command line, it will start in the background. This is intentional; see this for more details.