From d34b27c128422e77ef63d3e8e962dab924288466 Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Mon, 22 Jul 2024 13:16:24 -0700 Subject: [PATCH] add color scheme control to blog --- content/blog/-2024-07-22-initial-release.md | 2 ++ main.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/content/blog/-2024-07-22-initial-release.md b/content/blog/-2024-07-22-initial-release.md index 42bec28..891df50 100644 --- a/content/blog/-2024-07-22-initial-release.md +++ b/content/blog/-2024-07-22-initial-release.md @@ -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. + + * 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. diff --git a/main.go b/main.go index b5b1b2a..b25edf9 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ package main import ( "embed" + "image/color" "cogentcore.org/core/base/errors" "cogentcore.org/core/core" @@ -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() }