Add chat components 321-345; named List rows, inert scroll views
Speech bubbles, a chat log that follows its end, a composer that sends on Enter, typing dots, chat and channel lists, read receipts, reactions, emoji and sticker pickers, mentions, date and unread rules, system lines, member lists, user cards, a mailbox, mail reader and letter, a notification bell, call controls, a voice meter, attachment chips, link previews and polls. pixel's editor takes EnterSends; display's Bubble takes a Fill and exports EmojiSprite. data.List names its rows, which also lets typing choose one. layout.ScrollArea and input.TextArea hold still under Inert, and an inert scroll view leaves the Tab order until it wakes.
This commit is contained in:
50 files changed
+2697
-34
No files matched your search
@@ -383,3 +383,70 @@ func boolInt(b bool) int {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestScrollAreaHoldsStillWhenInert(t *testing.T) {
|
||||
s, inert := ui.ScrollState{}, false
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
pixel.Use(c, pixel.Settings{Palette: pixel.SpringDay, Inert: inert})
|
||||
layout.ScrollArea(c, &s, layout.ScrollAreaOptions{Label: "List"}, func() {
|
||||
for range 40 {
|
||||
ui.Box(c).Height(32)
|
||||
}
|
||||
}).Element.Size(200, 100)
|
||||
}, 300, 200)
|
||||
tt.Frame()
|
||||
r := box(t, tt, "List")
|
||||
if err := tt.Click("List"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bar := func() []uint8 {
|
||||
return tt.Image().SubImage(image.Rect(int(r.X+r.W), int(r.Y), int(r.X+r.W)+20, int(r.Y+r.H))).(*image.RGBA).Pix
|
||||
}
|
||||
looks := bar()
|
||||
inert = true
|
||||
tt.Frame()
|
||||
// Inert keeps the look; only Disabled dims the bar.
|
||||
if string(bar()) != string(looks) {
|
||||
t.Fatal("an inert scroll area changed its look")
|
||||
}
|
||||
// Keys, the wheel and the arrows all leave it be.
|
||||
tt.Key(0, ui.KeyDown)
|
||||
tt.Move(r.X+20, r.Y+30)
|
||||
tt.Scroll(r.X+20, r.Y+30, 0, 80)
|
||||
if err := tt.Click("SCROLL DOWN"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s.Y != 0 {
|
||||
t.Fatalf("an inert scroll area moved to %v", s.Y)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInertScrollAreaLetsTabPass(t *testing.T) {
|
||||
s, inert, clicks := ui.ScrollState{}, false, 0
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
use(c)
|
||||
set := pixel.Current(c)
|
||||
set.Inert = inert
|
||||
pixel.Scope(c, set, func() {
|
||||
layout.ScrollArea(c, &s, layout.ScrollAreaOptions{Label: "List"}, func() {
|
||||
for range 40 {
|
||||
ui.Box(c).Height(32)
|
||||
}
|
||||
}).Element.Size(200, 100)
|
||||
})
|
||||
if ui.ButtonBase(c).Label("Next").Size(60, 20).Clicked() {
|
||||
clicks++
|
||||
}
|
||||
}, 300, 200)
|
||||
if err := tt.Click("List"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inert = true
|
||||
tt.Frame()
|
||||
// Parked on the root, Tab passes the inert view.
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if clicks != 1 {
|
||||
t.Fatal("Tab stuck on an inert scroll area")
|
||||
}
|
||||
}
|
||||
+15
-8
@@ -44,21 +44,28 @@ func ScrollArea(c *ui.Context, s *ui.ScrollState, o ScrollAreaOptions, children
|
||||
row := ui.Row(c).AlignItems(ui.Stretch).Reverse()
|
||||
last := ui.Local(row, scrollKey{}, func() float32 { return s.Y })
|
||||
view := row.Bounds().H
|
||||
// Disabled freezes the view: any move is undone before paint.
|
||||
if o.Disabled {
|
||||
// Off freezes the view: any move is undone before paint.
|
||||
inert := pixel.Current(c).Inert
|
||||
if o.Disabled || inert {
|
||||
s.Y = *last
|
||||
}
|
||||
var v *ui.Element
|
||||
row.Children(func() {
|
||||
scrollBar(c, k, s, view, o.Disabled)
|
||||
scrollBar(c, k, s, view, o.Disabled || inert, o.Disabled)
|
||||
// A disabled view is a new element; the focus leaves.
|
||||
v = ui.Scroll(c).Key(o.Disabled).TrackScroll(s).Grow(1).Label(o.Label).FocusRing(false)
|
||||
if o.Disabled {
|
||||
switch {
|
||||
case o.Disabled:
|
||||
v.Role(ui.RoleGroup).Description(k.Msg("disabled"))
|
||||
} else {
|
||||
case inert:
|
||||
// Out of the Tab order, so Tab moves past it.
|
||||
v.Role(ui.RoleScroll)
|
||||
default:
|
||||
v.Role(ui.RoleScroll).Focusable()
|
||||
}
|
||||
v.Children(children)
|
||||
// Inert parks the focus and gives it back after.
|
||||
pixel.Park(c, v, inert)
|
||||
})
|
||||
focus := v.FocusVisible()
|
||||
row.Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
@@ -83,11 +90,11 @@ func ScrollArea(c *ui.Context, s *ui.ScrollState, o ScrollAreaOptions, children
|
||||
return res
|
||||
}
|
||||
|
||||
// scrollBar draws arrows, track and thumb, and moves s.
|
||||
func scrollBar(c *ui.Context, k pixel.Kit, s *ui.ScrollState, view float32, disabled bool) {
|
||||
// scrollBar moves s unless off; dim draws it disabled.
|
||||
func scrollBar(c *ui.Context, k pixel.Kit, s *ui.ScrollState, view float32, disabled, dim bool) {
|
||||
clamp := func(y float32) { s.Y = max(0, min(y, s.MaxY)) }
|
||||
ui.Column(c).Width(k.D(barW)).DrawOver(func(p *ui.Painter, r ui.Rect) {
|
||||
if disabled {
|
||||
if dim {
|
||||
g := k.Canvas(p, r)
|
||||
g.Checker(0, 0, g.W, g.H, pixel.Face)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user