Replace unicode cut icon with PNG icon in StatusBar
- Load cut.png from embedded filesystem - drawStatusBar uses drawPng() for cut icon (16dp) - No other files modified
This commit is contained in:
parent
106e91832a
commit
0ac2941802
|
|
@ -1,6 +1,8 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"embed"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
|
|
@ -15,16 +17,35 @@ import (
|
||||||
"golang.org/x/image/math/fixed"
|
"golang.org/x/image/math/fixed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed icons/*.png
|
||||||
|
var iconFS embed.FS
|
||||||
|
|
||||||
// Renderer consumes a slice of elements and draws them.
|
// Renderer consumes a slice of elements and draws them.
|
||||||
type Renderer struct {
|
type Renderer struct {
|
||||||
theme Theme
|
theme Theme
|
||||||
shp *text.Shaper
|
shp *text.Shaper
|
||||||
scale float32 // pixels per DP, from State.Scale
|
scale float32 // pixels per DP, from State.Scale
|
||||||
|
icons map[string]image.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Renderer.
|
// New creates a new Renderer.
|
||||||
func New(th Theme, shp *text.Shaper) *Renderer {
|
func New(th Theme, shp *text.Shaper) *Renderer {
|
||||||
return &Renderer{theme: th, shp: shp, scale: 1.0}
|
r := &Renderer{theme: th, shp: shp, scale: 1.0, icons: make(map[string]image.Image)}
|
||||||
|
r.loadIcons()
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadIcons loads PNG icons from the embedded filesystem.
|
||||||
|
func (r *Renderer) loadIcons() {
|
||||||
|
data, err := iconFS.ReadFile("cut.png")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
img, _, err := image.Decode(bytes.NewReader(data))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.icons["cut"] = img
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetScale updates the renderer's scale factor from State.Scale.
|
// SetScale updates the renderer's scale factor from State.Scale.
|
||||||
|
|
@ -159,7 +180,8 @@ func (r *Renderer) drawStatusBar(gtx layout.Context, sb StatusBar, _ WindowConst
|
||||||
leftX := reg.X + Dp(8)
|
leftX := reg.X + Dp(8)
|
||||||
iconY := iconsLineY
|
iconY := iconsLineY
|
||||||
|
|
||||||
r.drawText(gtx, th.Shaper, "✂", r.theme.FontSize, leftX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
iconSize := Dp(16)
|
||||||
|
r.drawPng(gtx, r.icons["cut"], leftX, iconY, iconSize, iconSize, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
||||||
leftX += Dp(36)
|
leftX += Dp(36)
|
||||||
r.drawText(gtx, th.Shaper, "⎘", r.theme.FontSize, leftX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
r.drawText(gtx, th.Shaper, "⎘", r.theme.FontSize, leftX, iconY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
||||||
leftX += Dp(36)
|
leftX += Dp(36)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user