Simple Layout Library in Go
Why?
Layout is very overtly complicated.
So why not make a layout calculation library that uses weights and ratios for things?
How it works
Pretty much check the example, but basically:
import (
g "codeberg.org/pingwt/glacier"
)
func main() {
// layout map is just a hashmap to look up your layouts
lm := make(g.LayoutMap)
// you can make a root as a Col layout to store things,
// then here we have top (calculated first) and bottom (calculated second)
root := g.NewLayout(lm, "root", g.Col, 0, 1)
g.NewLayout(lm, "top", g.Row, 0, 1)
g.NewLayout(lm, "bot", g.Row, 1, 1)
// and we can add those into root and update it
root.Children = g.Children{lm["top"], lm["bot"]}
root.W = 800
root.H = 600
root.Update()
// now you can query the outputs
botW := lm["bot"].W //should return 800 still
botH := lm["bot"].H //should return 300 as we split root into two equal weights
}
And then you can use the X,Y,W,H calculation in your favorite UI library.
Inspiration
Naming comes from Go+Layout so glay just like the clay C UI/Layout library but then it's extra play-on-word with glay-cier -> glacier