DEV Community

Proton: An industry standard Pure-Go GUI Library

The Problem with CGO in GUI Development

CGO is Go's mechanism for calling C code, and while powerful, it introduces significant challenges. Cross-compilation becomes a complex task, build times increase, and you inherit the memory safety concerns of C. For GUI applications, this often meant relying on bindings to libraries like GTK or Qt, which are large, complex, and not always pleasant to work with in a Go environment.

Proton sidesteps this entirely. By using a pure-Go rendering approach, it compiles to a single binary on any platform without the need for external C libraries or a C compiler during the build process. This alone is a major win for distribution and deployment.

Immediate-Mode GUI in Go

Proton adopts an immediate-mode GUI paradigm, which is refreshingly straightforward for Go developers. Unlike retained-mode frameworks where you maintain a persistent tree of widgets, immediate-mode interfaces are built from scratch every frame. This maps naturally to Go's procedural style and simplifies state management.

The core pattern is simple: your draw function runs every frame, and you call widget functions in the order you want them to appear. They stack vertically by default, giving you a clean, predictable layout model.

Getting Started is Minimal

The library's API is designed for rapid prototyping. The most basic application is just a few lines of code:

package main

import "github.com/CzaxStudio/proton"

func main() {
    a := proton.New("hello")
    a.Window("Hello", 400, 200, func(win proton.Context) {
        proton.H3(win, "Hello from Proton!")
    })
    a.Run()
}

This simplicity extends to installation. On macOS and Windows, it works out of the box. On Linux, you only need to install Wayland and Vulkan development packages, reflecting its modern backend choices.

State Management Without Boilerplate

A common challenge in immediate-mode UI is persisting state between frames. Proton handles this elegantly by encouraging you to store state in your own structs, using re-exported types from the library. This approach keeps your application logic clean and avoids the need for multiple imports.

type UI struct {
    btn    proton.Clickable
    name   proton.Editor
    checked proton.Bool
    choice proton.Enum
    vol    proton.Float
    scroll proton.Scrollable
}

The state types are lightweight handles that Proton uses to manage interactions like button clicks, text input, and slider values. You simply pass a pointer to your struct field to the corresponding widget function, and the library updates it as the user interacts.

A Comprehensive Widget Toolkit

Proton comes with a rich set of widgets that cover most common UI needs:

  • Elements: Labels (H1-H6, Body2, Caption), buttons (standard, outline, icon), and links.
  • Input Controls: Text inputs, text areas, checkboxes, toggles, radio buttons, sliders, number inputs, and select boxes.
  • Layout Tools: Rows, columns, grids, split panes (with resize handles), padding, and spacer elements for fine-tuned layout control.
  • Visual Components: Dividers, cards, badges, status dots, code blocks, and color swatches.
  • Feedback & Overlays: Alerts, toasts, tooltips, spinners, tabs, accordions, and context menus.

The layout system is particularly well-thought-out. While widgets stack vertically by default, you can easily create horizontal layouts, growable items that fill remaining space, and fixed-size elements. The split pane functionality is a nice touch for creating IDE-like interfaces.

Theming and Customization

Out of the box, Proton includes several built-in palettes including Dark, Nord, Rose Pine, and Catppuccin. Applying a theme is as simple as:

a.ApplyPalette(proton.DarkPalette)

For custom branding, you can define your own palette with colors and apply it. There is also a global font scale setting, making it easy to accommodate different display preferences.

Asynchronous Programming and Feedback

Modern applications need to handle background tasks without freezing the UI. Proton provides a simple Invalidate() method on the window context, allowing you to request a redraw from any goroutine after updating your application state. This pattern is clean and idiomatic Go:

go func() {
    result := fetchFromAPI()
    u.data = result
    win.Invalidate()
}()

User feedback is also well-supported with dismissable alerts and toast notifications that you can display for operations like saving or error conditions. Toasts are particularly convenient as they can be called from anywhere and will render on the next frame.

Keyboard Shortcuts and Accessibility

Keyboard shortcut support is built directly into the library. You can define global or context-specific shortcuts easily:

proton.OnKey(win, key.ModCtrl, "S", func() {
    save()
})

This makes it simple to add professional-grade keyboard navigation to your applications.

Examples and Documentation

The project includes several examples to get you started quickly:

  • hello: A minimal application demonstrating the basic structure.
  • todo: A classic to-do list application.
  • calculator: An interactive calculator showcasing button handling.
  • showcase: A comprehensive demonstration of layout and theming.
  • kitchen: A reference implementation that displays every available widget.

The documentation is well-organized and covers core topics such as text rendering, button handling, input controls, layout design, and theming.

The Road Ahead

Proton is under active development with a clear direction. The recent v0.8.0 release and consistent commit activity suggest a healthy project. The library already supports a wide range of widgets and layouts, making it suitable for many desktop applications. The community is growing, with early adopters providing feedback and contributing to the project. The MIT license makes it suitable for both open-source and commercial projects.

Who Should Consider Proton?

Proton is an excellent choice for Go developers who want to create desktop applications without the overhead of CGO. It is particularly well-suited for:

  • Internal Tools: Quickly building internal utilities that need a GUI.
  • Small/Medium-Sized to Large Applications: Projects where a full-featured GUI toolkit is beneficial but you want to avoid the complexity of web technologies or CGO bindings.
  • Cross-Platform Distribution: The pure-Go nature means compiling for Windows, macOS, and Linux is straightforward.

Get Proton

If you like it then please star the repo: https://github.com/CzaxStudio/proton

Or use it in your project using:

go get github.com/CzaxStudio/proton

Thanks for Reading

If you have been looking for a way to build cross-platform GUI applications in Go without the headaches of C interop, Proton is definitely worth exploring. The project's commitment to simplicity and its growing set of features make it a promising addition to the Go ecosystem.

Comments

No comments yet. Start the discussion.