Skip to content

CzaxStudio/proton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proton

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

Currently under development for v0.2.5

It is highly unlikely that we will change the API. Just adding more features to the Proton API.

Go Report Card Mentioned in Awesome Go

Our First Stargazers

Thank you to the early adopters who supported Proton from the very beginning!


@VioGrafu(First Stargazer)

@bigwhite

@TanmayCzax

@aurax

@DemonK1

@pekim

@fbaube

@gorilacrocodille

@alanmsant2

Documentation

Example apps (made using Proton)

Note: I have created basic apps, you can create even better apps with Proton.

GUI demo Demo2

Logo

Proton

Getting started

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.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 system deps:

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

About

A framework(library) for building GUI applications in Go without any need of CGO.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages