Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335// Package theme is 100gex's look: the Barbican palette, drawn neo-brutalist.// Flat colour, 2dp ink borders, hard offset shadows with no blur, Fraunces// for display type and Noto Sans for the rest.package theme
import ( "image" "image/color"
"gioui.org/font" "gioui.org/layout" "gioui.org/op" "gioui.org/op/clip" "gioui.org/op/paint" "gioui.org/text" "gioui.org/unit" "gioui.org/widget" "gioui.org/widget/material")
// Barbican, light. The colours match the Helix, Ghostty, and Noctalia// themes of the same name.var ( White = rgb(0xFFFFFF) Ink = rgb(0x21152D) Muted = rgb(0x63536D) Purple = rgb(0x7028C5) Yellow = rgb(0xFFDC45) SoftYellow = rgb(0xFFE875) Lavender = rgb(0xDAB6FF) Hover = rgb(0xEBD9FF) Cream = rgb(0xF5ECCC) Red = rgb(0xB42335) Green = rgb(0x267348) Amber = rgb(0xA36B00) Blue = rgb(0x3552B8) Cyan = rgb(0x116B77))
// Terminal colours, for the server's terminals.const ( TerminalForeground = "21152D" TerminalBackground = "FFFFFF" TerminalCursor = "7028C5")
// TerminalPalette is the 16-colour ANSI palette.var TerminalPalette = []string{ "0=21152D", "1=B42335", "2=267348", "3=A36B00", "4=3552B8", "5=7028C5", "6=116B77", "7=F5ECCC", "8=63536D", "9=D83F51", "10=339964", "11=D69900", "12=5978E4", "13=9D55EB", "14=2999A3", "15=FFFFFF",}
func rgb(c uint32) color.NRGBA { return color.NRGBA{R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c), A: 0xff}}
// Measurements.const ( Border unit.Dp = 2 // every outline Shadow unit.Dp = 4 // the offset of a control's or pane's shadow ShadowLarge unit.Dp = 8 // the offset of something above the rest, such as the palette Gap unit.Dp = 12 AccentWide unit.Dp = 6 // the bar down the left of a highlighted box TitlebarHigh unit.Dp = 52 SidebarWide unit.Dp = 232)
// Typefaces. Each lists fallbacks, since Gio only falls back to fonts that// match a listed family.const ( UIFace font.Typeface = uiFamily + ", Go, sans-serif" DisplayFace font.Typeface = "Fraunces 144pt, Fraunces, serif" TerminalFace font.Typeface = "Iosevka Nerd Font, Iosevka, Go Mono, monospace, emoji")
// Theme holds the shaper and the material theme the widgets draw text with.type Theme struct { Shaper *text.Shaper Material *material.Theme}
// New returns a theme drawing text with shaper.func New(shaper *text.Shaper) *Theme { m := material.NewTheme() m.Shaper = shaper m.Face = UIFace m.Fg = Ink m.Bg = White m.ContrastBg = Purple m.ContrastFg = White m.TextSize = 14 return &Theme{Shaper: shaper, Material: m}}
// Label is text in the UI face.func (t *Theme) Label(size unit.Sp, txt string, c color.NRGBA, weight font.Weight) material.LabelStyle { l := material.Label(t.Material, size, txt) l.Color = c l.Font.Weight = weight l.MaxLines = 1 l.Truncator = "…" return l}
// Display is text in the display face, Fraunces.func (t *Theme) Display(size unit.Sp, txt string, c color.NRGBA) material.LabelStyle { l := t.Label(size, txt, c, font.Black) l.Font.Typeface = DisplayFace return l}
// Fill paints r.func Fill(gtx layout.Context, c color.NRGBA, r image.Rectangle) { paint.FillShape(gtx.Ops, c, clip.Rect(r).Op())}
// Outline draws a border w pixels wide just inside r.func Outline(gtx layout.Context, c color.NRGBA, r image.Rectangle, w int) { Fill(gtx, c, image.Rect(r.Min.X, r.Min.Y, r.Max.X, r.Min.Y+w)) Fill(gtx, c, image.Rect(r.Min.X, r.Max.Y-w, r.Max.X, r.Max.Y)) Fill(gtx, c, image.Rect(r.Min.X, r.Min.Y, r.Min.X+w, r.Max.Y)) Fill(gtx, c, image.Rect(r.Max.X-w, r.Min.Y, r.Max.X, r.Max.Y))}
// Card draws the neo-brutalist box at r: a hard shadow offset down and to// the right, a fill, and an ink border.func Card(gtx layout.Context, r image.Rectangle, fill color.NRGBA, shadow unit.Dp) { if s := gtx.Dp(shadow); s > 0 { Fill(gtx, Ink, r.Add(image.Pt(s, s))) } Fill(gtx, fill, r) Outline(gtx, Ink, r, gtx.Dp(Border))}
// Box lays out w on a card with padding, its shadow drawn outside its// size.type Box struct { Fill color.NRGBA Shadow unit.Dp Padding layout.Inset // Accent, if set, is a bar down the left side, as on a highlighted // panel. Accent color.NRGBA}
func (b Box) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions { m := op.Record(gtx.Ops) inset := b.Padding if b.Accent != (color.NRGBA{}) { inset.Left += AccentWide } dims := inset.Layout(gtx, w) call := m.Stop() r := image.Rectangle{Max: dims.Size} Card(gtx, r, b.Fill, b.Shadow) if b.Accent != (color.NRGBA{}) { Fill(gtx, b.Accent, image.Rect(0, 0, gtx.Dp(AccentWide), dims.Size.Y)) Outline(gtx, Ink, r, gtx.Dp(Border)) } call.Add(gtx.Ops) return dims}
// ButtonKind picks a button's colours.type ButtonKind int
const ( Plain ButtonKind = iota // white, ink text Primary // purple, white text)
// Button is a neo-brutalist button: pressing it pushes it into its shadow.type Button struct { Theme *Theme Clickable *widget.Clickable Label string Kind ButtonKind Size unit.Sp // Selected draws a Plain button as Primary, as for the active tab. Selected bool}
func (b Button) Layout(gtx layout.Context) layout.Dimensions { size := b.Size if size == 0 { size = 13 } fill, fg := White, Ink if b.Kind == Primary || b.Selected { fill, fg = Purple, White } else if b.Clickable.Hovered() { fill = Hover } shadow := gtx.Dp(Shadow) / 2 pressed := b.Clickable.Pressed() return b.Clickable.Layout(gtx, func(gtx layout.Context) layout.Dimensions { m := op.Record(gtx.Ops) l := b.Theme.Label(size, b.Label, fg, font.Bold) dims := layout.Inset{Top: 5, Bottom: 5, Left: 12, Right: 12}.Layout(gtx, l.Layout) call := m.Stop()
r := image.Rectangle{Max: dims.Size} offset := image.Point{} if pressed { offset = image.Pt(shadow, shadow) } else { Fill(gtx, Ink, r.Add(image.Pt(shadow, shadow))) } t := op.Offset(offset).Push(gtx.Ops) Fill(gtx, fill, r) Outline(gtx, Ink, r, gtx.Dp(Border)) call.Add(gtx.Ops) t.Pop() dims.Size = dims.Size.Add(image.Pt(shadow, shadow)) return dims })}
// Highlighted lays out display text with a yellow highlighter bar behind// its lower half, as on a heading.func Highlighted(gtx layout.Context, l material.LabelStyle) layout.Dimensions { return HighlightedIn(gtx, l, Yellow)}
// HighlightedIn is Highlighted with the bar in c. A zero c draws no bar,// but lays the text out the same, so that a bar coming and going doesn't// move it.func HighlightedIn(gtx layout.Context, l material.LabelStyle, c color.NRGBA) layout.Dimensions { gtx.Constraints.Min = image.Point{} // hug the text m := op.Record(gtx.Ops) dims := l.Layout(gtx) call := m.Stop() if c != (color.NRGBA{}) { h := dims.Size.Y Fill(gtx, c, image.Rect(0, h*11/20, dims.Size.X+gtx.Dp(2), h-gtx.Dp(2))) } call.Add(gtx.Ops) return dims}
// Tag is a small label in capitals on a bordered box, such as a pane's// ZOOMED.func Tag(gtx layout.Context, t *Theme, text string, fill, fg color.NRGBA) layout.Dimensions { gtx.Constraints.Min = image.Point{} return Box{Fill: fill, Padding: layout.Inset{Top: 1, Bottom: 1, Left: 5, Right: 5}}.Layout(gtx, t.Label(10, text, fg, font.Bold).Layout)}
// KeyCap draws a key's spelling in a small bordered box, as in menus.func KeyCap(gtx layout.Context, t *Theme, keys string) layout.Dimensions { return Box{Fill: Cream, Padding: layout.Inset{Top: 1, Bottom: 1, Left: 6, Right: 6}}.Layout(gtx, t.Label(11, keys, Ink, font.Bold).Layout)}
// Icon is a glyph drawn by IconButton.type Icon int
const ( IconSplitRight Icon = iota // a box divided down the middle IconSplitDown // a box divided across the middle IconFloat // a solid box lifted off an outlined one IconDock // an outlined box with its right half solid IconPlus // a plus sign IconSidebar // an outlined box with a solid bar down its left)
// IconButton is a small square Button showing an icon instead of a label,// such as those in a pane's header.type IconButton struct { Clickable *widget.Clickable Icon Icon}
// IconButtonSize is an IconButton's side, without its shadow.const IconButtonSize unit.Dp = 20
func (b IconButton) Layout(gtx layout.Context) layout.Dimensions { fill := White if b.Clickable.Hovered() { fill = Hover } shadow := gtx.Dp(Shadow) / 2 pressed := b.Clickable.Pressed() return b.Clickable.Layout(gtx, func(gtx layout.Context) layout.Dimensions { side := gtx.Dp(IconButtonSize) r := image.Rect(0, 0, side, side) offset := image.Point{} if pressed { offset = image.Pt(shadow, shadow) } else { Fill(gtx, Ink, r.Add(image.Pt(shadow, shadow))) } t := op.Offset(offset).Push(gtx.Ops) Fill(gtx, fill, r) Outline(gtx, Ink, r, gtx.Dp(Border)) drawIcon(gtx, b.Icon, side) t.Pop() return layout.Dimensions{Size: image.Pt(side+shadow, side+shadow)} })}
// drawIcon draws icon centred in a square of the given side.func drawIcon(gtx layout.Context, icon Icon, side int) { w, h := gtx.Dp(12), gtx.Dp(10) line := max(1, gtx.Dp(1.5)) o := image.Pt((side-w)/2, (side-h)/2) box := image.Rect(0, 0, w, h).Add(o) switch icon { case IconSplitRight: Outline(gtx, Ink, box, line) mid := box.Min.X + (w-line)/2 Fill(gtx, Ink, image.Rect(mid, box.Min.Y, mid+line, box.Max.Y)) case IconSplitDown: Outline(gtx, Ink, box, line) mid := box.Min.Y + (h-line)/2 Fill(gtx, Ink, image.Rect(box.Min.X, mid, box.Max.X, mid+line)) case IconFloat: back := image.Rect(0, gtx.Dp(3), gtx.Dp(8), h).Add(o) front := image.Rect(gtx.Dp(4), 0, w, gtx.Dp(6)).Add(o) Outline(gtx, Ink, back, line) Fill(gtx, Ink, front) case IconDock: Outline(gtx, Ink, box, line) Fill(gtx, Ink, image.Rect(box.Min.X+w/2, box.Min.Y, box.Max.X, box.Max.Y)) case IconPlus: arm, thick := gtx.Dp(10), max(2, gtx.Dp(2)) c := image.Pt(side/2, side/2) Fill(gtx, Ink, image.Rect(c.X-arm/2, c.Y-thick/2, c.X-arm/2+arm, c.Y-thick/2+thick)) Fill(gtx, Ink, image.Rect(c.X-thick/2, c.Y-arm/2, c.X-thick/2+thick, c.Y-arm/2+arm)) case IconSidebar: Outline(gtx, Ink, box, line) Fill(gtx, Ink, image.Rect(box.Min.X, box.Min.Y, box.Min.X+gtx.Dp(4), box.Max.Y)) }}