main is the only program entry. Frame stays an ordinary function that apps pass to App.Run; the frame-entry export mechanism (frame_entry, ProjectFrame binds, KRYON_FRAME_ENTRY, *_run.zi hosts) is gone. The pixmap, dom, terminal, zx and android frame loops are now frames_*.zi modules that App.Run selects. Consumer tests and fixtures build their own shot programs through the kryon package exports, and the desktop project probe imports Window explicitly. General #program_export component exports stay.
111 lines
3.5 KiB
Ziran
111 lines
3.5 KiB
Ziran
App :: #import "kryon/app";
|
|
#import "kryon/geometry"
|
|
#import "kryon/session"
|
|
#import "kryon/frame_snapshot"
|
|
#import "kryon/style_sheet"
|
|
Box :: #import "kryon/box";
|
|
InlineEdit :: #import "kryon/inline_edit";
|
|
Text :: #import "kryon/text";
|
|
TextField :: #import "kryon/text_field";
|
|
Layout :: #import "kryon/layout";
|
|
#import "kryon/tree"
|
|
#import "kryon/drawing_props"
|
|
#import "kryon/key_input"
|
|
#import "kryon/tree_input"
|
|
#import "kryon/input_protocol"
|
|
|
|
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
|
|
}
|
|
|
|
bounds: Rectangle;
|
|
|
|
|
|
|
|
inline_state: InlineEdit.InlineEditState;
|
|
|
|
|
|
|
|
|
|
inputs_ready: bool;
|
|
|
|
|
|
gallery_input_key: s32;
|
|
|
|
gallery_typed: [128]u8;
|
|
|
|
Prepare :: (session: Session, scene: s32) {
|
|
bounds = GalleryBounds(Rectangle.{24.0, 96.0, 432.0, 104.0})
|
|
if !inputs_ready {
|
|
inline_state = InlineEdit.InlineEditStateFor("Launch checklist")
|
|
inputs_ready = true
|
|
}
|
|
}
|
|
|
|
Frame :: (frame: App.Frame) {
|
|
session := Session.{.slot = frame.slot, .epoch = frame.epoch}
|
|
viewport := frame.viewport
|
|
gallery_input: TextField.Input
|
|
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 }
|
|
Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "InlineEdit", .size = 23})
|
|
disabled := example_input.disabled
|
|
scene: s32 = 2
|
|
Prepare(session, scene)
|
|
if !gallery_live { gallery_input.focus = true }
|
|
if gallery_live {
|
|
gallery_input_key = KeyboardTake(session)
|
|
gallery_input = TextFieldInputFor(gallery_input_key, KeyboardModifiers(session), TypedTextTake(session, gallery_typed[:]))
|
|
}
|
|
unused InlineEdit.Draw(session, InlineEdit.Props.{.bounds = bounds,
|
|
.value = "Launch checklist", .placeholder = "Document title",
|
|
.input = gallery_input, .disabled = disabled, .focus_visible = true, .height = 42.0,
|
|
.font_size = 17.0}, *inline_state)
|
|
unused End(session)
|
|
return
|
|
}
|
|
|
|
example_disabled: bool;
|
|
example_reduced_motion: bool;
|
|
|
|
// The gallery host calls this before drawing the example's frames.
|
|
SetExampleOptions :: (disabled: bool, reduced_motion: bool) {
|
|
example_disabled = disabled
|
|
example_reduced_motion = reduced_motion
|
|
}
|
|
|
|
main :: () -> s32 { return App.Run(App.Window.{.title = "inlineedit"}, Frame) }
|