proton

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 24 Imported by: 0

README

Proton

A GUI library for Go that doesn't make you want to switch to web dev.

Built on Gio. No C dependencies. Pure Go. Works on Linux, macOS, and Windows.

package main

import "github.com/CzaxStudio/proton"

type UI struct {
    name proton.Editor
    btn  proton.Clickable
}

func main() {
    u := &UI{}
    a := proton.New("my app")
    a.ApplyPalette(proton.NordPalette)
    a.Window("Hello", 480, 300, func(win *proton.Win) {
        proton.H3(win, "Hello from Proton!")
        proton.Gap(win, 8)
        proton.Input(win, &u.name, "Your name")
        proton.Gap(win, 8)
        if proton.Button(win, &u.btn, "Go") {
            println("Hello,", u.name.Text())
        }
    })
    a.Run()
}

Install

go get github.com/CzaxStudio/proton

Linux — three extra packages required:

sudo apt install libwayland-dev libxkbcommon-dev libvulkan-dev

macOS and Windows need nothing extra.


How it works

Your draw function runs every frame. Call widget functions in order — they stack vertically by default. State lives in your own struct using Proton's re-exported types, so you only ever need one import.

type UI struct {
    btn     proton.Clickable    // button
    name    proton.Editor       // text input
    checked proton.Bool         // checkbox / toggle
    choice  proton.Enum         // radio group
    vol     proton.Float        // slider
    scroll  proton.Scrollable   // list / scroll area
}

Widgets

Text

Label H1H6 Body2 Caption Text Muted ColoredText ErrorText SuccessText WarningText

Buttons

Button OutlineButton IconButton Tappable Link LinkSmall

Inputs

Input TextArea Checkbox Toggle RadioButton Slider ProgressBar NumberInput SelectBox

Lists

List HList Scroll TextView LogView

Layout

Row Column RowSpread RowEnd GrowRow GrowColumn GrowItem FixedItem FlexSpacer Split HSplit ResizeSplit ResizeHSplit Center ZStack Pad PadH PadV PadSides Gap Grid MinSize MaxWidth

Visual

Divider LabeledDivider Rect RoundRect Card HoverCard Badge StatusDot Image CodeBlock ShortcutHint ColorSwatch

Feedback

Toast Alert AlertDismissable Tooltip Spinner

Overlays & Dialogs

Overlay Tabs Accordion ContextMenu

Utilities

If OnKey FocusArea


Layout

Widgets stack vertically by default. Use Row or Column to group them differently.

// side by side
proton.Row(win,
    func(win *proton.Win) { proton.Label(win, "left") },
    func(win *proton.Win) { proton.Label(win, "right") },
)

// one child fills remaining space
proton.GrowRow(win,
    proton.FixedItem(win, func(win *proton.Win) { proton.Label(win, "Search:") }),
    proton.GrowItem(win, func(win *proton.Win) { proton.Input(win, &e, "") }),
    proton.FixedItem(win, func(win *proton.Win) { proton.Button(win, &b, "Go") }),
)

// split pane (draggable)
proton.ResizeSplit(win, &u.split, 0.35, leftFn, rightFn)

// padding
proton.Pad(win, 16, func(win *proton.Win) { ... })
proton.PadSides(win, 8, 16, 8, 16, func(win *proton.Win) { ... })

// blank gap
proton.Gap(win, 12)

Theming

a.ApplyPalette(proton.DarkPalette)
a.ApplyPalette(proton.NordPalette)
a.ApplyPalette(proton.RosePinePalette)
a.ApplyPalette(proton.CatppuccinPalette)

// custom
a.ApplyPalette(proton.Palette{
    Bg:        proton.RGB(0x1e1e2e),
    Fg:        proton.RGB(0xcdd6f4),
    Primary:   proton.RGB(0x89b4fa),
    PrimaryFg: proton.RGB(0x1e1e2e),
})

a.SetFontScale(1.1)

Alerts and Feedback

proton.Alert(win, proton.AlertInfo,    "Informational message.")
proton.Alert(win, proton.AlertSuccess, "Operation completed.")
proton.Alert(win, proton.AlertWarning, "Proceed with caution.")
proton.Alert(win, proton.AlertError,   "Something went wrong.")

// dismissable
if proton.AlertDismissable(win, &u.closeBtn, proton.AlertInfo, "Click × to close") {
    u.showAlert = false
}

// toast — call last in your draw function
u.toast.Show("Saved!", 2*time.Second)
proton.Toast(win, &u.toast)

Async updates

go func() {
    result := fetchFromAPI()
    u.data = result
    win.Invalidate() // ask for a redraw
}()

Keyboard shortcuts

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

Examples

go run ./examples/hello        # 7 lines, one window
go run ./examples/todo         # classic todo list
go run ./examples/calculator   # buttons and state
go run ./examples/showcase     # layout and theming demo
go run ./examples/kitchen      # every widget in one place

Docs

See the docs repo for detailed per-topic guides:

  • [Getting started]
  • [Text]
  • [Buttons]
  • [Inputs]
  • [Layout]
  • [Lists]
  • [Visuals]
  • [Theming]
  • [Advanced]
  • [Examples]

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllPalettes = []NamedPalette{
	{"Dark", DarkPalette},
	{"Nord", NordPalette},
	{"Rose Pine", RosePinePalette},
	{"Rose Pine Moon", RosePineMoonPalette},
	{"Rose Pine Dawn", RosePineDawnPalette},
	{"Catppuccin Mocha", CatppuccinPalette},
	{"Catppuccin Frappé", CatppuccinFrappePalette},
	{"Catppuccin Macchiato", CatppuccinMacchiatoPalette},
	{"Catppuccin Latte", CatppuccinLattePalette},
	{"Dracula", DraculaPalette},
	{"Gruvbox Dark", GruvboxDarkPalette},
	{"Gruvbox Light", GruvboxLightPalette},
	{"Gruvbox Material", GruvboxMaterialDarkPalette},
	{"Tokyo Night", TokyoNightPalette},
	{"Tokyo Night Storm", TokyoNightStormPalette},
	{"Tokyo Night Day", TokyoNightDayPalette},
	{"Monokai", MonokaiPalette},
	{"Solarized Dark", SolarizedDarkPalette},
	{"Solarized Light", SolarizedLightPalette},
	{"One Dark", OneDarkPalette},
	{"Material Dark", MaterialDarkPalette},
	{"Ayu Dark", AyuDarkPalette},
	{"Ayu Mirage", AyuMiragePalette},
	{"Ayu Light", AyuLightPalette},
	{"Everforest Dark", EverforestDarkPalette},
	{"Everforest Light", EverforestLightPalette},
	{"Kanagawa", KanagawaPalette},
	{"Vesper", VesperPalette},
	{"Night Owl", NightOwlPalette},
	{"Carbon", CarbonPalette},
	{"Midnight", MidnightPalette},
	{"Obsidian", ObsidianPalette},
	{"Hacker", HackerPalette},
	{"Cyberpunk", CyberpunkPalette},
	{"Light", LightPalette},
	{"Paper", PaperPalette},
	{"GitHub Light", GithubLightPalette},
	{"Nord Light", NordLightPalette},
	{"Fluent Light", FluentLightPalette},
	{"Oceanic Next", OceanicNextPalette},
	{"Iceberg", IcebergPalette},
	{"Synthwave", SynthwavePalette},
	{"Ole Dark", OleDarkPalette},
	{"Slack", SlackPalette},
	{"Terminal Green", TerminalGreenPalette},
	{"Terminal Amber", TerminalAmberPalette},
}

AllPalettes is a slice of all built-in palettes with their names. Useful for building a theme picker UI.

for _, p := range proton.AllPalettes {
    if proton.Button(win, &btns[i], p.Name) {
        a.ApplyPalette(p.Palette)
    }
}
View Source
var AyuDarkPalette = MakePalette(0x0d1017, 0xbfbdb6, 0xe6b450, 0x0d1017)

AyuDarkPalette — Ayu dark, clean and modern.

View Source
var AyuLightPalette = MakePalette(0xfafafa, 0x575f66, 0xff9940, 0xfafafa)

AyuLightPalette — Ayu light variant.

View Source
var AyuMiragePalette = MakePalette(0x1f2430, 0xcccac2, 0xffcc66, 0x1f2430)

AyuMiragePalette — Ayu mirage, the middle-ground variant.

View Source
var CarbonPalette = MakePalette(0x161616, 0xf4f4f4, 0x0f62fe, 0xffffff)

CarbonPalette — IBM Carbon Design dark.

View Source
var CatppuccinFrappePalette = MakePalette(0x303446, 0xc6d0f5, 0x8caaee, 0x303446)

CatppuccinFrappePalette — medium-dark Catppuccin variant.

View Source
var CatppuccinLattePalette = MakePalette(0xeff1f5, 0x4c4f69, 0x1e66f5, 0xffffff)

CatppuccinLattePalette — Catppuccin's lightest variant.

View Source
var CatppuccinMacchiatoPalette = MakePalette(0x24273a, 0xcad3f5, 0x8aadf4, 0x24273a)

CatppuccinMacchiatoPalette — slightly darker Catppuccin.

View Source
var CatppuccinPalette = MakePalette(0x1e1e2e, 0xcdd6f4, 0x89b4fa, 0x1e1e2e)
View Source
var CyberpunkPalette = MakePalette(0x1a0b0b, 0xff2a6d, 0xd1ff00, 0x000000)

CyberpunkPalette — neon pink on near-black, lime accent.

View Source
var DarkPalette = MakePalette(0x121212, 0xdcdcdc, 0x6464f0, 0xffffff)
View Source
var DraculaPalette = MakePalette(0x282a36, 0xf8f8f2, 0xbd93f9, 0x282a36)

DraculaPalette — the classic purple dark theme.

View Source
var EverforestDarkPalette = MakePalette(0x2d353b, 0xd3c6aa, 0xa7c080, 0x2d353b)

EverforestDarkPalette — muted green forest theme.

View Source
var EverforestLightPalette = MakePalette(0xfdf6e3, 0x5c6a72, 0x8da101, 0xfdf6e3)

EverforestLightPalette — soft green light theme.

View Source
var FluentLightPalette = MakePalette(0xffffff, 0x201f1e, 0x0078d4, 0xffffff)

FluentLightPalette — Microsoft Fluent design, light.

View Source
var GithubLightPalette = MakePalette(0xffffff, 0x24292f, 0x0969da, 0xffffff)

GithubLightPalette — GitHub's clean light theme.

View Source
var GruvboxDarkPalette = MakePalette(0x282828, 0xebdbb2, 0xd79921, 0x282828)

GruvboxDarkPalette — warm earthy tones.

View Source
var GruvboxLightPalette = MakePalette(0xfbf1c7, 0x3c3836, 0xd65d0e, 0xfbf1c7)

GruvboxLightPalette — same palette, light background.

View Source
var GruvboxMaterialDarkPalette = MakePalette(0x292828, 0xdfbf8e, 0xa9b665, 0x292828)

GruvboxMaterialDarkPalette — Gruvbox with softened colors.

View Source
var HackerPalette = MakePalette(0x000000, 0x00ff00, 0x008f11, 0x000000)

HackerPalette — black terminal, green text.

View Source
var IcebergPalette = MakePalette(0x161821, 0xc6c8d1, 0x84a0c6, 0x161821)

IcebergPalette — cold blue-grey.

View Source
var KanagawaPalette = MakePalette(0x1f1f28, 0xdcd7ba, 0x7e9cd8, 0x1f1f28)

KanagawaPalette — inspired by Hokusai's The Great Wave.

View Source
var LightPalette = MakePalette(0xfafafa, 0x1a1a1a, 0x5b5bd6, 0xffffff)

LightPalette — clean, neutral light theme.

View Source
var MaterialDarkPalette = MakePalette(0x121212, 0xe1e1e1, 0xbb86fc, 0x121212)

MaterialDarkPalette — Material Design dark.

View Source
var MidnightPalette = MakePalette(0x0f172a, 0xf8fafc, 0x38bdf8, 0x0f172a)

MidnightPalette — deep navy, cool blue accent.

View Source
var MonokaiPalette = MakePalette(0x272822, 0xf8f8f2, 0xa6e22e, 0x272822)

MonokaiPalette — the Sublime Text classic.

View Source
var NightOwlPalette = MakePalette(0x011627, 0xd6deeb, 0x82aaff, 0x011627)

NightOwlPalette — designed for night coding sessions.

View Source
var NordLightPalette = MakePalette(0xeceff4, 0x2e3440, 0x5e81ac, 0xeceff4)

NordLightPalette — Nord's lighter, warmer variant.

View Source
var NordPalette = MakePalette(0x2e3440, 0xd8dee9, 0x88c0d0, 0x2e3440)
View Source
var ObsidianPalette = MakePalette(0x293134, 0xe0e2db, 0x93c763, 0x293134)

ObsidianPalette — dark green tinted, editor-inspired.

View Source
var OceanicNextPalette = MakePalette(0x1b2b34, 0xd8dee9, 0x6699cc, 0x1b2b34)

OceanicNextPalette — cool ocean blues.

View Source
var OleDarkPalette = MakePalette(0x1c1917, 0xe7e5e4, 0xf97316, 0x1c1917)

OleDarkPalette — warm brown-dark, like old paper under lamplight.

View Source
var OneDarkPalette = MakePalette(0x282c34, 0xabb2bf, 0x61afef, 0x282c34)

OneDarkPalette — Atom's One Dark, ported everywhere.

View Source
var PaperPalette = MakePalette(0xf5f0e8, 0x2c2416, 0x8b4513, 0xf5f0e8)

PaperPalette — warm off-white, ink-like text. Easy on the eyes.

View Source
var RosePineDawnPalette = MakePalette(0xfaf4ed, 0x575279, 0xb4637a, 0xfaf4ed)

RosePineDawnPalette — the light variant of Rose Pine.

View Source
var RosePineMoonPalette = MakePalette(0x232136, 0xe0def4, 0xc4a7e7, 0x232136)

RosePineMoonPalette — Rose Pine's dark moon variant.

View Source
var RosePinePalette = MakePalette(0x191724, 0xe0def4, 0xc4a7e7, 0x191724)
View Source
var SlackPalette = MakePalette(0x3f0e40, 0xffffff, 0xe8a723, 0x3f0e40)

SlackPalette — Slack's sidebar dark palette.

View Source
var SolarizedDarkPalette = MakePalette(0x002b36, 0x839496, 0x268bd2, 0x002b36)

SolarizedDarkPalette — the original tinted dark theme.

View Source
var SolarizedLightPalette = MakePalette(0xfdf6e3, 0x657b83, 0x268bd2, 0xfdf6e3)

SolarizedLightPalette — warm cream, the light sibling of SolarizedDark.

View Source
var SynthwavePalette = MakePalette(0x262335, 0xffffff, 0xf92aad, 0x262335)

SynthwavePalette — 80s retro neon.

View Source
var TerminalAmberPalette = MakePalette(0x0d0800, 0xffb000, 0xff8c00, 0x0d0800)

TerminalAmberPalette — amber phosphor terminal.

View Source
var TerminalGreenPalette = MakePalette(0x001100, 0x33ff33, 0x00cc00, 0x001100)

TerminalGreenPalette — classic green phosphor terminal.

View Source
var TokyoNightDayPalette = MakePalette(0xe1e2e7, 0x3760bf, 0x2e7de9, 0xffffff)

TokyoNightDayPalette — Tokyo Night but light.

View Source
var TokyoNightPalette = MakePalette(0x1a1b26, 0xc0caf5, 0x7aa2f7, 0x1a1b26)

TokyoNightPalette — dark blue-purple, very popular in editors.

View Source
var TokyoNightStormPalette = MakePalette(0x24283b, 0xc0caf5, 0x7aa2f7, 0x24283b)

TokyoNightStormPalette — slightly lighter variant of Tokyo Night.

View Source
var VesperPalette = MakePalette(0x101010, 0xffffff, 0xffc799, 0x101010)

VesperPalette — minimal warm dark theme.

Functions

func Accordion added in v1.0.0

func Accordion(win *Win, state *AccordionState, btn *Clickable, title string, content func(*Win))

Accordion draws a collapsible section with a clickable header.

proton.Accordion(win, &u.sec1, &u.sec1btn, "Advanced", func(win *proton.Win) {
    proton.Label(win, "Hidden until expanded.")
})

func Alert added in v1.0.0

func Alert(win *Win, kind AlertKind, message string)

Alert draws a colored banner with a message — like an inline notification that stays visible until dismissed. Good for form errors, status messages, or anything that needs persistent visibility unlike a toast.

proton.Alert(win, proton.AlertError, "Invalid email address.")
proton.Alert(win, proton.AlertSuccess, "Your changes have been saved.")
proton.Alert(win, proton.AlertWarning, "This action cannot be undone.")
proton.Alert(win, proton.AlertInfo, "The app will restart to apply updates.")

func AlertDismissable added in v1.0.0

func AlertDismissable(win *Win, closeBtn *Clickable, kind AlertKind, message string) bool

AlertDismissable is like Alert but shows a close button. visible controls whether it's shown. Set it to false to dismiss. Returns true on the frame the close button is clicked.

type UI struct {
    showAlert bool
    alertDismiss proton.Clickable
}

if u.showAlert {
    if proton.AlertDismissable(win, &u.alertDismiss, proton.AlertInfo, "Click X to dismiss") {
        u.showAlert = false
    }
}

func Badge

func Badge(win *Win, bg, fg color.NRGBA, text string)

func Body2

func Body2(win *Win, text string)

func Button

func Button(win *Win, state *widget.Clickable, label string) bool

Button draws a filled button. Returns true if it was clicked. Click state is read from the previous frame's event processing — at 60fps this one-frame latency is imperceptible.

func Caption

func Caption(win *Win, text string)

func Card

func Card(win *Win, bg color.NRGBA, cornerDp, padDp float32, content func(*Win))

func Center

func Center(win *Win, fn func(*Win))

Center places a widget in the center of available space.

func Checkbox

func Checkbox(win *Win, state *widget.Bool, label string) bool

func CodeBlock added in v1.0.0

func CodeBlock(win *Win, code string)

CodeBlock draws a monospace text box styled like a code snippet. Good for showing commands, file paths, API keys, config values, etc.

proton.CodeBlock(win, "go get github.com/CzaxStudio/proton")

func ColorSwatch added in v1.0.0

func ColorSwatch(win *Win, btns []Clickable, colors []color.NRGBA, selected int, sizeDp float32) int

ColorSwatch draws a grid of color circles the user can click to select a color. colors is the palette to show. state is one Clickable per color. Returns the index of the selected color, or -1 if none selected yet.

palette := []color.NRGBA{
    proton.RGB(0xff6b6b),
    proton.RGB(0x4ecdc4),
    proton.RGB(0x45b7d1),
}
var swatches [3]proton.Clickable
var selectedColor int

i := proton.ColorSwatch(win, swatches[:], palette, selectedColor, 28)
if i >= 0 { selectedColor = i }

func ColoredText added in v1.0.0

func ColoredText(win *Win, text string, c color.NRGBA)

ColoredText draws a label with an explicit color without needing to build a full Text() call. Saves a line when you just want one color change.

proton.ColoredText(win, "Warning: this cannot be undone", proton.RGB(0xfbbf24))

func Column

func Column(win *Win, widgets ...func(*Win))

Column stacks widgets vertically.

func ContextMenu added in v1.0.0

func ContextMenu(win *Win, state *ContextMenuState, tag *FrameTag, items []ContextMenuItem, content func(*Win)) int

ContextMenu draws a right-click context menu over the target area. items defines the menu entries. The returned int is the index of the clicked item, or -1 if nothing was selected this frame.

items := []proton.ContextMenuItem{
    {Label: "Copy"},
    {Label: "Paste"},
    {Label: "Delete", Disabled: false},
}

i := proton.ContextMenu(win, &u.menu, &u.menuTag, items, func(win *proton.Win) {
    proton.Label(win, "right-click me")
})
if i >= 0 {
    fmt.Println("selected:", items[i].Label)
}

func Divider

func Divider(win *Win)

func ErrorText added in v1.0.0

func ErrorText(win *Win, text string)

ErrorText draws text in the theme's error/red color. Pass an empty string to draw nothing (useful for conditional errors).

proton.ErrorText(win, validationErr)

func FixedItem

func FixedItem(win *Win, fn func(*Win)) layout.FlexChild

FixedItem makes a child take only as much space as it needs. Use inside GrowRow/GrowColumn.

func FlexSpacer added in v1.0.0

func FlexSpacer() layout.FlexChild

FlexSpacer returns a flexible empty space that fills remaining room in a GrowRow or GrowColumn, pushing siblings to opposite edges.

proton.GrowRow(win,
    proton.FixedItem(win, func(win *proton.Win) { proton.Label(win, "left") }),
    proton.FlexSpacer(),
    proton.FixedItem(win, func(win *proton.Win) { proton.Label(win, "right") }),
)

func FocusArea

func FocusArea(win *Win, tag event.Tag, filter key.Filter, content func(*Win))

FocusArea registers a UI region as a key event receiver.

func Gap

func Gap(win *Win, dp float32)

Gap inserts a fixed blank space.

func Grid

func Grid(win *Win, cols int, gapDp float32, cells ...func(*Win))

Grid arranges widgets in a fixed-column grid.

proton.Grid(win, 3, 8,
    func(win *proton.Win) { proton.Label(win, "one") },
    func(win *proton.Win) { proton.Label(win, "two") },
    func(win *proton.Win) { proton.Label(win, "three") },
)

func GrowColumn

func GrowColumn(win *Win, children ...layout.FlexChild)

GrowColumn is a vertical column with explicit stretch control.

func GrowItem

func GrowItem(win *Win, fn func(*Win)) layout.FlexChild

GrowItem makes a child fill remaining space. Use inside GrowRow/GrowColumn.

func GrowRow

func GrowRow(win *Win, children ...layout.FlexChild)

GrowRow is a horizontal row with explicit stretch control. Use FixedItem for natural-size children, GrowItem for stretchy ones.

proton.GrowRow(win,
    proton.FixedItem(win, func(win *proton.Win) { proton.Label(win, "Name:") }),
    proton.GrowItem(win, func(win *proton.Win) { proton.Input(win, &e, "") }),
    proton.FixedItem(win, func(win *proton.Win) { proton.Button(win, &b, "Go") }),
)

func H1

func H1(win *Win, text string)

func H2

func H2(win *Win, text string)

func H3

func H3(win *Win, text string)

func H4

func H4(win *Win, text string)

func H5

func H5(win *Win, text string)

func H6

func H6(win *Win, text string)

func HList

func HList(win *Win, state *widget.List, length int, draw func(*Win, int))

func HSplit

func HSplit(win *Win, topFraction float32, top, bottom func(*Win))

HSplit splits vertically. topFraction is 0.0–1.0.

func HoverCard added in v1.0.0

func HoverCard(win *Win, state *Clickable, bg, hover color.NRGBA, cornerDp float32, content func(*Win)) bool

HoverCard wraps content in an area that highlights on hover. bg is the normal background, hover is the color when the mouse is over it. Returns true if clicked.

var row proton.Clickable
if proton.HoverCard(win, &row, proton.RGB(0x1e1e2e), proton.RGB(0x2a2a3e), 8, func(win *proton.Win) {
    proton.Label(win, "hover me")
}) {
    println("clicked")
}

func IconButton

func IconButton(win *Win, state *widget.Clickable, icon *widget.Icon, desc string) bool

func If added in v1.0.0

func If(win *Win, cond bool, content func(*Win))

If only draws content when cond is true. Saves you from wrapping everything in a Go if block when you just want to show or hide a single widget.

proton.If(win, user.IsAdmin, func(win *proton.Win) {
    proton.Button(win, &u.deleteBtn, "Delete All Users")
})

func Image

func Image(win *Win, img ImageOp, widthDp, heightDp float32)

func Input

func Input(win *Win, state *widget.Editor, hint string)

func Label

func Label(win *Win, text string)

func LabeledDivider added in v1.0.0

func LabeledDivider(win *Win, label string)

LabeledDivider draws a horizontal rule with an optional centered label. Pass an empty string for a plain divider.

proton.LabeledDivider(win, "Advanced Settings")
proton.LabeledDivider(win, "")
func Link(win *Win, state *Clickable, text string) bool

Link draws a clickable underlined text label styled like a hyperlink. Returns true if clicked. Handle the click yourself — open a browser, navigate in-app, whatever makes sense.

var lnk proton.Clickable
if proton.Link(win, &lnk, "View on GitHub") {
    openBrowser("https://github.com/CzaxStudio/proton")
}

func LinkSmall added in v1.0.0

func LinkSmall(win *Win, state *Clickable, text string) bool

LinkSmall is like Link but uses caption-sized text.

func List

func List(win *Win, state *widget.List, length int, draw func(*Win, int))

func LogView added in v1.0.0

func LogView(win *Win, state *widget.List, text string)

LogView is like TextView but new lines get appended at the bottom and it auto-scrolls to keep the latest output visible. Pass the full log string each frame.

type UI struct {
    log    string
    logScroll proton.Scrollable
}

u.log += "Build started...\n"
proton.LogView(win, &u.logScroll, u.log)

func MaxWidth

func MaxWidth(win *Win, widthDp float32, fn func(*Win))

func MinSize

func MinSize(win *Win, widthDp, heightDp float32, fn func(*Win))

func Muted added in v1.0.0

func Muted(win *Win, text string)

Muted draws body text in a dimmer color — good for secondary info, placeholders, descriptions that shouldn't compete with the main content.

proton.Label(win, "Alice Johnson")
proton.Muted(win, "alice@example.com")

func NumberInput added in v1.0.0

func NumberInput(win *Win, state *NumberState, min, max, step float64) float64

NumberInput draws a − value + stepper row. min/max clamp the value, step is the increment per click. Returns the current value.

qty := proton.NumberInput(win, &u.qty, 1, 99, 1)

func OnKey

func OnKey(win *Win, modifiers key.Modifiers, name key.Name, fn func())

OnKey fires fn when the given key+modifiers are pressed.

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

func OutlineButton

func OutlineButton(win *Win, state *widget.Clickable, label string) bool

func Overlay added in v1.0.0

func Overlay(win *Win, state *OverlayState, content func(*Win))

Overlay draws a dimmed backdrop with centered content on top of everything. Does nothing when state.Visible is false.

func Pad

func Pad(win *Win, dp float32, fn func(*Win))

Pad adds uniform padding around a widget.

func PadH

func PadH(win *Win, dp float32, fn func(*Win))

PadH adds left+right padding.

func PadSides

func PadSides(win *Win, top, right, bottom, left float32, fn func(*Win))

PadSides gives per-edge padding control.

func PadV

func PadV(win *Win, dp float32, fn func(*Win))

PadV adds top+bottom padding.

func ProgressBar

func ProgressBar(win *Win, progress float32)

func RGB

func RGB(hex uint32) color.NRGBA

func RGBA

func RGBA(r, g, b, a uint8) color.NRGBA

func RadioButton

func RadioButton(win *Win, group *widget.Enum, key, label string) bool

func Rect

func Rect(win *Win, c color.NRGBA, widthDp, heightDp float32)

func ResizeHSplit added in v1.0.0

func ResizeHSplit(win *Win, state *ResizeSplitState, defaultFraction float32, top, bottom func(*Win))

ResizeHSplit is the vertical version of ResizeSplit — top and bottom panes with a draggable horizontal divider.

func ResizeSplit added in v1.0.0

func ResizeSplit(win *Win, state *ResizeSplitState, defaultFraction float32, left, right func(*Win))

ResizeSplit is like Split but the user can drag the divider to resize the panes.

proton.ResizeSplit(win, &u.split, 0.35,
    func(win *proton.Win) { drawSidebar(win) },
    func(win *proton.Win) { drawContent(win) },
)

func RoundRect

func RoundRect(win *Win, c color.NRGBA, widthDp, heightDp, radiusDp float32)

func Row

func Row(win *Win, widgets ...func(*Win))

Row places widgets side by side.

func RowEnd

func RowEnd(win *Win, widgets ...func(*Win))

RowEnd pushes all children to the right edge.

func RowSpread

func RowSpread(win *Win, widgets ...func(*Win))

RowSpread is like Row but puts leftover space between children.

func Scroll

func Scroll(win *Win, state *widget.List, content func(*Win))

func SelectBox added in v1.0.0

func SelectBox(win *Win, state *SelectBoxState, options []string) int

SelectBox draws a dropdown selector. Returns the index of the selected option.

func ShortcutHint added in v1.0.0

func ShortcutHint(win *Win, keys string)

ShortcutHint draws a small keyboard shortcut badge, e.g. "Ctrl+S". Place it next to a button or menu label to show the hotkey.

proton.Row(win,
    func(win *proton.Win) { proton.Label(win, "Save") },
    func(win *proton.Win) { proton.Gap(win, 8) },
    func(win *proton.Win) { proton.ShortcutHint(win, "Ctrl+S") },
)

func Slider

func Slider(win *Win, state *widget.Float) float32

func Spinner added in v1.0.0

func Spinner(win *Win, state *SpinnerState, sizeDp float32)

Spinner draws an animated circular loading indicator. sizeDp is the diameter.

func Split

func Split(win *Win, leftFraction float32, left, right func(*Win))

Split gives left and right a fraction of the width. leftFraction is 0.0–1.0.

func StatusDot added in v1.0.0

func StatusDot(win *Win, c color.NRGBA, sizeDp float32)

StatusDot draws a small colored circle — useful for online/offline indicators, build status, connection state, etc.

proton.Row(win,
    func(win *proton.Win) { proton.StatusDot(win, proton.RGB(0x4ade80), 10) },
    func(win *proton.Win) { proton.Gap(win, 6) },
    func(win *proton.Win) { proton.Caption(win, "Connected") },
)

func Sub

func Sub(win *Win, fn func(*Win)) func(gtx layout.Context) layout.Dimensions

Sub returns a layout.Widget that runs fn with a fresh Win. Use when mixing Proton with raw Gio layout code.

func SuccessText added in v1.0.0

func SuccessText(win *Win, text string)

SuccessText draws text in green. Same empty-string shortcut as ErrorText.

proton.SuccessText(win, "Saved successfully!")

func Tabs added in v1.0.0

func Tabs(win *Win, labels []string, btns []Clickable, state *TabState, content func(*Win, int))

Tabs draws a horizontal tab bar. labels are the tab names, btns is one Clickable per tab. content is called with the selected tab index.

proton.Tabs(win, []string{"Files", "Settings"}, u.tabBtns[:], &u.tabs,
    func(win *proton.Win, i int) {
        switch i {
        case 0: drawFiles(win)
        case 1: drawSettings(win)
        }
    },
)

func Tappable

func Tappable(win *Win, state *widget.Clickable, content func(*Win)) bool

Tappable makes any content clickable. Returns true if clicked.

func Text

func Text(win *Win, s string, size float32, c color.NRGBA, bold bool)

func TextArea

func TextArea(win *Win, state *widget.Editor, hint string)

func TextView added in v1.0.0

func TextView(win *Win, state *widget.List, text string)

TextView draws a read-only scrollable text area — useful for log output, file previews, help text, or any large block of text.

var tv proton.Scrollable
proton.TextView(win, &tv, longText)

func ThemePicker added in v1.0.0

func ThemePicker(win *Win, state *ThemePickerState, a *App)

ThemePicker draws a scrollable list of all built-in palettes. Clicking one applies it immediately to the app. Place it in a settings panel or a dedicated theme window.

proton.ThemePicker(win, &u.picker, a)

func Toast

func Toast(win *Win, state *ToastState)

Toast draws a pill notification. Call last in your draw function.

func Toggle

func Toggle(win *Win, state *widget.Bool, label string) bool

func Tooltip

func Tooltip(win *Win, state *Clickable, tip string, content func(*Win))

Tooltip shows a label when the user hovers over content.

var hov proton.Clickable
proton.Tooltip(win, &hov, "Saves the file", func(win *proton.Win) {
    proton.Button(win, &saveBtn, "Save")
})

func WarningText added in v1.0.0

func WarningText(win *Win, text string)

WarningText draws text in yellow/amber.

func ZStack added in v1.0.0

func ZStack(win *Win, layers ...func(*Win))

ZStack draws multiple widgets layered on top of each other. The first is drawn at the bottom, the last is on top. All layers share the same available space.

proton.ZStack(win,
    func(win *proton.Win) { proton.Rect(win, proton.RGB(0x1e1e2e), 0, 120) },
    func(win *proton.Win) {
        proton.Center(win, func(win *proton.Win) { proton.Label(win, "on top") })
    },
)

Types

type AccordionState added in v1.0.0

type AccordionState struct {
	Open bool
}

AccordionState tracks whether a collapsible section is open or closed.

type UI struct {
    sec1    proton.AccordionState
    sec1btn proton.Clickable
}

type AlertKind added in v1.0.0

type AlertKind int

AlertKind controls the visual style of an alert banner.

const (
	AlertInfo    AlertKind = iota // blue — informational
	AlertSuccess                  // green — success
	AlertWarning                  // yellow — caution
	AlertError                    // red — something went wrong
)

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(name string) *App

func (*App) ApplyPalette

func (a *App) ApplyPalette(p Palette)

ApplyPalette pushes palette colors into the app theme. Call after New(), before Run().

func (*App) ColorCode added in v1.2.0

func (a *App) ColorCode(slot, code string)

ColorCode parses a CSS hex color string and sets the background color. Accepts "#rrggbb", "#rgb", "rrggbb", or "rgb" — with or without the #. This is the main entry point for the hex color code API.

Which slot to set is determined by the method you chain it from:

a.Theme().Bg("#1e1e2e").Fg("#cdd6f4").Primary("#89b4fa").Apply()

Or if you want to patch just one color on the current theme:

a.Theme().Primary("#ff0000").Apply()

func (*App) Notify added in v1.0.0

func (a *App) Notify(title, body string)

Notify is a stub for OS-level notifications. Gio's notification support lives in gioui.org/x/notify which has platform-specific setup requirements (Android manifest entries, macOS entitlements, etc.). Rather than pulling that dependency in by default, Proton exposes this no-op stub so your code compiles on all platforms.

To send real OS notifications, add gioui.org/x/notify to your go.mod and call its API directly from your app code.

// go get gioui.org/x/notify
// then in your app:
manager, _ := notify.NewManager()
manager.CreateNotification("Title", "Body")

func (*App) Run

func (a *App) Run()

func (*App) SetFontScale

func (a *App) SetFontScale(scale float32)

SetFontScale multiplies the base text size. 1.0 is the default.

func (*App) Theme

func (a *App) Theme() *material.Theme

func (*App) ThemeBuilder added in v1.2.0

func (a *App) ThemeBuilder() *ThemeBuilder

ThemeBuilder returns a builder pre-loaded with the current palette colors.

func (*App) Window

func (a *App) Window(title string, width, height int, draw func(*Win))

func (*App) WindowEx

func (a *App) WindowEx(title string, width, height int, opts []app.Option, draw func(*Win))

type Bool

type Bool = widget.Bool

Bool holds the checked state of a checkbox.

type Clickable

type Clickable = widget.Clickable

Clickable tracks clicks on a button or tappable area.

type ContextMenuItem added in v1.0.0

type ContextMenuItem struct {
	Label    string
	Disabled bool
}

ContextMenuItem is one entry in a context menu.

type ContextMenuState added in v1.0.0

type ContextMenuState struct {
	Open bool
	// contains filtered or unexported fields
}

ContextMenuState tracks whether the menu is open and the click positions.

type UI struct {
    menu     proton.ContextMenuState
    menuTag  proton.FrameTag
}

type Drag

type Drag = widget.Draggable

Drag tracks drag gesture state.

type Editor

type Editor = widget.Editor

Editor holds state for a text input or textarea.

type Enum

type Enum = widget.Enum

Enum holds the selected key in a radio group.

type Float

type Float = widget.Float

Float holds a slider value 0.0–1.0.

type FrameTag

type FrameTag struct{}

FrameTag is a stable pointer for use as a Gio event tag.

type ImageOp

type ImageOp struct {
	// contains filtered or unexported fields
}

func LoadImage

func LoadImage(path string) (ImageOp, error)

type NamedPalette added in v1.0.0

type NamedPalette struct {
	Name    string
	Palette Palette
}

NamedPalette pairs a palette with its display name.

type NumberState added in v1.0.0

type NumberState struct {
	Value float64
	// contains filtered or unexported fields
}

NumberState holds state for a numeric stepper.

type UI struct {
    qty proton.NumberState
}

type OverlayState added in v1.0.0

type OverlayState struct {
	Visible bool
}

OverlayState controls whether the overlay is visible.

type UI struct {
    modal    proton.OverlayState
    closeBtn proton.Clickable
}

if proton.Button(win, &u.openBtn, "Open") {
    u.modal.Show()
}
proton.Overlay(win, &u.modal, func(win *proton.Win) {
    proton.Card(win, proton.RGB(0x1e1e2e), 12, 24, func(win *proton.Win) {
        proton.H5(win, "Dialog Title")
        proton.Gap(win, 8)
        proton.Pad(win, 4, func(win *proton.Win) {
            if proton.Button(win, &u.closeBtn, "Close") { u.modal.Hide() }
        })
    })
})

func (*OverlayState) Hide added in v1.0.0

func (o *OverlayState) Hide()

Hide dismisses the overlay.

func (*OverlayState) Show added in v1.0.0

func (o *OverlayState) Show()

Show makes the overlay visible.

func (*OverlayState) Toggle added in v1.0.0

func (o *OverlayState) Toggle()

Toggle flips the overlay visibility.

type Palette

type Palette struct {
	Bg        color.NRGBA // window background
	Fg        color.NRGBA // text and icons
	Primary   color.NRGBA // buttons, sliders, accents
	PrimaryFg color.NRGBA // text drawn on primary elements
}

Palette holds the four colors that define an app's visual style.

func MakePalette added in v1.0.0

func MakePalette(bg, fg, primary, primaryFg uint32) Palette

MakePalette builds a Palette from four hex values. Saves typing color.NRGBA{} structs by hand.

a.ApplyPalette(proton.MakePalette(0x1e1e2e, 0xcdd6f4, 0x89b4fa, 0x1e1e2e))

type ResizeSplitState added in v1.0.0

type ResizeSplitState struct {
	Fraction float32
	// contains filtered or unexported fields
}

ResizeSplitState tracks the drag position for a resizable split pane.

type UI struct {
    split proton.ResizeSplitState
}

type Scrollable

type Scrollable = widget.List

Scrollable tracks scroll position for List and HList.

type SelectBoxState added in v1.0.0

type SelectBoxState struct {
	Open     bool
	Selected int
	// contains filtered or unexported fields
}

SelectBoxState holds the open/closed state and per-item clickables.

type UI struct {
    lang proton.SelectBoxState
}

i := proton.SelectBox(win, &u.lang, []string{"Go", "Rust", "Zig"})

type SpinnerState added in v1.0.0

type SpinnerState struct {
	// contains filtered or unexported fields
}

SpinnerState tracks the animation start time.

type UI struct {
    spin proton.SpinnerState
}

proton.Spinner(win, &u.spin, 32)

type TabState added in v1.0.0

type TabState struct {
	Selected int
}

TabState tracks which tab is selected.

type UI struct {
    tabs    proton.TabState
    tabBtns [3]proton.Clickable
}

type ThemeBuilder added in v1.2.0

type ThemeBuilder struct {
	// contains filtered or unexported fields
}

Theme is a chainable builder for custom palettes using CSS hex color codes. Get one from a.Theme(), set the colors you want, then call Apply().

a.Theme().
    Bg("#1e1e2e").
    Fg("#cdd6f4").
    Primary("#89b4fa").
    PrimaryFg("#1e1e2e").
    Apply()

Or use ColorCode to patch a single slot on an existing palette:

a.ApplyPalette(proton.NordPalette)
a.Theme().Primary("#ff6b6b").Apply()  // override just the primary color

func (*ThemeBuilder) Apply added in v1.2.0

func (tb *ThemeBuilder) Apply()

Apply pushes the built palette into the app.

func (*ThemeBuilder) Bg added in v1.2.0

func (tb *ThemeBuilder) Bg(code string) *ThemeBuilder

Bg sets the background color from a hex code string. Accepts "#rrggbb", "rrggbb", "#rgb", or "rgb".

func (*ThemeBuilder) Fg added in v1.2.0

func (tb *ThemeBuilder) Fg(code string) *ThemeBuilder

Fg sets the foreground (text) color from a hex code string.

func (*ThemeBuilder) Palette added in v1.2.0

func (tb *ThemeBuilder) Palette() Palette

Palette returns the built Palette without applying it. Useful if you want to store it and apply it later.

func (*ThemeBuilder) Primary added in v1.2.0

func (tb *ThemeBuilder) Primary(code string) *ThemeBuilder

Primary sets the accent/button color from a hex code string.

func (*ThemeBuilder) PrimaryFg added in v1.2.0

func (tb *ThemeBuilder) PrimaryFg(code string) *ThemeBuilder

PrimaryFg sets the text-on-primary color from a hex code string.

type ThemePickerState added in v1.0.0

type ThemePickerState struct {
	// contains filtered or unexported fields
}

ThemePickerState tracks the picker's scroll and selection.

type UI struct {
    picker proton.ThemePickerState
}

proton.ThemePicker(win, &u.picker, a)

type ToastState

type ToastState struct {
	// contains filtered or unexported fields
}

ToastState holds notification state. Declare one in your UI struct.

u.toast.Show("Saved!", 2*time.Second)
proton.Toast(win, &u.toast)  // call last so it renders on top

func (*ToastState) Show

func (t *ToastState) Show(msg string, duration time.Duration)

type Win

type Win struct {
	// contains filtered or unexported fields
}

Win collects widget draw functions. They run inside Gio's layout engine so each gets a correctly scoped gtx.

func (*Win) Invalidate

func (w *Win) Invalidate()

func (*Win) Theme

func (w *Win) Theme() *material.Theme

Directories

Path Synopsis
cmd
Proton command
examples
Github command
calculator command
cybertool command
hello command
showcase command
test command
todo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL