Files
MyGolandRelease/internal/app/icons.go
T
zerorigin a80c0f886a MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲)
- 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表)
- 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记
- Git:状态着色、选择性暂存提交、pull/push、历史并排对比
- 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复
- 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈
- 设计文档与验证记录见 docs/plans/
2026-11-04 16:37:05 +08:00

108 lines
4.4 KiB
Go

package app
import (
"time"
"github.com/egoist/mygo/ui"
)
// 图标全部内嵌为 SVG,24 栅格自绘,不依赖任何字体字形。
//
// ui.Icon 会把图形画成文字颜色,所以 SVG 里的颜色只是占位:
// 需要实心的形状写 fill,线框形状保持 fill="none"。
var iconMarkup = map[string]string{
"folder": `<path d="M3 8a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>`,
"refresh": `<path d="M19.5 12a7.5 7.5 0 1 1-2.2-5.3"/><path d="M20 3.5V8h-4.5"/>`,
"collapse": `<path d="M8 5l4 4 4-4"/><path d="M8 19l4-4 4 4"/>`,
"expand": `<path d="M8 10l4-4 4 4"/><path d="M8 14l4 4 4-4"/>`,
"plus": `<path d="M12 5v14"/><path d="M5 12h14"/>`,
"outline": `<path d="M4 6h3"/><path d="M10 6h10"/><path d="M4 12h3"/><path d="M10 12h10"/><path d="M4 18h3"/><path d="M10 18h10"/>`,
"chevron": `<path d="M9.5 6.5l6 5.5-6 5.5"/>`,
// 靶心加十字准星:定位当前文件在树里的位置。
"locate": `<circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="1.8" fill="black"/><path d="M12 2.5v3"/><path d="M12 18.5v3"/><path d="M2.5 12h3"/><path d="M18.5 12h3"/>`,
"build": `<path d="M13.5 3.5l7 7-2.5 2.5-7-7z"/><path d="M11.5 9.5L4 17l2.5 2.5 7.5-7.5"/>`,
"run": `<path d="M8.5 5.5l10 6.5-10 6.5z" fill="black"/>`,
"test": `<path d="M9 3.5h6"/><path d="M10 3.5v6.2L4.8 18.2A1.8 1.8 0 0 0 6.3 21h11.4a1.8 1.8 0 0 0 1.5-2.8L14 9.7V3.5"/>`,
"stop": `<path d="M7.5 7.5h9v9h-9z" fill="black"/>`,
"clear": `<path d="M4 7h16"/><path d="M9.5 7V5h5v2"/><path d="M6.5 7l1 13h9l1-13"/>`,
"hide": `<path d="M6 9l6 6 6-6"/>`,
"panel": `<rect x="3.5" y="4.5" width="17" height="15" rx="2"/><path d="M3.5 15h17"/>`,
"continue": `<path d="M8 5v14"/><path d="M13 6l7 6-7 6z" fill="black"/>`,
"over": `<path d="M4 11.5h10.5"/><path d="M11.5 8l3.5 3.5-3.5 3.5"/><circle cx="18" cy="17.5" r="1.6" fill="black"/>`,
"into": `<path d="M12 4v9"/><path d="M8 9.5l4 4 4-4"/><path d="M6 19h12"/>`,
"out": `<path d="M12 20V11"/><path d="M8 14.5l4-4 4 4"/><path d="M6 5h12"/>`,
"close": `<path d="M7 7l10 10"/><path d="M17 7L7 17"/>`,
"error": `<circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.5"/><path d="M12 16.5h.01"/>`,
"warning": `<path d="M12 3.8l9.2 16.4H2.8z"/><path d="M12 9.5v4.5"/><path d="M12 17.2h.01"/>`,
"debug": `<path d="M12 4.5a3 3 0 0 1 3 3v2a3 3 0 0 1-6 0v-2a3 3 0 0 1 3-3z"/><path d="M6 12h12"/><path d="M8 19l2.5-3"/><path d="M16 19l-2.5-3"/>`,
}
// icons 是解析好的图标,进程启动时建一次。
var icons = map[string]*ui.SVG{}
func init() {
for name, body := range iconMarkup {
src := `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">` + body + `</svg>`
svg, err := ui.ParseSVG([]byte(src))
if err != nil {
logf("图标 %s 解析失败: %v", name, err)
continue
}
icons[name] = svg
}
}
// icon 画一个图标,size 是像素高度,color 是颜色。
func icon(c *ui.Context, name string, size float32, color ui.Color) ui.Element {
svg := icons[name]
if svg == nil {
return ui.Box(c).Width(size).Height(size)
}
return ui.Icon(c, svg).Width(size).Height(size).TextColor(color)
}
// iconButtonEl 是带图标的按钮,带悬停与按下的过渡动效。
func iconButtonEl(c *ui.Context, name, label, tip string, color ui.Color) ui.Element {
t := c.Theme()
if color == (ui.Color{}) {
color = t.Text
}
base := ui.ButtonBase(c).Padding(2, 5).Radius(4)
// 悬停淡入一层底色,按下再深一档并轻微缩小。
bgTarget := ui.RGBA(0, 0, 0, 0)
switch {
case base.Pressed():
bgTarget = t.SurfacePressed
case base.Hovered():
bgTarget = t.SurfaceHover
}
bg := base.AnimateColor("iconbg", bgTarget, ui.Animation{Duration: 120 * time.Millisecond})
base = base.Background(bg)
scaleTarget := float32(1)
if base.Pressed() {
scaleTarget = 0.92
}
scale := base.AnimateTo("iconscale", scaleTarget, ui.Animation{Duration: 90 * time.Millisecond})
base = base.Scale(scale, scale)
base.Children(func() {
ui.Row(c).Gap(4).AlignItems(ui.Center).Children(func() {
icon(c, name, 13, color)
if label != "" {
ui.Text(c, label).FontSize(11).TextColor(color)
}
})
})
if tip != "" {
base = base.Tooltip(tip)
}
return base
}
// iconButton 只需要知道是否被点时用。
func iconButton(c *ui.Context, name, label, tip string, color ui.Color) bool {
return iconButtonEl(c, name, label, tip, color).Clicked()
}