Documentation
¶
Index ¶
- Variables
- func Accordion(win *Win, state *AccordionState, btn *Clickable, title string, ...)
- func Alert(win *Win, kind AlertKind, message string)
- func AlertDismissable(win *Win, closeBtn *Clickable, kind AlertKind, message string) bool
- func Badge(win *Win, bg, fg color.NRGBA, text string)
- func Body2(win *Win, text string)
- func Button(win *Win, state *widget.Clickable, label string) bool
- func Caption(win *Win, text string)
- func Card(win *Win, bg color.NRGBA, cornerDp, padDp float32, content func(*Win))
- func Center(win *Win, fn func(*Win))
- func Checkbox(win *Win, state *widget.Bool, label string) bool
- func CodeBlock(win *Win, code string)
- func ColorSwatch(win *Win, btns []Clickable, colors []color.NRGBA, selected int, sizeDp float32) int
- func ColoredText(win *Win, text string, c color.NRGBA)
- func Column(win *Win, widgets ...func(*Win))
- func ContextMenu(win *Win, state *ContextMenuState, tag *FrameTag, items []ContextMenuItem, ...) int
- func Divider(win *Win)
- func ErrorText(win *Win, text string)
- func FixedItem(win *Win, fn func(*Win)) layout.FlexChild
- func FlexSpacer() layout.FlexChild
- func FocusArea(win *Win, tag event.Tag, filter key.Filter, content func(*Win))
- func Gap(win *Win, dp float32)
- func Grid(win *Win, cols int, gapDp float32, cells ...func(*Win))
- func GrowColumn(win *Win, children ...layout.FlexChild)
- func GrowItem(win *Win, fn func(*Win)) layout.FlexChild
- func GrowRow(win *Win, children ...layout.FlexChild)
- func H1(win *Win, text string)
- func H2(win *Win, text string)
- func H3(win *Win, text string)
- func H4(win *Win, text string)
- func H5(win *Win, text string)
- func H6(win *Win, text string)
- func HList(win *Win, state *widget.List, length int, draw func(*Win, int))
- func HSplit(win *Win, topFraction float32, top, bottom func(*Win))
- func HoverCard(win *Win, state *Clickable, bg, hover color.NRGBA, cornerDp float32, ...) bool
- func IconButton(win *Win, state *widget.Clickable, icon *widget.Icon, desc string) bool
- func If(win *Win, cond bool, content func(*Win))
- func Image(win *Win, img ImageOp, widthDp, heightDp float32)
- func Input(win *Win, state *widget.Editor, hint string)
- func Label(win *Win, text string)
- func LabeledDivider(win *Win, label string)
- func Link(win *Win, state *Clickable, text string) bool
- func LinkSmall(win *Win, state *Clickable, text string) bool
- func List(win *Win, state *widget.List, length int, draw func(*Win, int))
- func LogView(win *Win, state *widget.List, text string)
- func MaxWidth(win *Win, widthDp float32, fn func(*Win))
- func MinSize(win *Win, widthDp, heightDp float32, fn func(*Win))
- func Muted(win *Win, text string)
- func NumberInput(win *Win, state *NumberState, min, max, step float64) float64
- func OnKey(win *Win, modifiers key.Modifiers, name key.Name, fn func())
- func OutlineButton(win *Win, state *widget.Clickable, label string) bool
- func Overlay(win *Win, state *OverlayState, content func(*Win))
- func Pad(win *Win, dp float32, fn func(*Win))
- func PadH(win *Win, dp float32, fn func(*Win))
- func PadSides(win *Win, top, right, bottom, left float32, fn func(*Win))
- func PadV(win *Win, dp float32, fn func(*Win))
- func ProgressBar(win *Win, progress float32)
- func RGB(hex uint32) color.NRGBA
- func RGBA(r, g, b, a uint8) color.NRGBA
- func RadioButton(win *Win, group *widget.Enum, key, label string) bool
- func Rect(win *Win, c color.NRGBA, widthDp, heightDp float32)
- func ResizeHSplit(win *Win, state *ResizeSplitState, defaultFraction float32, ...)
- func ResizeSplit(win *Win, state *ResizeSplitState, defaultFraction float32, ...)
- func RoundRect(win *Win, c color.NRGBA, widthDp, heightDp, radiusDp float32)
- func Row(win *Win, widgets ...func(*Win))
- func RowEnd(win *Win, widgets ...func(*Win))
- func RowSpread(win *Win, widgets ...func(*Win))
- func Scroll(win *Win, state *widget.List, content func(*Win))
- func SelectBox(win *Win, state *SelectBoxState, options []string) int
- func ShortcutHint(win *Win, keys string)
- func Slider(win *Win, state *widget.Float) float32
- func Spinner(win *Win, state *SpinnerState, sizeDp float32)
- func Split(win *Win, leftFraction float32, left, right func(*Win))
- func StatusDot(win *Win, c color.NRGBA, sizeDp float32)
- func Sub(win *Win, fn func(*Win)) func(gtx layout.Context) layout.Dimensions
- func SuccessText(win *Win, text string)
- func Tabs(win *Win, labels []string, btns []Clickable, state *TabState, ...)
- func Tappable(win *Win, state *widget.Clickable, content func(*Win)) bool
- func Text(win *Win, s string, size float32, c color.NRGBA, bold bool)
- func TextArea(win *Win, state *widget.Editor, hint string)
- func TextView(win *Win, state *widget.List, text string)
- func ThemePicker(win *Win, state *ThemePickerState, a *App)
- func Toast(win *Win, state *ToastState)
- func Toggle(win *Win, state *widget.Bool, label string) bool
- func Tooltip(win *Win, state *Clickable, tip string, content func(*Win))
- func WarningText(win *Win, text string)
- func ZStack(win *Win, layers ...func(*Win))
- type AccordionState
- type AlertKind
- type App
- func (a *App) ApplyPalette(p Palette)
- func (a *App) ColorCode(slot, code string)
- func (a *App) Notify(title, body string)
- func (a *App) Run()
- func (a *App) SetFontScale(scale float32)
- func (a *App) Theme() *material.Theme
- func (a *App) ThemeBuilder() *ThemeBuilder
- func (a *App) Window(title string, width, height int, draw func(*Win))
- func (a *App) WindowEx(title string, width, height int, opts []app.Option, draw func(*Win))
- type Bool
- type Clickable
- type ContextMenuItem
- type ContextMenuState
- type Drag
- type Editor
- type Enum
- type Float
- type FrameTag
- type ImageOp
- type NamedPalette
- type NumberState
- type OverlayState
- type Palette
- type ResizeSplitState
- type Scrollable
- type SelectBoxState
- type SpinnerState
- type TabState
- type ThemeBuilder
- func (tb *ThemeBuilder) Apply()
- func (tb *ThemeBuilder) Bg(code string) *ThemeBuilder
- func (tb *ThemeBuilder) Fg(code string) *ThemeBuilder
- func (tb *ThemeBuilder) Palette() Palette
- func (tb *ThemeBuilder) Primary(code string) *ThemeBuilder
- func (tb *ThemeBuilder) PrimaryFg(code string) *ThemeBuilder
- type ThemePickerState
- type ToastState
- type Win
Constants ¶
This section is empty.
Variables ¶
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)
}
}
var AyuDarkPalette = MakePalette(0x0d1017, 0xbfbdb6, 0xe6b450, 0x0d1017)
AyuDarkPalette — Ayu dark, clean and modern.
var AyuLightPalette = MakePalette(0xfafafa, 0x575f66, 0xff9940, 0xfafafa)
AyuLightPalette — Ayu light variant.
var AyuMiragePalette = MakePalette(0x1f2430, 0xcccac2, 0xffcc66, 0x1f2430)
AyuMiragePalette — Ayu mirage, the middle-ground variant.
var CarbonPalette = MakePalette(0x161616, 0xf4f4f4, 0x0f62fe, 0xffffff)
CarbonPalette — IBM Carbon Design dark.
var CatppuccinFrappePalette = MakePalette(0x303446, 0xc6d0f5, 0x8caaee, 0x303446)
CatppuccinFrappePalette — medium-dark Catppuccin variant.
var CatppuccinLattePalette = MakePalette(0xeff1f5, 0x4c4f69, 0x1e66f5, 0xffffff)
CatppuccinLattePalette — Catppuccin's lightest variant.
var CatppuccinMacchiatoPalette = MakePalette(0x24273a, 0xcad3f5, 0x8aadf4, 0x24273a)
CatppuccinMacchiatoPalette — slightly darker Catppuccin.
var CatppuccinPalette = MakePalette(0x1e1e2e, 0xcdd6f4, 0x89b4fa, 0x1e1e2e)
var CyberpunkPalette = MakePalette(0x1a0b0b, 0xff2a6d, 0xd1ff00, 0x000000)
CyberpunkPalette — neon pink on near-black, lime accent.
var DarkPalette = MakePalette(0x121212, 0xdcdcdc, 0x6464f0, 0xffffff)
var DraculaPalette = MakePalette(0x282a36, 0xf8f8f2, 0xbd93f9, 0x282a36)
DraculaPalette — the classic purple dark theme.
var EverforestDarkPalette = MakePalette(0x2d353b, 0xd3c6aa, 0xa7c080, 0x2d353b)
EverforestDarkPalette — muted green forest theme.
var EverforestLightPalette = MakePalette(0xfdf6e3, 0x5c6a72, 0x8da101, 0xfdf6e3)
EverforestLightPalette — soft green light theme.
var FluentLightPalette = MakePalette(0xffffff, 0x201f1e, 0x0078d4, 0xffffff)
FluentLightPalette — Microsoft Fluent design, light.
var GithubLightPalette = MakePalette(0xffffff, 0x24292f, 0x0969da, 0xffffff)
GithubLightPalette — GitHub's clean light theme.
var GruvboxDarkPalette = MakePalette(0x282828, 0xebdbb2, 0xd79921, 0x282828)
GruvboxDarkPalette — warm earthy tones.
var GruvboxLightPalette = MakePalette(0xfbf1c7, 0x3c3836, 0xd65d0e, 0xfbf1c7)
GruvboxLightPalette — same palette, light background.
var GruvboxMaterialDarkPalette = MakePalette(0x292828, 0xdfbf8e, 0xa9b665, 0x292828)
GruvboxMaterialDarkPalette — Gruvbox with softened colors.
var HackerPalette = MakePalette(0x000000, 0x00ff00, 0x008f11, 0x000000)
HackerPalette — black terminal, green text.
var IcebergPalette = MakePalette(0x161821, 0xc6c8d1, 0x84a0c6, 0x161821)
IcebergPalette — cold blue-grey.
var KanagawaPalette = MakePalette(0x1f1f28, 0xdcd7ba, 0x7e9cd8, 0x1f1f28)
KanagawaPalette — inspired by Hokusai's The Great Wave.
var LightPalette = MakePalette(0xfafafa, 0x1a1a1a, 0x5b5bd6, 0xffffff)
LightPalette — clean, neutral light theme.
var MaterialDarkPalette = MakePalette(0x121212, 0xe1e1e1, 0xbb86fc, 0x121212)
MaterialDarkPalette — Material Design dark.
var MidnightPalette = MakePalette(0x0f172a, 0xf8fafc, 0x38bdf8, 0x0f172a)
MidnightPalette — deep navy, cool blue accent.
var MonokaiPalette = MakePalette(0x272822, 0xf8f8f2, 0xa6e22e, 0x272822)
MonokaiPalette — the Sublime Text classic.
var NightOwlPalette = MakePalette(0x011627, 0xd6deeb, 0x82aaff, 0x011627)
NightOwlPalette — designed for night coding sessions.
var NordLightPalette = MakePalette(0xeceff4, 0x2e3440, 0x5e81ac, 0xeceff4)
NordLightPalette — Nord's lighter, warmer variant.
var NordPalette = MakePalette(0x2e3440, 0xd8dee9, 0x88c0d0, 0x2e3440)
var ObsidianPalette = MakePalette(0x293134, 0xe0e2db, 0x93c763, 0x293134)
ObsidianPalette — dark green tinted, editor-inspired.
var OceanicNextPalette = MakePalette(0x1b2b34, 0xd8dee9, 0x6699cc, 0x1b2b34)
OceanicNextPalette — cool ocean blues.
var OleDarkPalette = MakePalette(0x1c1917, 0xe7e5e4, 0xf97316, 0x1c1917)
OleDarkPalette — warm brown-dark, like old paper under lamplight.
var OneDarkPalette = MakePalette(0x282c34, 0xabb2bf, 0x61afef, 0x282c34)
OneDarkPalette — Atom's One Dark, ported everywhere.
var PaperPalette = MakePalette(0xf5f0e8, 0x2c2416, 0x8b4513, 0xf5f0e8)
PaperPalette — warm off-white, ink-like text. Easy on the eyes.
var RosePineDawnPalette = MakePalette(0xfaf4ed, 0x575279, 0xb4637a, 0xfaf4ed)
RosePineDawnPalette — the light variant of Rose Pine.
var RosePineMoonPalette = MakePalette(0x232136, 0xe0def4, 0xc4a7e7, 0x232136)
RosePineMoonPalette — Rose Pine's dark moon variant.
var RosePinePalette = MakePalette(0x191724, 0xe0def4, 0xc4a7e7, 0x191724)
var SlackPalette = MakePalette(0x3f0e40, 0xffffff, 0xe8a723, 0x3f0e40)
SlackPalette — Slack's sidebar dark palette.
var SolarizedDarkPalette = MakePalette(0x002b36, 0x839496, 0x268bd2, 0x002b36)
SolarizedDarkPalette — the original tinted dark theme.
var SolarizedLightPalette = MakePalette(0xfdf6e3, 0x657b83, 0x268bd2, 0xfdf6e3)
SolarizedLightPalette — warm cream, the light sibling of SolarizedDark.
var SynthwavePalette = MakePalette(0x262335, 0xffffff, 0xf92aad, 0x262335)
SynthwavePalette — 80s retro neon.
var TerminalAmberPalette = MakePalette(0x0d0800, 0xffb000, 0xff8c00, 0x0d0800)
TerminalAmberPalette — amber phosphor terminal.
var TerminalGreenPalette = MakePalette(0x001100, 0x33ff33, 0x00cc00, 0x001100)
TerminalGreenPalette — classic green phosphor terminal.
var TokyoNightDayPalette = MakePalette(0xe1e2e7, 0x3760bf, 0x2e7de9, 0xffffff)
TokyoNightDayPalette — Tokyo Night but light.
var TokyoNightPalette = MakePalette(0x1a1b26, 0xc0caf5, 0x7aa2f7, 0x1a1b26)
TokyoNightPalette — dark blue-purple, very popular in editors.
var TokyoNightStormPalette = MakePalette(0x24283b, 0xc0caf5, 0x7aa2f7, 0x24283b)
TokyoNightStormPalette — slightly lighter variant of Tokyo Night.
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
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
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 Button ¶
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 CodeBlock ¶ added in v1.0.0
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
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 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 ErrorText ¶ added in v1.0.0
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 ¶
FixedItem makes a child take only as much space as it needs. Use inside GrowRow/GrowColumn.
func FlexSpacer ¶ added in v1.0.0
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 Grid ¶
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 ¶
GrowColumn is a vertical column with explicit stretch control.
func GrowRow ¶
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 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 If ¶ added in v1.0.0
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 LabeledDivider ¶ added in v1.0.0
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 ¶ added in v1.0.0
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 LogView ¶ added in v1.0.0
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 Muted ¶ added in v1.0.0
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 ¶
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 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 ProgressBar ¶
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 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
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 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 StatusDot ¶ added in v1.0.0
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 ¶
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
SuccessText draws text in green. Same empty-string shortcut as ErrorText.
proton.SuccessText(win, "Saved successfully!")
func Tabs ¶ added in v1.0.0
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 TextView ¶ added in v1.0.0
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 Tooltip ¶
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
WarningText draws text in yellow/amber.
func ZStack ¶ added in v1.0.0
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.
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) ApplyPalette ¶
ApplyPalette pushes palette colors into the app theme. Call after New(), before Run().
func (*App) ColorCode ¶ added in v1.2.0
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
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) SetFontScale ¶
SetFontScale multiplies the base text size. 1.0 is the default.
func (*App) ThemeBuilder ¶ added in v1.2.0
func (a *App) ThemeBuilder() *ThemeBuilder
ThemeBuilder returns a builder pre-loaded with the current palette colors.
type ContextMenuItem ¶ added in v1.0.0
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 NamedPalette ¶ added in v1.0.0
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
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 ¶
Scrollable tracks scroll position for List and HList.
type SelectBoxState ¶ added in v1.0.0
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