Choices: components 031-040

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 12:32:37 -04:00
1 parent e538f88d5d
commit 325667cd10
23 files changed
+27 -44

No files matched your search

+1 -1
View File
@@ -227,7 +227,7 @@ func cascaderRow(c *ui.Context, st *cascaderState, path *[]string, opts Cascader
ui.Text(c, n.Label).SingleLine().Grow(1).Shrink(1) ui.Text(c, n.Label).SingleLine().Grow(1).Shrink(1)
if !n.Leaf { if !n.Leaf {
ui.Box(c).Size(14, 14).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) { ui.Box(c).Size(14, 14).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
internal.Chevron(p, r, true, k.TextMuted) internal.Mark(p, r, "chevron-right", k.TextMuted)
}) })
} }
}) })
+1 -6
View File
@@ -69,12 +69,7 @@ func Combobox(c *ui.Context, value *string, options []string, opts ComboboxOptio
p.Input.Focus() p.Input.Focus()
} }
open := p.Open() open := p.Open()
arrow.Draw(func(pt *ui.Painter, r ui.Rect) { arrow.Draw(func(pt *ui.Painter, r ui.Rect) { internal.Mark(pt, r, selectChevron(open), k.TextMuted) })
if open {
r.Y, r.H = r.Y+r.H, -r.H
}
internal.Chevron(pt, r, false, k.TextMuted)
})
}) })
in := p.Input in := p.Input
if f.Clicked() { if f.Clicked() {
+9 -22
View File
@@ -3,6 +3,7 @@ package internal
import ( import (
"github.com/egoist/mygo/ui" "github.com/egoist/mygo/ui"
"mujicaui/icons"
"mujicaui/theme" "mujicaui/theme"
) )
@@ -31,30 +32,16 @@ func CheckBox(p *ui.Painter, r ui.Rect, s CheckState, k theme.Tokens, hover bool
bg = k.AccentHover bg = k.AccentHover
} }
p.Fill(r, bg, theme.ControlRadius) p.Fill(r, bg, theme.ControlRadius)
var path ui.Path mark := "check"
if s == Mixed { if s == Mixed {
path.MoveTo(r.X+r.W*0.25, r.Y+r.H/2).LineTo(r.X+r.W*0.75, r.Y+r.H/2) mark = "minus"
} else {
path.MoveTo(r.X+r.W*0.22, r.Y+r.H*0.52).LineTo(r.X+r.W*0.42, r.Y+r.H*0.72).LineTo(r.X+r.W*0.78, r.Y+r.H*0.3)
} }
p.StrokePath(&path, 1.75, k.OnAccent) Mark(p, r, mark, k.OnAccent)
} }
// Chevron strokes an arrow in r pointing down, or right when right. // Mark paints the Lucide icon name inset in r. Icons sit on the pixel grid,
func Chevron(p *ui.Painter, r ui.Rect, right bool, c ui.Color) { // so their cached masks never differ between frames or tests.
var path ui.Path func Mark(p *ui.Painter, r ui.Rect, name string, c ui.Color) {
if right { in := r.W * 0.12
path.MoveTo(r.X+r.W*0.38, r.Y+r.H*0.22).LineTo(r.X+r.W*0.66, r.Y+r.H/2).LineTo(r.X+r.W*0.38, r.Y+r.H*0.78) p.Icon(icons.Must(name), ui.Rect{X: r.X + in, Y: r.Y + in, W: r.W - 2*in, H: r.H - 2*in}, c)
} else {
path.MoveTo(r.X+r.W*0.22, r.Y+r.H*0.38).LineTo(r.X+r.W/2, r.Y+r.H*0.66).LineTo(r.X+r.W*0.78, r.Y+r.H*0.38)
}
p.StrokePath(&path, 1.5, c)
}
// Cross strokes an x in r.
func Cross(p *ui.Painter, r ui.Rect, c ui.Color) {
var path ui.Path
k := r.W * 0.28
path.MoveTo(r.X+k, r.Y+k).LineTo(r.X+r.W-k, r.Y+r.H-k).MoveTo(r.X+r.W-k, r.Y+k).LineTo(r.X+k, r.Y+r.H-k)
p.StrokePath(&path, 1.5, c)
} }
+1 -4
View File
@@ -229,10 +229,7 @@ func selectSearch(c *ui.Context, query *string, placeholder string) *ui.Element
var in *ui.Element var in *ui.Element
f.Children(func() { f.Children(func() {
ui.Box(c).Size(14, 14).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) { ui.Box(c).Size(14, 14).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
var path ui.Path internal.Mark(p, r, "search", k.TextMuted)
path.Circle(r.X+r.W*0.42, r.Y+r.H*0.42, r.W*0.32)
path.MoveTo(r.X+r.W*0.66, r.Y+r.H*0.66).LineTo(r.X+r.W*0.92, r.Y+r.H*0.92)
p.StrokePath(&path, 1.5, k.TextMuted)
}) })
in = ui.TextInputBase(c, query).Grow(1).Placeholder(placeholder).Label(placeholder).AutoFocus() in = ui.TextInputBase(c, query).Grow(1).Placeholder(placeholder).Label(placeholder).AutoFocus()
}) })
+11 -9
View File
@@ -178,15 +178,19 @@ func selectField(c *ui.Context, tr *ui.Element, open bool, content func()) {
tr.Children(func() { tr.Children(func() {
content() content()
ui.Box(c).Size(16, 16).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) { ui.Box(c).Size(16, 16).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
if open { internal.Mark(p, r, selectChevron(open), k.TextMuted)
// Mirrored: the chevron points up while the popup shows.
r.Y, r.H = r.Y+r.H, -r.H
}
internal.Chevron(p, r, false, k.TextMuted)
}) })
}) })
} }
// selectChevron names the arrow of a field: up while its popup shows.
func selectChevron(open bool) string {
if open {
return "chevron-up"
}
return "chevron-down"
}
// selectClear draws a small clear button that takes no Tab stop; it reports a click. // selectClear draws a small clear button that takes no Tab stop; it reports a click.
func selectClear(c *ui.Context, k theme.Tokens, name string) bool { func selectClear(c *ui.Context, k theme.Tokens, name string) bool {
x := ui.Box(c).Size(18, 18).Shrink(0).Radius(theme.ControlRadius).Role(ui.RoleButton).Label(name) x := ui.Box(c).Size(18, 18).Shrink(0).Radius(theme.ControlRadius).Role(ui.RoleButton).Label(name)
@@ -194,7 +198,7 @@ func selectClear(c *ui.Context, k theme.Tokens, name string) bool {
if x.Hovered() { if x.Hovered() {
x.Background(k.SurfaceHover) x.Background(k.SurfaceHover)
} }
x.Draw(func(p *ui.Painter, r ui.Rect) { internal.Cross(p, r, k.TextMuted) }) x.Draw(func(p *ui.Painter, r ui.Rect) { internal.Mark(p, r, "x", k.TextMuted) })
return clicked return clicked
} }
@@ -220,9 +224,7 @@ func selectRow(c *ui.Context, row *ui.Element, highlighted, chosen bool, label s
row.Children(func() { row.Children(func() {
ui.Box(c).Size(14, 14).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) { ui.Box(c).Size(14, 14).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
if chosen { if chosen {
var path ui.Path internal.Mark(p, r, "check", k.AccentText)
path.MoveTo(r.X+r.W*0.15, r.Y+r.H*0.52).LineTo(r.X+r.W*0.4, r.Y+r.H*0.76).LineTo(r.X+r.W*0.85, r.Y+r.H*0.26)
p.StrokePath(&path, 1.75, k.AccentText)
} }
}) })
ui.Text(c, label).SingleLine() ui.Text(c, label).SingleLine()
+1 -1
View File
@@ -137,7 +137,7 @@ func TestSelectEmptyAndDisabled(t *testing.T) {
} }
func TestSelectSnapshot(t *testing.T) { func TestSelectSnapshot(t *testing.T) {
snapshot(t, "select", 460, 110, func(c *ui.Context) { snapshot(t, "select", 660, 90, func(c *ui.Context) {
a, b, d := "", "banana", "apple" a, b, d := "", "banana", "apple"
ui.Row(c).Padding(20).Gap(16).Wrap().Children(func() { ui.Row(c).Padding(20).Gap(16).Wrap().Children(func() {
Select(c, &a, selectTestOptions, SelectOptions{}) Select(c, &a, selectTestOptions, SelectOptions{})
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

+3 -1
View File
@@ -217,7 +217,9 @@ func treeSelectRowView(c *ui.Context, st *treeSelectState, selected *[]string, r
if arrow.Hovered() { if arrow.Hovered() {
arrow.Background(k.SurfaceHover) arrow.Background(k.SurfaceHover)
} }
arrow.Draw(func(p *ui.Painter, rc ui.Rect) { internal.Chevron(p, rc, !open, k.TextMuted) }) arrow.Draw(func(p *ui.Painter, rc ui.Rect) {
internal.Mark(p, rc, map[bool]string{true: "chevron-down", false: "chevron-right"}[open], k.TextMuted)
})
} }
state := treeSelectCheck(n, *selected, opts) state := treeSelectCheck(n, *selected, opts)
var b *ui.Element var b *ui.Element