Optimizations for rendering large number of items (in a stack panel) and improved visualization of scrollbar.

This commit is contained in:
Sander Schobers 2019-07-04 22:06:48 +02:00
parent 3adf44a516
commit 9e577ab1aa
3 changed files with 9 additions and 2 deletions

View File

@ -17,6 +17,7 @@ type overflow struct {
offset geom.PointF32
parent Control
content Buffer
proxied Control
hor *Scrollbar
ver *Scrollbar
@ -84,7 +85,7 @@ func (o *overflow) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.Po
}
if ver {
o.ver.ContentLength = o.desired.Y
o.ver.Arrange(ctx, geom.RectF32(bounds.Min.X+contentW, bounds.Min.Y, bounds.Max.X, bounds.Max.Y), offset, o)
o.ver.Arrange(ctx, geom.RectF32(bounds.Min.X+contentW, bounds.Min.Y, bounds.Max.X, bounds.Min.Y+contentH), offset, o)
}
}
@ -95,6 +96,11 @@ func (o *overflow) DesiredSize(ctx Context) geom.PointF32 {
}
func (o *overflow) Handle(ctx Context, e Event) {
if o.Content != o.proxied {
o.hor.ContentOffset = 0
o.ver.ContentOffset = 0
o.proxied = o.Content
}
hor, ver := o.shouldScroll(o.bounds)
if hor {
o.hor.Handle(ctx, e)

View File

@ -55,6 +55,7 @@ func (s *Scrollbar) Handle(ctx Context, e Event) {
}
func (s *Scrollbar) Render(ctx Context) {
ctx.Renderer().FillRectangle(s.bounds, RGBA(0, 0, 0, 1))
s.handle.Render(ctx)
}

View File

@ -79,7 +79,7 @@ func (p *StackPanel) Render(ctx Context) {
var bounds = p.Bounds()
for _, child := range p.Children {
var childB = child.Bounds()
if childB.Min.X >= bounds.Max.X || childB.Min.Y >= bounds.Max.Y || childB.Max.X < bounds.Min.X || childB.Max.Y < bounds.Min.Y {
if childB.Min.X >= bounds.Max.X || childB.Min.Y >= bounds.Max.Y || childB.Max.X < bounds.Min.X || childB.Max.Y < bounds.Min.Y || childB.Max.X < 0 || childB.Max.Y < 0 {
continue
}
child.Render(ctx)