Port the swipe area and transition examples

Both lay content over one area: a Stack now holds the swipe surface, its
caption and the swipe target, and the transition's fade over its text, in
a padded Layout column.

Shot digests, light theme, before -> after:
  swipearea         73f2134f0c98 -> 88e7cce61521
  transition        0497bf53627d -> 7863a2b8626b
This commit is contained in:
waozi committed 2026-11-23 01:11:53 -03:00
1 parent 56862f15da
commit 02cc10e682
2 files changed
+36 -12

No files matched your search

+21 -7
View File
@@ -1,6 +1,8 @@
Box :: #import "kryon/box";
Joystick :: #import "kryon/joystick";
Text :: #import "kryon/text";
Layout :: #import "kryon/layout";
#import "kryon/tree"
#import "kryon/drawing_props"
#import "kryon/geometry"
#import "kryon/session"
@@ -10,16 +12,28 @@ Text :: #import "kryon/text";
swipes: s32;
#program_export
Frame :: (session: Session, viewport: Rectangle) -> s32 {
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{viewport.x + 20.0, viewport.y + 16.0, viewport.width - 40.0, 40.0}, .text = "Swipe area", .size = 28})
bounds := Rectangle.{viewport.x + 20.0, viewport.y + 76.0, viewport.width - 40.0, 180.0}
page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5),
.gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true})
if !page.opened { return 0 }
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Swipe area", .size = 28})
input := CaptureFrameInput(session)
now := cast(float64)input.elapsed_ms / 1000.0
Box.Draw(session, Box.Props.{.bounds = bounds, .fill = StyleTokenColor("surface"), .radius = 12.0})
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{bounds.x + 16.0, bounds.y + 16.0, bounds.width - 32.0, 36.0}, .text = "Swipe here"})
result := Joystick.SwipeArea(session, Joystick.SwipeAreaProps.{.disabled = example_disabled, .bounds = bounds, .label = "Swipe here", .now = now})
if result.swiped >= 0 { swipes += 1 }
// A stack lays the surface, its caption and the swipe target over one area.
area := Layout.Stack(session, Layout.Props.{.bounds = .{height = 180}})
if area.opened {
Box.Draw(session, Box.Props.{.bounds = area.bounds, .fill = StyleTokenColor("surface"), .radius = 12.0})
caption := Layout.Draw(session, Layout.Props.{.padding = Layout.Gap(.ThemeMetricSpace4), .padding_override = true})
if caption.opened {
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = "Swipe here"})
unused End(session)
}
result := Joystick.SwipeArea(session, Joystick.SwipeAreaProps.{.disabled = example_disabled, .bounds = area.bounds, .label = "Swipe here", .now = now})
if result.swiped >= 0 { swipes += 1 }
unused End(session)
}
digits: [24]u8
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{bounds.x, bounds.y + 200.0, bounds.width, 36.0}, .text = FormatInteger(cast(s64)swipes, digits[:])})
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = FormatInteger(cast(s64)swipes, digits[:])})
unused End(session)
return 0
}
+15 -5
View File
@@ -1,6 +1,8 @@
Box :: #import "kryon/box";
Button :: #import "kryon/button";
Text :: #import "kryon/text";
Layout :: #import "kryon/layout";
#import "kryon/tree"
#import "kryon/geometry"
#import "kryon/session"
#import "kryon/transition"
@@ -12,12 +14,20 @@ state: TransitionState;
#program_export
Frame :: (session: Session, viewport: Rectangle) -> s32 {
input := CaptureFrameInput(session)
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{viewport.x + 20.0, viewport.y + 16.0, viewport.width - 40.0, 40.0}, .text = "Transition", .size = 28})
if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{viewport.x + 20.0, viewport.y + 76.0, 180.0, 44.0}, .label = "Animate fade"}) != 0 { state = TransitionStart(0.6) }
page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5),
.gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true})
if !page.opened { return 0 }
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Transition", .size = 28})
if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{width = 180, height = 44}, .label = "Animate fade"}) != 0 { state = TransitionStart(0.6) }
state = TransitionAdvance(state, (ifx (example_reduced_motion || DemoTheme.CurrentTheme().motion.reduced_motion) then 1.0 else cast(float32)input.delta_ms / 1000.0)).state
bounds := Rectangle.{viewport.x + 20.0, viewport.y + 144.0, viewport.width - 40.0, 128.0}
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = bounds, .text = "A transition over this content"})
Box.Draw(session, Box.Props.{.bounds = bounds, .fill = TransitionFadeColor(state, .{16, 34, 45, 180})})
// The fade lies over the content it covers.
area := Layout.Stack(session, Layout.Props.{.bounds = .{height = 128}})
if area.opened {
Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = area.bounds, .text = "A transition over this content"})
Box.Draw(session, Box.Props.{.bounds = area.bounds, .fill = TransitionFadeColor(state, .{16, 34, 45, 180})})
unused End(session)
}
unused End(session)
return 0
}