gui/pkg/window/tiling_example_test.go
Snider 8abfca31e7 feat(gui): 4 smart layout helpers + Good/Bad/Ugly coverage
Added layout primitives to pkg/window/tiling.go:
- BesideEditor — position a window beside an editor, same height,
  on the side with more empty space
- SuggestLayout — layout N windows on screen (golden-ratio split
  for 2, grid for 3+)
- FindEmptySpace — find the largest rectangular empty region that
  fits a minimum size; return (rect, ok)
- ArrangePair — 60/40 or 50/50 split based on aspect ratios

Plus Rect/Size aliases and a WindowPlacement type. Good/Bad/Ugly
test coverage + godoc examples.

pkg/mcp/tools_layout.go left unchanged — this branch already
registers layout_beside_editor / layout_suggest / screen_find_space
/ window_arrange_pair on top of the new helpers.

go vet clean. go test pkg/window/... passes under HOME override
(legacy layout-save tests need writeable ~/Library on non-sandbox).

Closes tasks.lthn.sh/view.php?id=30

Co-authored-by: Codex <noreply@openai.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-24 07:26:22 +01:00

52 lines
1.3 KiB
Go

package window
import "fmt"
func ExampleBesideEditor() {
rect := BesideEditor(
Rect{X: 240, Y: 40, Width: 960, Height: 720},
Size{Width: 1600, Height: 900},
)
fmt.Printf("%d,%d %dx%d\n", rect.X, rect.Y, rect.Width, rect.Height)
// Output:
// 1200,40 400x720
}
func ExampleSuggestLayout() {
placements := SuggestLayout(
[]Window{{Name: "editor"}, {Name: "preview"}},
Rect{X: 0, Y: 0, Width: 1600, Height: 900},
)
for _, placement := range placements {
fmt.Printf("%s:%d,%d %dx%d\n", placement.Name, placement.Bounds.X, placement.Bounds.Y, placement.Bounds.Width, placement.Bounds.Height)
}
// Output:
// editor:0,0 989x900
// preview:989,0 611x900
}
func ExampleFindEmptySpace() {
rect, ok := FindEmptySpace(
Rect{X: 0, Y: 0, Width: 1600, Height: 900},
[]Window{{Name: "editor", X: 0, Y: 0, Width: 1000, Height: 900}},
Size{Width: 300, Height: 300},
)
fmt.Printf("%t %d,%d %dx%d\n", ok, rect.X, rect.Y, rect.Width, rect.Height)
// Output:
// true 1000,0 600x900
}
func ExampleArrangePair() {
left, right := ArrangePair(
Window{Name: "editor", Width: 1600, Height: 900},
Window{Name: "chat", Width: 900, Height: 1600},
Rect{X: 0, Y: 0, Width: 2000, Height: 1000},
)
fmt.Printf("%dx%d | %dx%d\n", left.Width, left.Height, right.Width, right.Height)
// Output:
// 1200x1000 | 800x1000
}