Skip to content

Commit

Permalink
start on pages based structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Jul 14, 2024
1 parent f060647 commit 025ae18
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<home-page></home-page>
52 changes: 31 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,47 @@ import (
"cogentcore.org/core/base/errors"
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"cogentcore.org/core/htmlcore"
"cogentcore.org/core/pages"
"cogentcore.org/core/styles"
"cogentcore.org/core/styles/units"
)

//go:embed name.png
var resources embed.FS

//go:embed content
var content embed.FS

func main() {
b := core.NewBody("Cogent Core")
pg := pages.NewPage(b).SetContent(content)
b.AddAppBar(pg.MakeToolbar)

frame := core.NewFrame(b)
frame.Styler(func(s *styles.Style) {
s.Direction = styles.Column
s.Grow.Set(1, 1)
s.CenterAll()
})
errors.Log(core.NewSVG(frame).ReadString(core.AppIcon))
img := core.NewImage(frame)
errors.Log(img.OpenFS(resources, "name.png"))
img.Styler(func(s *styles.Style) {
x := func(uc *units.Context) float32 {
return min(uc.Dp(612), uc.Vw(90))
}
s.Min.Set(units.Custom(x), units.Custom(func(uc *units.Context) float32 {
return x(uc) * (128.0 / 612.0)
}))
})
core.NewText(frame).SetType(core.TextHeadlineMedium).SetText(core.AppAbout)
core.NewButton(frame).SetText("Learn about the Cogent Core framework").OnClick(func(e events.Event) {
core.TheApp.OpenURL("https://cogentcore.org/core")
})
htmlcore.ElementHandlers["home-page"] = func(ctx *htmlcore.Context) bool {
frame := core.NewFrame(ctx.BlockParent)
frame.Styler(func(s *styles.Style) {
s.Direction = styles.Column
s.Grow.Set(1, 1)
s.CenterAll()
})
errors.Log(core.NewSVG(frame).ReadString(core.AppIcon))
img := core.NewImage(frame)
errors.Log(img.OpenFS(resources, "name.png"))
img.Styler(func(s *styles.Style) {
x := func(uc *units.Context) float32 {
return min(uc.Dp(612), uc.Vw(90))
}
s.Min.Set(units.Custom(x), units.Custom(func(uc *units.Context) float32 {
return x(uc) * (128.0 / 612.0)
}))
})
core.NewText(frame).SetType(core.TextHeadlineMedium).SetText(core.AppAbout)
core.NewButton(frame).SetText("Learn about the Cogent Core framework").OnClick(func(e events.Event) {
core.TheApp.OpenURL("https://cogentcore.org/core")
})
return true
}

b.RunMainWindow()
}

0 comments on commit 025ae18

Please sign in to comment.