Add layout components 001-020 with demos and behavior tests

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 18:02:26 -04:00
1 parent 08e19833a2
commit 9a7f593892
29 files changed
+2110 -9

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
package layout
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type PanelOptions struct {
Style pixel.FrameStyle
// Fill is the body slot; zero means Face.
Fill pixel.Slot
// Padding is inside the border; zero means 4.
Padding int
}
// Panel frames children in a style.
func Panel(c *ui.Context, o PanelOptions, children func()) *ui.Element {
k := pixel.K(c)
fill := o.Fill
if fill == pixel.Ink {
fill = pixel.Face
}
pad := border(o.Style) + orDef("Panel Padding", o.Padding, 4)
return ui.Column(c).Padding(k.D(pad)).Draw(func(p *ui.Painter, r ui.Rect) {
box(k.Canvas(p, r), o.Style, fill)
}).Children(children)
}
// border is the dots a frame style takes per side.
func border(s pixel.FrameStyle) int {
switch s {
case pixel.Flat, pixel.Notched:
return 1
case pixel.Raised, pixel.Sunken:
return 2
case pixel.Double, pixel.Window:
return 3
}
panic("layout: unknown frame style")
}