63 lines
2.5 KiB
Ziran
63 lines
2.5 KiB
Ziran
#import "kryon/geometry"
|
|
#import "kryon/session"
|
|
#import "kryon/frame_snapshot"
|
|
#import "kryon/style_sheet"
|
|
Box :: #import "kryon/box";
|
|
Shape :: #import "kryon/shape";
|
|
Text :: #import "kryon/text";
|
|
#import "kryon/drawing_props"
|
|
#import "kryon/system_theme"
|
|
#import "std/number_text"
|
|
|
|
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
|
|
}
|
|
|
|
color: [4]float32 = .{0.18, 0.52, 0.68, 1.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.{.key = 9000, .bounds = viewport, .fill = StyleTokenColor("canvas")})
|
|
Text.Draw(session, Text.Props.{.key = 9001, .bounds = .{viewport.x + 24.0, viewport.y + 12.0, viewport.width - 48.0, 36.0}, .text = "Circle Ring Triangle Line", .size = 23})
|
|
disabled := example_input.disabled
|
|
|
|
unused Shape.Circle(session, Shape.CircleProps.{.center = .{88.0, 128.0}, .radius = 38.0, .fill = .{30, 115, 138, 255}})
|
|
unused Shape.Ring(session, Shape.RingProps.{.center = .{202.0, 128.0}, .inner_radius = 27.0, .outer_radius = 38.0, .start_angle = -90.0, .end_angle = 200.0, .color = .{30, 115, 138, 255}})
|
|
unused Shape.Triangle(session, Shape.TriangleProps.{.first = .{292.0, 166.0}, .second = .{330.0, 90.0}, .third = .{368.0, 166.0}, .color = .{30, 115, 138, 255}})
|
|
unused Shape.Draw(session, Shape.Props.{.start = .{28.0, 220.0}, .end = .{432.0, 220.0}, .thickness = 2.0, .color = .{30, 115, 138, 255}})
|
|
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
|
|
}
|