ListClipper.go 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package giu
  2. import (
  3. "github.com/AllenDang/imgui-go"
  4. )
  5. var _ Widget = &ListClipperWrapper{}
  6. // ListClipperWrapper is a ImGuiListClipper implementation.
  7. // it can be used to diplay a large, vertical list of items and
  8. // avoid rendering them.
  9. type ListClipperWrapper struct {
  10. layout Layout
  11. }
  12. // ListClipper creates list clipper.
  13. func ListClipper() *ListClipperWrapper {
  14. return &ListClipperWrapper{}
  15. }
  16. // Layout sets layout for list clipper.
  17. func (l *ListClipperWrapper) Layout(layout ...Widget) *ListClipperWrapper {
  18. l.layout = layout
  19. return l
  20. }
  21. // Build implements widget interface.
  22. func (l *ListClipperWrapper) Build() {
  23. // read all the layout widgets and (eventually) split nested layouts
  24. var layout Layout
  25. l.layout.Range(func(w Widget) {
  26. layout = append(layout, w)
  27. })
  28. clipper := imgui.NewListClipper()
  29. defer clipper.Delete()
  30. clipper.Begin(len(layout))
  31. for clipper.Step() {
  32. for i := clipper.DisplayStart(); i < clipper.DisplayEnd(); i++ {
  33. layout[i].Build()
  34. }
  35. }
  36. clipper.End()
  37. }