Choices: review r1 fixes
This commit is contained in:
40 files changed
+774
-209
No files matched your search
@@ -105,10 +105,10 @@ view := func(c *ui.Context) {
|
||||
func choiceDemo(c *ui.Context, controls, samples func()) {
|
||||
k := mujica.Tokens(c)
|
||||
ui.Column(c).Gap(20).AlignItems(ui.Start).Children(func() {
|
||||
ui.Text(c, "Parameters").Font(theme.SerifFont).FontSize(theme.H3Size).TextColor(k.Text)
|
||||
ui.Text(c, "Parameters").Font(theme.SerifFont).FontSize(mujica.FontSize(c, theme.H3Size)).TextColor(k.Text)
|
||||
ui.Row(c).Gap(20).Wrap().AlignItems(ui.Center).Children(controls)
|
||||
ui.Box(c).Height(1).FillWidth().Background(k.Ornament)
|
||||
ui.Text(c, "States").Font(theme.SerifFont).FontSize(theme.H3Size).TextColor(k.Text)
|
||||
ui.Text(c, "States").Font(theme.SerifFont).FontSize(mujica.FontSize(c, theme.H3Size)).TextColor(k.Text)
|
||||
ui.Column(c).Gap(16).AlignItems(ui.Start).Children(samples)
|
||||
})
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func choiceFlag(c *ui.Context, on *bool, label string, log func(string)) {
|
||||
// choiceLabeled shows a caption above a sample.
|
||||
func choiceLabeled(c *ui.Context, caption string, fn func()) {
|
||||
ui.Column(c).Gap(6).Children(func() {
|
||||
ui.Text(c, caption).FontSize(theme.CaptionSize).TextColor(mujica.Tokens(c).TextMuted)
|
||||
ui.Text(c, caption).FontSize(mujica.FontSize(c, theme.CaptionSize)).TextColor(mujica.Tokens(c).TextMuted)
|
||||
fn()
|
||||
})
|
||||
}
|
||||
@@ -288,7 +288,7 @@ var choiceFruits = []mujica.SelectOption[string]{
|
||||
|
||||
func selectDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
value string
|
||||
value, picked string
|
||||
clearable, disabled, noData bool
|
||||
}
|
||||
s := *ui.Local(c.Root(), "036", func() *state { return &state{value: "banana", clearable: true} })
|
||||
@@ -306,9 +306,10 @@ func selectDemo(c *ui.Context, log func(string)) {
|
||||
log(fmt.Sprintf("Fruit: %q", s.value))
|
||||
}
|
||||
})
|
||||
empty := ""
|
||||
choiceLabeled(c, "Placeholder", func() {
|
||||
mujica.Select(c, &empty, choiceFruits, mujica.SelectOptions{Placeholder: "Pick a fruit"})
|
||||
if mujica.Select(c, &s.picked, choiceFruits, mujica.SelectOptions{Placeholder: "Pick a fruit", Clearable: true}).Changed() {
|
||||
log(fmt.Sprintf("Picked: %q", s.picked))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
mujica "mujicaui"
|
||||
)
|
||||
|
||||
// choiceDemoTester runs the demo of page id at text scale and returns its tester and event log.
|
||||
func choiceDemoTester(t *testing.T, id string, scale float32) (*ui.Tester, *[]string) {
|
||||
t.Helper()
|
||||
i := slices.IndexFunc(choicePages, func(p page) bool { return p.ID == id })
|
||||
if i < 0 {
|
||||
t.Fatalf("no page %s", id)
|
||||
}
|
||||
events := &[]string{}
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{Mode: mujica.Light})
|
||||
ui.Scroll(c).Fill().Padding(24).Children(func() {
|
||||
choicePages[i].Demo(c, func(s string) { *events = append(*events, s) })
|
||||
})
|
||||
}, 900, 700)
|
||||
tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: scale})
|
||||
return tt, events
|
||||
}
|
||||
|
||||
func TestChoiceSelectDemoKeepsPlaceholderChoice(t *testing.T) {
|
||||
tt, events := choiceDemoTester(t, "036", 1)
|
||||
if err := tt.Click("Pick a fruit"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := tt.Click("Fig"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tt.Frame()
|
||||
if !tt.HasText("Fig") || !slices.Contains(*events, `Picked: "fig"`) {
|
||||
t.Fatalf("choice lost: texts %q, events %q", tt.Texts(), *events)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChoiceDemoHeadingsFollowTextScale(t *testing.T) {
|
||||
height := func(scale float32) float32 {
|
||||
tt, _ := choiceDemoTester(t, "031", scale)
|
||||
tt.Frame()
|
||||
r, ok := tt.Find("Parameters")
|
||||
if !ok {
|
||||
t.Fatal("heading missing")
|
||||
}
|
||||
return r.H
|
||||
}
|
||||
if one, two := height(1), height(2); two < one*1.5 {
|
||||
t.Fatalf("heading %v high at 2x, %v at 1x", two, one)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user