86 lines
3.0 KiB
Ziran
86 lines
3.0 KiB
Ziran
#import "kryon/geometry"
|
|
#import "kryon/session"
|
|
#import "kryon/frame_snapshot"
|
|
#import "kryon/style_sheet"
|
|
Box :: #import "kryon/box";
|
|
Button :: #import "kryon/button";
|
|
Modal :: #import "kryon/modal";
|
|
Text :: #import "kryon/text";
|
|
#import "kryon/drawing_props"
|
|
#import "kryon/tree"
|
|
#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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
clicks: s32;
|
|
|
|
dismissed: bool;
|
|
|
|
Label :: (session: Session, value: string, y: float32 = 76.0) {
|
|
Text.Draw(session, Text.Props.{.bounds = GalleryBounds(Rectangle.{28.0, y, 420.0, 38.0}), .text = value})
|
|
}
|
|
|
|
b: Rectangle;
|
|
|
|
#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 = "ModalFrame", .size = 23})
|
|
b = Rectangle.{viewport.x + 24.0, viewport.y + 64.0, viewport.width - 48.0, 44.0}
|
|
disabled := example_input.disabled
|
|
|
|
b.height = 188.0
|
|
if dismissed {
|
|
if Button.Draw(session, Button.Props.{.bounds = b, .label = "Open modal again"}) == 1 { dismissed = false }
|
|
} else {
|
|
modal := Modal.Draw(session, Modal.Props.{.bounds = b, .title = "A focused moment", .right_label = "Done", .has_right_action = true})
|
|
if modal.opened { Label(session, "Keep the next step clear", 140.0); unused End(session) }
|
|
if modal.dismissed || modal.right_clicked { dismissed = true; clicks += 1 }
|
|
}
|
|
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
|
|
}
|