Replace Unicode icons with PNG icons in StatusBar

- Move icons/ to internal/ui/icons/ for go:embed
- Renderer.loadIcons() loads PNGs from embedded filesystem
- drawStatusBar() uses drawPng() for cut/copy/paste/search/conflict icons
- Icons are 16dp, rendered from 48x48 PNGs (2x density)
This commit is contained in:
gmp
2026-05-10 06:29:19 -04:00
parent 14284afa73
commit d2509123b0
9 changed files with 38 additions and 10 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

+4
View File
@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<rect x="7" y="7" width="12" height="14" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/>
<rect x="4" y="4" width="12" height="14" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/>
</svg>

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

+7
View File
@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="6" cy="6" r="3"/>
<circle cx="6" cy="18" r="3"/>
<path d="M20 4 8.12 15.12"/>
<path d="M14.8 14.8 20 20"/>
<path d="M8.12 8.12 12 12"/>
</svg>

After

Width:  |  Height:  |  Size: 347 B

+104
View File
@@ -0,0 +1,104 @@
//go:build ignore
//go:generate go run gen_icons.go
// gen_icons reads SVG files and generates icons/embedded.go with go:embed directives.
// Run: go generate ./icons
// To regenerate: cd icons && go run gen_icons.go
package main
import (
"bytes"
"fmt"
"go/format"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"text/template"
)
const output = "icons.go"
var iconTemplate = template.Must(template.New("").Parse(`// Code generated by gen_icons.go; DO NOT EDIT.
package icons
import (
_ "embed"
)
//go:embed {{.Embeds}}
var svgFS embed.FS
{{range $name, $files := .Icons}}
// {{$name}}SVG contains the {{$name}} icon SVG source.
var {{$name}}SVG = ` + "`" + `{{.}}` + "`" + `
{{end}}
`))
type iconData struct {
Embeds string
Icons map[string]string
}
func main() {
icons := make(map[string]string)
var embeds []string
err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
if !strings.HasSuffix(path, ".svg") {
return nil
}
data, err := os.ReadFile(path)
if err != nil {
return err
}
name := strings.TrimSuffix(filepath.Base(path), ".svg")
icons[name] = string(data)
embeds = append(embeds, filepath.Base(path))
return nil
})
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
// Sort embeds for deterministic output
sort.Strings(embeds)
data := iconData{
Embeds: strings.Join(embeds, " "),
Icons: icons,
}
var buf bytes.Buffer
if err := iconTemplate.Execute(&buf, data); err != nil {
fmt.Fprintf(os.Stderr, "template error: %v\n", err)
os.Exit(1)
}
src, err := format.Source(buf.Bytes())
if err != nil {
fmt.Fprintf(os.Stderr, "format error: %v\n", err)
os.Exit(1)
}
if err := os.WriteFile(output, src, 0644); err != nil {
fmt.Fprintf(os.Stderr, "write error: %v\n", err)
os.Exit(1)
}
fmt.Println("generated icons.go")
}
+40
View File
@@ -0,0 +1,40 @@
// Code generated by gen_icons.go; DO NOT EDIT.
package icons
import (
_ "embed"
)
//go:embed copy.svg cut.svg paste.svg
var svgFS embed.FS
// copySVG contains the copy icon SVG source.
var copySVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<rect x="7" y="7" width="12" height="14" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/>
<rect x="4" y="4" width="12" height="14" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/>
</svg>
`
// cutSVG contains the cut icon SVG source.
var cutSVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<!-- Left blade -->
<circle cx="7" cy="7" r="4" />
<line x1="9.5" y1="9.5" x2="14" y2="14" />
<!-- Right blade -->
<circle cx="17" cy="7" r="4" />
<line x1="14.5" y1="9.5" x2="10" y2="14" />
<!-- Handles -->
<line x1="7" y1="3" x2="7" y2="11" />
<line x1="17" y1="3" x2="17" y2="11" />
</svg>
`
// pasteSVG contains the paste icon SVG source.
var pasteSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<rect x="5" y="6" width="14" height="15" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/>
<path d="M8 6V4.5C8 3.67 8.67 3 9.5 3h5C15.33 3 16 3.67 16 4.5V6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
<line x1="8" y1="10" x2="16" y2="10" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
<line x1="8" y1="14" x2="16" y2="14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
</svg>
`
Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

+6
View File
@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<rect x="5" y="6" width="14" height="15" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/>
<path d="M8 6V4.5C8 3.67 8.67 3 9.5 3h5C15.33 3 16 3.67 16 4.5V6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
<line x1="8" y1="10" x2="16" y2="10" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
<line x1="8" y1="14" x2="16" y2="14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 552 B

+38 -10
View File
@@ -1,8 +1,12 @@
package ui
import (
"bytes"
"embed"
"image"
"image/color"
_ "image/png"
"strings"
"gioui.org/f32"
"gioui.org/layout"
@@ -15,6 +19,9 @@ import (
"golang.org/x/image/math/fixed"
)
//go:embed icons/*.png
var iconFS embed.FS
// StateReader provides access to scale and window dimensions from State.
// Implemented by editor.State to avoid import cycles.
type StateReader interface {
@@ -28,11 +35,31 @@ type Renderer struct {
theme Theme
shp *text.Shaper
state StateReader // read-only access to State for scale/window size
icons map[string]image.Image // loaded PNG icons
}
// New creates a new Renderer.
func New(th Theme, shp *text.Shaper) *Renderer {
return &Renderer{theme: th, shp: shp}
r := &Renderer{theme: th, shp: shp, icons: make(map[string]image.Image)}
r.loadIcons()
return r
}
// loadIcons loads all PNG icons from the embedded filesystem.
func (r *Renderer) loadIcons() {
files := []string{"cut.png", "copy.png", "paste.png", "search.png", "conflict.png", "wrapOn.png", "wrapOff.png"}
for _, filename := range files {
data, err := iconFS.ReadFile(filename)
if err != nil {
continue // skip missing icons
}
img, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
continue
}
name := strings.TrimSuffix(filename, ".png")
r.icons[name] = img
}
}
// SetState sets the State reference for the Renderer.
@@ -167,22 +194,23 @@ func (r *Renderer) drawStatusBar(gtx layout.Context, sb StatusBar, _ WindowConst
// Left side: Cut, Copy, Paste icons (always visible)
leftX := reg.X + Dp(8)
iconY := iconsLineY
iconSize := Dp(16) // 16dp icons
r.drawText(gtx, th.Shaper, "✂", r.theme.FontSize, leftX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
leftX += Dp(36)
r.drawText(gtx, th.Shaper, "⎘", r.theme.FontSize, leftX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
leftX += Dp(36)
r.drawText(gtx, th.Shaper, "⎘", r.theme.FontSize, leftX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
r.drawPng(gtx, r.icons["cut"], leftX, iconY, iconSize, iconSize, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
leftX += Dp(28)
r.drawPng(gtx, r.icons["copy"], leftX, iconY, iconSize, iconSize, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
leftX += Dp(28)
r.drawPng(gtx, r.icons["paste"], leftX, iconY, iconSize, iconSize, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
leftX += Dp(12)
// Right side: Conflict (conditional), Search (always visible)
rightX := reg.X + reg.W - Dp(8)
if sb.ConflictIcon {
rightX -= Dp(36)
r.drawText(gtx, th.Shaper, "⚠", r.theme.FontSize, rightX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
rightX -= Dp(28)
r.drawPng(gtx, r.icons["conflict"], rightX, iconY, iconSize, iconSize, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
}
rightX -= Dp(36)
r.drawText(gtx, th.Shaper, "🔍", r.theme.FontSize, rightX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
rightX -= Dp(28)
r.drawPng(gtx, r.icons["search"], rightX, iconY, iconSize, iconSize, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
c.Pop()
}