Skip to content

Commit

Permalink
add color scheme control to blog
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Jul 22, 2024
1 parent b526743 commit d34b27c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions content/blog/-2024-07-22-initial-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ The key feature of Cogent Core is that it allows you to efficiently write full-s

* A dynamic color system based on Material Design 3 enables effortless switching between light and dark mode and gives developers and users the ability to easily customize the colors of an app while maintaining key contrast and legibility standards.

<color-scheme-control></color-scheme-control>

* Automatic views of any Go data structure, including slices, structs, and maps, allow for instant data binding and advanced app inspection, making complex widgets like editable tables, trees, and forms take just one line of code.

* [SVG](https://cogentcore.org/core/widgets/media/svg), [HTML](https://cogentcore.org/core/widgets/other/html), [Markdown](https://cogentcore.org/core/widgets/other/html), [Canvas](https://cogentcore.org/core/widgets/media/canvases), [Video](https://www.cogentcore.org/core/widgets/media/videos), and [3D](https://www.cogentcore.org/core/widgets/other/xyz) support make it possible to create engaging multimedia experiences from 3D models to games, and documentation and blogs like you're reading now.
Expand Down
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"embed"
"image/color"

"cogentcore.org/core/base/errors"
"cogentcore.org/core/core"
Expand Down Expand Up @@ -80,6 +81,20 @@ func main() {
})
return true
}
htmlcore.ElementHandlers["color-scheme-control"] = func(ctx *htmlcore.Context) bool {
type theme struct {
Theme core.Themes `default:"Auto"`
Color color.RGBA `default:"#4285f4"`
}
th := &theme{core.AppearanceSettings.Theme, core.AppearanceSettings.Color}
fm := core.NewForm(ctx.BlockParent).SetStruct(th)
fm.OnChange(func(e events.Event) {
core.AppearanceSettings.Theme = th.Theme
core.AppearanceSettings.Color = th.Color
core.UpdateSettings(ctx.BlockParent, core.AppearanceSettings)
})
return true
}

b.RunMainWindow()
}

0 comments on commit d34b27c

Please sign in to comment.