repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

pico / pkg / tui
Eric Bower  ·  2025-03-17

group.go

 1package tui
 2
 3import (
 4	"git.sr.ht/~rockorager/vaxis"
 5	"git.sr.ht/~rockorager/vaxis/vxfw"
 6)
 7
 8type GroupStack struct {
 9	s         []vxfw.Surface
10	Gap       int
11	Direction string
12}
13
14func NewGroupStack(widgets []vxfw.Surface) *GroupStack {
15	return &GroupStack{
16		s:         widgets,
17		Gap:       0,
18		Direction: "vertical",
19	}
20}
21
22func (m *GroupStack) HandleEvent(vaxis.Event, vxfw.EventPhase) (vxfw.Command, error) {
23	return nil, nil
24}
25
26func (m *GroupStack) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
27	root := vxfw.NewSurface(ctx.Max.Width, ctx.Max.Height, m)
28	ah := 0
29	aw := 0
30	for _, surf := range m.s {
31		if m.Direction == "vertical" {
32			root.AddChild(0, ah, surf)
33			ah += int(surf.Size.Height) + m.Gap
34		} else {
35			// horizontal
36			root.AddChild(aw, 0, surf)
37			if surf.Size.Height > uint16(ah) {
38				ah = int(surf.Size.Height)
39			}
40			aw += int(surf.Size.Width) + m.Gap
41		}
42	}
43	root.Size.Height = uint16(ah)
44	return root, nil
45}