Add feedback components 106-130; inert scope, focus return, two-step deploy
This commit is contained in:
87 files changed
+2492
-147
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ type BlinkTextOptions struct {
|
||||
// BlinkText blinks; under Reduce Motion it stays shown.
|
||||
func BlinkText(c *ui.Context, s string, o BlinkTextOptions) *ui.Element {
|
||||
k, sc := pixel.K(c), scale(o.Scale)
|
||||
fps := orDef("BlinkText FPS", o.FPS, 2)
|
||||
fps := pixel.Or("BlinkText FPS", o.FPS, 2)
|
||||
return block(c, k, s, pixel.Measure(s)*sc, pixel.LineHeight*sc, func(g pixel.Canvas) {
|
||||
if g.Step(fps)%2 == 0 {
|
||||
g.Text(0, 0, s, o.Slot, sc)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ type HeadingOptions struct {
|
||||
|
||||
// Heading is a title with a 1-dot Shade shadow.
|
||||
func Heading(c *ui.Context, s string, o HeadingOptions) *ui.Element {
|
||||
level := orDef("Heading Level", o.Level, 1)
|
||||
level := pixel.Or("Heading Level", o.Level, 1)
|
||||
if level > 3 {
|
||||
panic(fmt.Sprintf("text: Heading Level %d outside 1–3", level))
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ type marqueeState struct{ offset, last int }
|
||||
// Marquee scrolls s a dot a step; hover pauses it.
|
||||
func Marquee(c *ui.Context, s string, o MarqueeOptions) *ui.Element {
|
||||
k := pixel.K(c)
|
||||
w := orDef("Marquee Width", o.Width, 120)
|
||||
w := pixel.Or("Marquee Width", o.Width, 120)
|
||||
e := ui.Box(c).Size(k.D(w), k.D(pixel.LineHeight)).Clip().Label(s).Role(ui.RoleText)
|
||||
ms := ui.Local(e, marqueeKey{}, func() marqueeState { return marqueeState{last: -1} })
|
||||
if k.Reduce() || e.Hovered() {
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ func Odometer(c *ui.Context, value int, o OdometerOptions) *ui.Element {
|
||||
panic(fmt.Sprintf("text: Odometer value %d is negative", value))
|
||||
}
|
||||
k := pixel.K(c)
|
||||
digits := orDef("Odometer Digits", o.Digits, len(strconv.Itoa(value)))
|
||||
digits := pixel.Or("Odometer Digits", o.Digits, len(strconv.Itoa(value)))
|
||||
if value >= int(math.Pow10(digits)) {
|
||||
panic(fmt.Sprintf("text: Odometer value %d needs more than %d digits", value, digits))
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ type ParagraphOptions struct {
|
||||
// Paragraph wraps s at the width it had last frame.
|
||||
func Paragraph(c *ui.Context, s string, o ParagraphOptions) *ui.Element {
|
||||
k := pixel.K(c)
|
||||
gap := orDef("Paragraph Gap", o.Gap, 0)
|
||||
gap := pixel.Or("Paragraph Gap", o.Gap, 0)
|
||||
if o.Align > Right {
|
||||
panic(fmt.Sprintf("text: unknown Align %d", o.Align))
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ type scrambleState struct {
|
||||
// ScrambleText settles from random glyphs to s, left to right.
|
||||
func ScrambleText(c *ui.Context, s string, o ScrambleTextOptions) *ui.Element {
|
||||
k, sc := pixel.K(c), scale(o.Scale)
|
||||
fps := orDef("ScrambleText FPS", o.FPS, 30)
|
||||
fps := pixel.Or("ScrambleText FPS", o.FPS, 30)
|
||||
rs := []rune(s)
|
||||
e := ui.Box(c).Size(k.D(pixel.Measure(s)*sc), k.D(pixel.LineHeight*sc)).Label(s).Role(ui.RoleText)
|
||||
st := ui.Local(e, scrambleKey{}, func() scrambleState { return scrambleState{start: -1} })
|
||||
|
||||
+1
-12
@@ -16,20 +16,9 @@ func block(c *ui.Context, k pixel.Kit, s string, w, h int, fn func(g pixel.Canva
|
||||
})
|
||||
}
|
||||
|
||||
// orDef is v, or def for zero; negative panics.
|
||||
func orDef(name string, v, def int) int {
|
||||
if v < 0 {
|
||||
panic(fmt.Sprintf("text: %s %d is negative", name, v))
|
||||
}
|
||||
if v == 0 {
|
||||
return def
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// scale is s, or 1 for zero; outside 1–4 panics.
|
||||
func scale(s int) int {
|
||||
s = orDef("Scale", s, 1)
|
||||
s = pixel.Or("Scale", s, 1)
|
||||
if s > 4 {
|
||||
panic(fmt.Sprintf("text: Scale %d outside 1–4", s))
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ type typeState struct {
|
||||
// Typewriter reveals s; a click or Enter shows the rest.
|
||||
func Typewriter(c *ui.Context, s string, o TypewriterOptions) TypewriterResult {
|
||||
k := pixel.K(c)
|
||||
cps := orDef("Typewriter CPS", o.CPS, 20)
|
||||
cps := pixel.Or("Typewriter CPS", o.CPS, 20)
|
||||
shell, base, st := pixel.Shell(c, func() *ui.Element {
|
||||
e := ui.Box(c).Role(ui.RoleText).Label(s).Disabled(o.Disabled)
|
||||
if !o.Disabled {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ type WaveTextOptions struct {
|
||||
// WaveText bobs characters on a sine wave at 10 fps.
|
||||
func WaveText(c *ui.Context, s string, o WaveTextOptions) *ui.Element {
|
||||
k, sc := pixel.K(c), scale(o.Scale)
|
||||
amp := orDef("WaveText Amp", o.Amp, 2)
|
||||
amp := pixel.Or("WaveText Amp", o.Amp, 2)
|
||||
return block(c, k, s, pixel.Measure(s)*sc, pixel.LineHeight*sc+2*amp, func(g pixel.Canvas) {
|
||||
step := g.Step(10)
|
||||
each(s, sc, func(i int, r rune, x int) {
|
||||
|
||||
Reference in new issue
Block a user