Follow the active Kryon palette when drawing plots

This commit is contained in:
waozi committed 2026-11-20 00:42:55 -03:00
1 parent 45bdd3bb9d
commit 376f273dd1
5 files changed
+83 -49

No files matched your search

+46 -29
View File
@@ -13,7 +13,9 @@ TestSession :: () -> Session {
#import "plot_widget"
#import "band_chart"
#import "band_chart_props"
Theme :: #import "kryon/theme";
#import "kryon/tree"
#import "kryon/widget_palette"
#import "kryon/widget_kind"
using PlotMode;
@@ -134,19 +136,10 @@ BandChecks :: () -> s32 {
#program_export
main :: () -> s32 {
if ThemeChecks() != 0 { return 20 }
band := BandChecks()
if band != 0 { return band }
index: s32 = 0
while index < 2 {
if Frame() != index || PlotHostFailed() { return 1 }
if PlotBackgrounds() != (index + 1) * 2 ||
PlotMarks() != (index + 1) * 3 ||
PlotOutlines() != (index + 1) * 2 ||
PlotLineCount() != (index + 1) * 2 ||
PlotLabels() != (index + 1) * 4 { return 2 }
index += 1
}
theme := ThemeChecks()
if theme != 0 { return theme }
return CompareLines()
}
@@ -155,25 +148,49 @@ ThemeToken :: (name: string, color: u32) -> bool {
for index: 0..cast(s32)name.count - 1 { bytes[index] = name[index] }
return SetStyleTokenColorBytes(bytes[0:name.count], color)
}
CheckThemeFrame :: () -> bool {
index := phase
if Frame() != index || PlotHostFailed() { return false }
return PlotBackgrounds() == (index + 1) * 2 &&
PlotMarks() == (index + 1) * 3 && PlotOutlines() == (index + 1) * 2 &&
PlotLineCount() == (index + 1) * 2 && PlotLabels() == (index + 1) * 4
}
ExpectPalette :: (palette: Theme.Palette) {
ExpectPlotColors(palette.surface, palette.border, palette.foreground, palette.accent)
}
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 }
if !Theme.InstallDefaultTheme(false) { return 20 }
ExpectPalette(Theme.LightPalette())
if !CheckThemeFrame() { return 21 }
// Both existing nodes draw again with the new palette and the same keys.
if !Theme.SetThemeMode(true) { return 22 }
dark := Theme.DarkPalette()
ExpectPalette(dark)
if !CheckThemeFrame() { return 23 }
custom := cast(u32)0xe8dccaff
if !ThemeToken("surface", custom) { return 24 }
ExpectPlotColors(custom, dark.border, dark.foreground, dark.accent)
if !CheckThemeFrame() { return 25 }
scoped := WidgetPalette.{.base = cast(u32)0x17212bff,
.background = cast(u32)0x101820ff, .text = cast(u32)0xf1f5f9ff,
.border = cast(u32)0x506080ff, .selected = cast(u32)0x90d0e0ff,
.selected_text = cast(u32)0x102030ff}
if !WidgetPaletteUse(TestSession(), scoped) { return 26 }
ExpectPlotColors(scoped.base, scoped.border, scoped.text, scoped.selected)
if !CheckThemeFrame() { return 27 }
if !WidgetPaletteRestore(TestSession()) { return 28 }
ExpectPlotColors(custom, dark.border, dark.foreground, dark.accent)
if !CheckThemeFrame() { return 29 }
ClearStyleTokenColors()
if !Theme.SetThemeMode(false) { return 30 }
ExpectPalette(Theme.LightPalette())
if !CheckThemeFrame() { return 31 }
return 0
}