Add layout components 0001-0025
Stack through StickyHeader, with behavior tests and gallery demos. kit gains Arrive, Settle (paint-time layout check) and Shade. Several actions return named ui.Element results; mygo vet forbids elements in structs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b34562333b
commit
4efaf2680f
41 files changed
+1765
-11
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/CrychicUI/icon"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/CrychicUI/kit"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/CrychicUI/sound"
|
||||
"github.com/egoist/mygo/ui"
|
||||
)
|
||||
|
||||
// SidebarLayout puts a side column by main; side springs open.
|
||||
func SidebarLayout(c *ui.Context, open *bool, side, main func()) ui.Element {
|
||||
if open == nil {
|
||||
panic("layout: SidebarLayout needs open")
|
||||
}
|
||||
t := c.Theme()
|
||||
root := ui.Row(c).Fill().AlignItems(ui.Stretch)
|
||||
return root.Children(func() {
|
||||
col := ui.Column(c).ClipX().Background(t.Surface)
|
||||
w := float32(0)
|
||||
if *open {
|
||||
w = t.Rem(16)
|
||||
}
|
||||
col.Width(col.AnimateTo("w", w, ui.Snappy)).Children(func() {
|
||||
ui.Column(c).Width(t.Rem(16)).Grow(1).Padding(t.Space(3)).Gap(t.Space(1)).Children(side)
|
||||
})
|
||||
ui.Column(c).Grow(1).Basis(0).Children(func() {
|
||||
glyph := "panel-left-open"
|
||||
if *open {
|
||||
glyph = "panel-left-close"
|
||||
}
|
||||
b := ui.Button(c, "").Label("Toggle sidebar").Margin(t.Space(2)).Children(func() {
|
||||
ui.Icon(c, icon.Must(glyph)).Size(16, 16).ContentTransition(ui.ContentTransition{})
|
||||
})
|
||||
if kit.Clicked(kit.Press(b), sound.Toggle) {
|
||||
*open = !*open
|
||||
root.SetChanged()
|
||||
kit.Log("SidebarLayout", "toggled", "open", *open)
|
||||
}
|
||||
ui.Column(c).Grow(1).Children(main)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user