From 8858a54b5ddb3a2d8a42ecb1a837c02800bc934f Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Mon, 2 Mar 2026 17:38:55 -0500 Subject: create lay/strain package The lay/strain package uses the Cassowary algorithm to solve systems of layout constraints. --- lay/strain/bound.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lay/strain/bound.go (limited to 'lay/strain/bound.go') diff --git a/lay/strain/bound.go b/lay/strain/bound.go new file mode 100644 index 0000000..f1d4488 --- /dev/null +++ b/lay/strain/bound.go @@ -0,0 +1,28 @@ +package strain + +import "golang.org/x/exp/shiny/unit" + +// Bounds places the inclusive lower and upper bounds [Min, Max] +// on a dimension. A negative value means there is no bound. +// If both Min and Max are non-negative, then it is well formed if +// Min <= Max. +type Bounds struct { + Min, Max unit.Value +} + +// BoundedPoint is a point with bounds on its horizontal/vertical +// position. +type BoundedPoint struct { + X, Y Bounds +} + +// Free returns an unconstrained value (negative Min and Max). +func Free() Bounds { + return Bounds{unit.Pixels(-1), unit.Pixels(-1)} +} + +// FreePoint returns an unconstrained point (negative Min and Max +// in both dimensions). +func FreePoint() BoundedPoint { + return BoundedPoint{Free(), Free()} +} -- cgit v1.2.3