From 1b1663f2c1d0dd9217531011b35d512a76c3db73 Mon Sep 17 00:00:00 2001 From: Waozi Date: Mon, 16 Nov 2026 21:29:43 -0300 Subject: [PATCH] Follow current Kryon appearance in Plot surfaces --- README.md | 5 +++++ src/plot_widget.zi | 15 +++++++++++---- tests/plot_widget_behavior.zi | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8c375c0..2e22f22 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ has a simple line chart. Both accept caller-owned values and colors; market data, networking, price formatting, and time labels stay in the application. +The shared plot surface, text, border and marks follow Kryon's current +`surface`, `text`, `border` and `accent` style tokens on each draw. Installed +style rules still override those defaults. Changing appearance updates an +existing chart without recreating it; callers retain their series colors. + Install the Ziran launcher once with `make install-user` in Ziran, then run `ziran fetch` and `make build` here. `make run` opens a small demo on the Cairo backend; `make check` checks the source and runs the nonvisual indicator test. diff --git a/src/plot_widget.zi b/src/plot_widget.zi index e267dba..fbe427d 100644 --- a/src/plot_widget.zi +++ b/src/plot_widget.zi @@ -25,6 +25,13 @@ PlotFaces :: struct { mark: StyleFrame } +PlotThemeColor :: (name: string, fallback: u32) -> u32 { + color := StyleTokenColorOr(name, ColorFromPacked(fallback)) + return (cast(u32)color.r << cast(u32)24) | + (cast(u32)color.g << cast(u32)16) | + (cast(u32)color.b << cast(u32)8) | cast(u32)color.a +} + #program_export DefaultPlotFaces :: () -> PlotFaces { faces: PlotFaces @@ -33,9 +40,9 @@ DefaultPlotFaces :: () -> PlotFaces { cast(u32)StyleBorderWidth | cast(u32)StyleRadius | cast(u32)StyleFontSize | cast(u32)StylePaddingX | cast(u32)StylePaddingY | cast(u32)StyleOpacity - faces.plot.value.background = cast(u32)0xf5f5f5ff - faces.plot.value.foreground = cast(u32)0x171717ff - faces.plot.value.border = cast(u32)0x737373ff + faces.plot.value.background = PlotThemeColor("surface", cast(u32)0xf5f5f5ff) + faces.plot.value.foreground = PlotThemeColor("text", cast(u32)0x171717ff) + faces.plot.value.border = PlotThemeColor("border", cast(u32)0x737373ff) faces.plot.value.border_width = 1.0 faces.plot.value.radius = 4.0 faces.plot.value.font_size = 14.0 @@ -44,7 +51,7 @@ DefaultPlotFaces :: () -> PlotFaces { faces.plot.value.opacity = 1.0 faces.mark.value.fields = cast(u32)StyleBackground | cast(u32)StyleOpacity - faces.mark.value.background = cast(u32)0x3b609bff + faces.mark.value.background = PlotThemeColor("accent", cast(u32)0x3b609bff) faces.mark.value.opacity = 1.0 return faces } diff --git a/tests/plot_widget_behavior.zi b/tests/plot_widget_behavior.zi index 7df1947..ec9fc09 100644 --- a/tests/plot_widget_behavior.zi +++ b/tests/plot_widget_behavior.zi @@ -6,6 +6,7 @@ TestSession :: () -> Session { } #import "kryon/geometry" +#import "kryon/drawing_props" #import "kryon/paint_queue" #import "plot" #import "plot_props" @@ -133,6 +134,7 @@ BandChecks :: () -> s32 { #program_export main :: () -> s32 { + if ThemeChecks() != 0 { return 20 } band := BandChecks() if band != 0 { return band } index: s32 = 0 @@ -147,3 +149,31 @@ main :: () -> s32 { } return CompareLines() } + +ThemeToken :: (name: string, color: u32) -> bool { + bytes: [16]u8 + for index: 0..cast(s32)name.count - 1 { bytes[index] = name[index] } + return SetStyleTokenColorBytes(bytes[0:name.count], color) +} +ThemeChecks :: () -> s32 { + saved := CaptureStyleTokenColors() + defer { unused RestoreStyleTokenColors(saved) } + ClearStyleTokenColors() + fallback := DefaultPlotFaces() + if fallback.plot.value.background != cast(u32)0xf5f5f5ff { return 1 } + unused ThemeToken("surface", cast(u32)0xe8dccaff) + unused ThemeToken("text", cast(u32)0x302820ff) + unused ThemeToken("border", cast(u32)0xd0b898ff) + unused ThemeToken("accent", cast(u32)0x704020ff) + light := PlotFacesFor(PlotProps.{}, DefaultPlotFaces()) + if light.plot.value.background != cast(u32)0xe8dccaff || + light.plot.value.foreground != cast(u32)0x302820ff || + light.plot.value.border != cast(u32)0xd0b898ff || + light.mark.value.background != cast(u32)0x704020ff { return 2 } + unused ThemeToken("surface", cast(u32)0x17212bff) + unused ThemeToken("text", cast(u32)0xf1f5f9ff) + dark := PlotFacesFor(PlotProps.{}, DefaultPlotFaces()) + if dark.plot.value.background != cast(u32)0x17212bff || + dark.plot.value.foreground != cast(u32)0xf1f5f9ff { return 3 } + return 0 +}