Refactored the menu system
This commit is contained in:
12 files changed
+474
-344
No files matched your search
+17
-3
@@ -12,6 +12,7 @@ import (
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
// IconFont is the Nerd Font patched Hack Mono Regular font at 16pt.
|
||||
var IconFont = HackMono.WithPointSize(16)
|
||||
|
||||
func init() {
|
||||
@@ -23,17 +24,30 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// Icon draws an icon from the built-in Nerd Font set.
|
||||
//
|
||||
// Use https://www.nerdfonts.com/cheat-sheet to find what icons to use;
|
||||
// you do not have to supply the "nf-" prefix for the name.
|
||||
func Icon(dst draw.Image, p image.Point, c color.Color, name string) {
|
||||
if strings.HasPrefix(name, "nf-") {
|
||||
name = name[3:]
|
||||
}
|
||||
|
||||
icon := nameIcon[strings.ToLower(name)]
|
||||
logrus.Debugf("map font %q -> %q", name, icon)
|
||||
IconP(dst, p, c, icon)
|
||||
if icon == 0 {
|
||||
logrus.Debugf("icon %q not found", name)
|
||||
IconP(dst, p, c, nameIcon["md_image_broken"])
|
||||
} else {
|
||||
IconP(dst, p, c, icon)
|
||||
}
|
||||
}
|
||||
|
||||
// IconP draws an icon from the built-in Nerd Font set using code points.
|
||||
func IconP(dst draw.Image, p image.Point, c color.Color, icon rune) {
|
||||
IconFont.Draw(dst, p, image.NewUniform(c), string(icon))
|
||||
}
|
||||
|
||||
// Maps codepoints to names used in Nerd Font.
|
||||
// maps codepoints to names used in Nerd Font.
|
||||
var nameIcon = map[string]rune{}
|
||||
var iconName = map[rune]string{
|
||||
'': "cod_add",
|
||||
|
||||
Reference in new issue
Block a user