BandChart, Box, CandleChart, DiscreteSlider, Flow, Image, InlineEdit, Kanban, LineChart, LineChartCompare, MoneyField, OneTimeCode, Page, PanedView, Plot bars and lines, ScrubField, Shape, ShortcutRecorder, Slider, TableView, TagInput and TreeView draw in a padded Layout column; Box lays its caption over the surface in a Stack. Image and PanedView read their rect before submitting a node and now place themselves ahead, so a column shows the picture and keeps the panes inside its padding. Popup stays at its explicit rect: an overlay places itself. Shot digests, light theme, before -> after: bandchart cfd806fbd932 -> d37fe84375f2 box d6ddc973a937 -> a821528e410f candlechart f2e99d28cdf1 -> cd5f05909ee6 discreteslider f5272a989129 -> 70622cc955d9 flow 2c5805b26b8b -> 3e22f2b27294 image ca6250c0a36d -> 3fb48f5fd6b8 inlineedit 8a527d0ad8ac -> f866a3238cb1 kanban dd5a34289cc8 -> f8c1ef8bb347 linechart cc8e3ef43199 -> 5fd1b3ad6ee2 linechartcompare 7a8b1df653c7 -> 945b38580f5b moneyfield c68414de862d -> dc7081c25f6c onetimecode ffa8c2b07b64 -> f31c29882232 page a0e259c9a197 -> 93471a5ffc7a panedview c989da6c2e7d -> 1bea2c600517 plotbars a9a4863153a8 -> 328835f9f30f plotlines 0c37c01f8363 -> cd702f3d76e1 scrubfield ed4adbba3b14 -> e54c141be31f shape afea96070eff -> d0fda20c598f shortcutrecorder 2c5d3a09f612 -> a7d1ecf60db4 slider 572dbc46e242 -> fce52743e18d tableview 586c1be5b4b3 -> 82df7903b3ac taginput cfa785b58e2c -> 02253e90ba58 treeview f5dbe580fdd0 -> 7b80a157be8c
99 lines
3.5 KiB
Ziran
99 lines
3.5 KiB
Ziran
#import "kryon/geometry"
|
|
#import "kryon/session"
|
|
#import "kryon/frame_snapshot"
|
|
#import "kryon/style_sheet"
|
|
Box :: #import "kryon/box";
|
|
Text :: #import "kryon/text";
|
|
#import "kryon/control_props"
|
|
#import "kryon/drawing_props"
|
|
Plot :: #import "plot/PlotWidget";
|
|
Charts :: #import "plot/Plot";
|
|
Theme :: #import "kryon/theme";
|
|
Layout :: #import "kryon/layout";
|
|
#import "kryon/tree"
|
|
|
|
WidgetContext :: struct { theme: s32; now: float32; disabled: bool; reduced_motion: bool }
|
|
|
|
WidgetInput :: (session: Session) -> WidgetContext {
|
|
snapshot := CaptureFrameInput(session)
|
|
result: WidgetContext
|
|
result.now = cast(float32)snapshot.elapsed_ms / 1000.0
|
|
result.theme = ifx StyleTokenColor("canvas").r < 128 then 2 else 1
|
|
result.disabled = example_disabled
|
|
result.reduced_motion = example_reduced_motion
|
|
return result
|
|
}
|
|
|
|
gallery_view: Rectangle = Rectangle.{.x = 0.0, .y = 0.0, .width = 480.0, .height = 320.0};
|
|
|
|
gallery_live: bool;
|
|
|
|
gallery_now: float32;
|
|
|
|
gallery_reduced_motion: bool;
|
|
|
|
SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion: bool) {
|
|
gallery_view = view; gallery_live = live; gallery_now = now
|
|
gallery_reduced_motion = reduced_motion
|
|
}
|
|
|
|
GalleryBounds :: (bounds: Rectangle) -> Rectangle {
|
|
if !gallery_live { return bounds }
|
|
bounds.x = gallery_view.x + bounds.x * gallery_view.width / 480.0
|
|
bounds.y += gallery_view.y
|
|
bounds.width *= gallery_view.width / 480.0
|
|
return bounds
|
|
}
|
|
|
|
installed_style: s32 = -1;
|
|
|
|
InstallStyles :: (dark: bool) {
|
|
wanted: s32 = ifx dark then 1 else 0
|
|
if wanted == installed_style { return }
|
|
installed_style = wanted
|
|
palette := Theme.DefaultPalette(dark)
|
|
rules := ActiveStyleRules()
|
|
rule: StyleRule
|
|
rule.selector = StyleDefaultSelector(); rule.selector.kind = StyleKindPlot()
|
|
rule.style.fields = cast(u32)StyleField.StyleBackground | cast(u32)StyleField.StyleForeground | cast(u32)StyleField.StyleBorder
|
|
rule.style.background = palette.surface; rule.style.foreground = palette.accent; rule.style.border = palette.border
|
|
rule.order = rules.count; rules.items[rules.count] = rule; rules.count += 1
|
|
unused InstallStyleRules(rules)
|
|
}
|
|
|
|
bounds: Rectangle;
|
|
|
|
values: [8]float32 = .{3.0, 5.0, 4.0, 8.0, 6.0, 9.0, 8.0, 11.0};
|
|
|
|
Prepare :: (session: Session, scene: s32) {
|
|
bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0})
|
|
}
|
|
|
|
#program_export
|
|
Frame :: (session: Session, viewport: Rectangle) -> s32 {
|
|
example_input := WidgetInput(session)
|
|
SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion)
|
|
Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")})
|
|
page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6),
|
|
.gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true})
|
|
if !page.opened { return 0 }
|
|
Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Plot · lines", .size = 23})
|
|
disabled := example_input.disabled
|
|
scene: s32 = 0
|
|
InstallStyles(example_input.theme == 2)
|
|
Prepare(session, scene)
|
|
unused Plot.Plot(session, Plot.PlotProps.{.bounds = bounds, .semantic_label = "Eight example values", .scale_min = 0.0, .scale_max = 12.0, .mode = cast(Plot.PlotMode)scene}, values[:])
|
|
unused End(session)
|
|
return 0
|
|
}
|
|
|
|
example_disabled: bool;
|
|
example_reduced_motion: bool;
|
|
|
|
// Hosts publish these options before the unchanged application entry point.
|
|
#program_export
|
|
SetExampleOptions :: (disabled: bool, reduced_motion: bool) {
|
|
example_disabled = disabled
|
|
example_reduced_motion = reduced_motion
|
|
}
|