forked from AllenDang/giu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListClipper.go
46 lines (35 loc) · 1 KB
/
ListClipper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package giu
import imgui "github.com/AllenDang/cimgui-go"
var _ Widget = &ListClipperWrapper{}
// ListClipperWrapper is a ImGuiListClipper implementation.
// it can be used to display a large, vertical list of items and
// avoid rendering them.
type ListClipperWrapper struct {
layout Layout
}
// ListClipper creates list clipper.
func ListClipper() *ListClipperWrapper {
return &ListClipperWrapper{}
}
// Layout sets layout for list clipper.
func (l *ListClipperWrapper) Layout(layout ...Widget) *ListClipperWrapper {
l.layout = layout
return l
}
// Build implements widget interface.
func (l *ListClipperWrapper) Build() {
// read all the layout widgets and (eventually) split nested layouts
var layout Layout
l.layout.Range(func(w Widget) {
layout = append(layout, w)
})
clipper := imgui.NewListClipper()
defer clipper.Destroy()
clipper.Begin(int32(len(layout)))
for clipper.Step() {
for i := clipper.DisplayStart(); i < clipper.DisplayEnd(); i++ {
layout[i].Build()
}
}
clipper.End()
}