Files
prevara/pools.go
2025-11-30 16:45:22 +00:00

39 lines
1.1 KiB
Go

package gel
// Pool provides object pooling for frequently created widgets to reduce
// allocations during rendering. It maintains pools for Bool, List, Checkable,
// Clickable, Editor, and IncDec widgets. Use GetXxx methods to obtain widgets
// and FreeXxx methods to return them. Call Reset() between frames to reclaim
// all pooled widgets without individual Free calls.
type Pool struct {
*Window
bools []*Bool
boolsInUse int
lists []*List
listsInUse int
checkables []*Checkable
checkablesInUse int
clickables []*Clickable
clickablesInUse int
editors []*Editor
editorsInUse int
incDecs []*IncDec
incDecsInUse int
}
// NewPool creates a new widget pool associated with the given Window.
func (w *Window) NewPool() *Pool {
return &Pool{Window: w}
}
// Reset marks all pooled widgets as available for reuse.
// Call this at the start of each frame to reclaim widgets from the previous frame.
func (p *Pool) Reset() {
p.boolsInUse = 0
p.listsInUse = 0
p.checkablesInUse = 0
p.clickablesInUse = 0
p.editorsInUse = 0
p.incDecsInUse = 0
}