plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


fa56a8b — Peter John 2026-11-16T16:23:27+05:30
declarative paint (user: "try to optimize it later"): std/game/Blend, `struct Blend[View, Touch](x = 0.0, y = 0.0, mode: Int, touch = ChildrenOnly, children: List<View>)`, its children (a block) drawn in the host's blend mode and the host back to `Blend.Normal` after them (`Views.paintDone`, in `paint` and `paintCulled`; a `Blend` under another returns to Normal), the mode constants moved from Gfx.plum's `primitive Blend` onto it (`Blend.Add`, ..: fixtures using `Gfx.blendMode` import std/game/Blend), stepped by `Views.stepIn` as a `Group` is; std/game/Line, `struct Line[View, Sized, Touch](from: Vec2, to: Vec2, width = 1.0, color = Color.White, touch = Disabled)`, drawn through the walk's transform, scale and alpha (`Line.draw`), bounds the box around the segment widened by half the width, hit within half its width (`Line.near`, Balloon Pop's `nearLine` moved there); games: the orb's glow is `Blend(x, y, mode: Blend.Add) { Circle Circle }` before its sprite, the balloon's string a `Line` first in its view (`string()`, also its hit), so no game calls `Gfx` or writes `paintSelf`, which stays for std's own kinds and as the documented escape hatch (host-API fixtures and screen_views/scale's hand variant keep it). Draw calls of both games over a 600-tick replay identical before and after (Recorder, same recording); checksum 166413027 kept. Cost, not optimised yet: Orbit Runner, native, medians of 5: update 14.05 to 14.10 ms, paint 139.5 to 146.7 ms (+5.2%: a Blend and two Circles made per orb per frame, the Blend type test after each item). Tests: tests/std/game/Blend.plum, Line.plum, host_test's aBlendWrapsItsChildrenAndALineIsDrawnThroughItsPlace (plain and culled walks); docs: game.md (views, the kinds table, the escape hatch), std.md
compiler/game/tests/fixtures/blend_line_fixture.plum ADDED
@@ -0,0 +1,48 @@
1
+ module blend_line_fixture
2
+
3
+ import std/Int
4
+ import std/Float
5
+ import std/Str
6
+ import std/Io
7
+ import std/collections/List
8
+ import std/math/Vec2
9
+ import std/game/Color
10
+ import std/game/View
11
+ import std/game/Box
12
+ import std/game/Circle
13
+ import std/game/Blend
14
+ import std/game/Line
15
+ import std/game/Group
16
+ import std/game/Input
17
+ import std/game/Screen
18
+ import std/game/ScreenSlice
19
+ import std/game/Game
20
+ import std/App
21
+
22
+ # A 1000 by 600 world, one unit a pixel in a window that size: an additive glow at
23
+ # (100, 50) holding a multiplied circle, a line under a group scaled by nothing, a box.
24
+ # C makes the screen cull, so it takes the culled walk.
25
+ struct BlendScreen[ScreenSlice<Bool>](cull: Bool) =
26
+ fun name(self) -> Str = "blend"
27
+
28
+ fun size(self) -> Vec2 = Vec2(x: 1000.0, y: 600.0)
29
+
30
+ fun culls(self) -> Bool = self.cull
31
+
32
+ fun view(self) -> List<View> = [
33
+ Blend(x: 100.0, y: 50.0, mode: Blend.Add) {
34
+ Circle(r: 10.0, color: Color(r: 1.0, g: 0.0, b: 0.0, a: 0.5))
35
+ Blend(mode: Blend.Multiply) { Circle(x: 5.0, r: 4.0, color: Color.Blue) }
36
+ }
37
+ Group(x: 10.0, y: 20.0) { Line(from: Vec2(x: 0.0, y: 0.0), to: Vec2(x: 30.0, y: 40.0), width: 2.0, color: Color.Green) }
38
+ Box(x: 1.0, y: 2.0, w: 3.0, h: 4.0, color: Color.Red)
39
+ ]
40
+
41
+ fun subscriptions(self) -> List<Sub<Bool>> = [OnKeyDown(key: Key.KeyC, act: true)]
42
+
43
+ fun update(self, c: Bool) -> Next<BlendScreen, Bool> = Next(state: BlendScreen(cull: c))
44
+
45
+ primitive BlendLineFixture[App] =
46
+ fun main(io: Io) -> Game =
47
+ s: Screen := BlendScreen(cull: false)
48
+ Game(screens: [s])
compiler/game/tests/fixtures/target_fixture.plum CHANGED
@@ -6,6 +6,7 @@ import std/Str
6
6
  import std/math/Vec2
7
7
  import std/game/Color
8
8
  import std/game/Gfx
9
+ import std/game/Blend
9
10
  import std/Io
10
11
  import std/game/Input
11
12
  import std/math/Affine
compiler/game/tests/host_test.rs CHANGED
@@ -925,3 +925,33 @@ fn theBridgeLaysTextOutByLabelsAdvances() {
925
925
  assert!(table.bytes().all(|b| b.is_ascii_digit()));
926
926
  assert_eq!(quoted(&bridge, "const ADVANCES ="), table);
927
927
  }
928
+
929
+ /// A `Blend` sets the host's blend mode around its children and returns it to Normal
930
+ /// after them (an inner one returns to Normal too), and a `Line` is drawn through its
931
+ /// holder's transform, in both the culled walk and the plain one.
932
+ #[test]
933
+ fn aBlendWrapsItsChildrenAndALineIsDrawnThroughItsPlace() {
934
+ let mut rec = Recorder::new();
935
+ rec.screen = (1000.0, 600.0);
936
+ let mut g = PlumGame::load(&fixtureOut("blend_line_fixture.plum").wasm, rec).expect("load game");
937
+ g.init().expect("main");
938
+ g.update(1.0 / 60.0).unwrap();
939
+ let want = [
940
+ "blendMode(1)",
941
+ "drawCircle(100,50,10,1,0,0,0.5)",
942
+ "blendMode(2)",
943
+ "drawCircle(105,50,4,0,0,1,1)",
944
+ "blendMode(0)",
945
+ "blendMode(0)",
946
+ "drawLine(10,20,40,60,2,0,1,0,1)",
947
+ "drawRect(1,2,3,4,1,0,0,1)",
948
+ ];
949
+ let mut drawn = |g: &mut PlumGame<Recorder>| -> Vec<String> {
950
+ g.backend_mut().calls.clear();
951
+ g.draw().unwrap();
952
+ g.backend().calls.iter().filter(|c| c.starts_with("draw") || c.starts_with("blend")).cloned().collect()
953
+ };
954
+ assertCallsNear(&drawn(&mut g), &want);
955
+ tapKey(&mut g, 67);
956
+ assertCallsNear(&drawn(&mut g), &want);
957
+ }
compiler/game/web-test/fixtures/rendertarget.plum CHANGED
@@ -20,6 +20,7 @@ import std/Float
20
20
  import std/math/Vec2
21
21
  import std/game/Color
22
22
  import std/game/Gfx
23
+ import std/game/Blend
23
24
  import std/Io
24
25
  import std/game/Input
25
26
  import std/math/Affine
docs/game.md CHANGED
@@ -142,7 +142,7 @@ trait Actor[View] = # acts: state that advan
142
142
  fun step(self, dt: Float) -> Self
143
143
  ```
144
144
 
145
- `place` is its `Place` (`std/game/Place`: position, rotation, scale, the origin it turns about and its `alpha`); `view` is what is under it, ready-made items placed in its coordinates; `visible` hides it, with what is under it, from the draw and from presses; `paintSelf` is what it draws itself, before its view, for what no ready-made view draws (an additive glow, a line): it draws with `Gfx` through `m`, its own coordinates to the world's, at `alpha` (Orbit Runner's `Orb`, Balloon Pop's `Balloon`, whose string is a line). Its other fields are plain and public. `step` returns the actor's next version, `dt` seconds on. The ready-made views (`Group`, `Box`, `Circle`, `Sprite`, `Label`, `Overlay`) are stateless and never stepped.
145
+ `place` is its `Place` (`std/game/Place`: position, rotation, scale, the origin it turns about and its `alpha`); `view` is what is under it, ready-made items placed in its coordinates; `visible` hides it, with what is under it, from the draw and from presses; `paintSelf` is what it draws itself, before its view: std's own kinds draw their shape there (`Box.draw`, `Circle.draw`, ..). A game says what it draws in its `view`, with the ready-made views: Orbit Runner's orb glow is a `Blend(mode: Blend.Add)` of two `Circle`s under its sprite, Balloon Pop's string a `Line`, so no game calls `Gfx` or writes `paintSelf`. It stays as the escape hatch for what no ready-made view draws: it draws with `Gfx` through `m`, its own coordinates to the world's, at `alpha` (`m.apply(p)` is where a point of its own lands, `m.scaleX()` how much its sizes grow), as `Line.draw` does. Its other fields are plain and public. `step` returns the actor's next version, `dt` seconds on. The ready-made views (`Group`, `Box`, `Circle`, `Line`, `Sprite`, `Label`, `Blend`, `Overlay`) are stateless and never stepped.
146
146
 
147
147
  ```plum
148
148
  struct Mine[Actor, Round, Steps](body: Body, clock: Float = 0.0, tex: Texture) =
@@ -193,7 +193,7 @@ fun update(self, a: PlayAction) -> Next<PlayingScreen, PlayAction> = match a
193
193
 
194
194
  so a screen that doesn't call it steps nothing, and one that pauses (a menu over the play) skips the call. A plain screen (no slice) has no actions: its tick is its `stepped`. An `OnDemand` screen asleep steps nothing, as it gets no tick; a replay, a rewind and the kit's `tick` go through the same tick.
195
195
 
196
- An actor that lists `Steps` (`std/game/View`) has the same fields stepped after its own `step`: the compiler renames the `step` it writes `step$own` and makes `step` that and then the fields' stepping, whose conditions read the actor after its own step. When its own `step(self, dt)` is one spread of `self` that sets none of those fields and none has `@stepsWhen`, the fields' steps join that spread instead, one construction: Orbit Runner's ship writes `Ship(..self, clock: self.clock + dt)` and is compiled as `Ship(..self, clock: self.clock + dt, body: self.body.step(dt))`. So a container actor writes only what is special about itself, or no `step` at all when it is only what it holds (clicks' `Ball[Actor, Steps](body: Body)`). An actor that doesn't list `Steps` steps what it holds itself, in its own `step`. `Views.stepIn` steps each `Actor` of a `List<View>` and each one a `Group` or an `Overlay` in it holds, the others as they are; it doesn't look inside an actor, nor make its view; any other view of your own that holds actors is passed over, so make it an `Actor` that steps them. A `List<View>` field is stepped with `Views.stepIn`: it holds views of any kind, so each item is tested for being an `Actor` (or a `Group` or an `Overlay`) as it is stepped, the one place the stepping looks at an item's type at run time (`benchmarks/screen_views/scale.plum`'s `CrowdScreen`, 10,000 actors in a `List<View>`). An actor left out of the stepping is not stepped, whether it is in the view or not, and one stepped moves whether it is visible or not.
196
+ An actor that lists `Steps` (`std/game/View`) has the same fields stepped after its own `step`: the compiler renames the `step` it writes `step$own` and makes `step` that and then the fields' stepping, whose conditions read the actor after its own step. When its own `step(self, dt)` is one spread of `self` that sets none of those fields and none has `@stepsWhen`, the fields' steps join that spread instead, one construction: Orbit Runner's ship writes `Ship(..self, clock: self.clock + dt)` and is compiled as `Ship(..self, clock: self.clock + dt, body: self.body.step(dt))`. So a container actor writes only what is special about itself, or no `step` at all when it is only what it holds (clicks' `Ball[Actor, Steps](body: Body)`). An actor that doesn't list `Steps` steps what it holds itself, in its own `step`. `Views.stepIn` steps each `Actor` of a `List<View>` and each one a `Group`, a `Blend` or an `Overlay` in it holds, the others as they are; it doesn't look inside an actor, nor make its view; any other view of your own that holds actors is passed over, so make it an `Actor` that steps them. A `List<View>` field is stepped with `Views.stepIn`: it holds views of any kind, so each item is tested for being an `Actor` (or a `Group`, a `Blend` or an `Overlay`) as it is stepped, the one place the stepping looks at an item's type at run time (`benchmarks/screen_views/scale.plum`'s `CrowdScreen`, 10,000 actors in a `List<View>`). An actor left out of the stepping is not stepped, whether it is in the view or not, and one stepped moves whether it is visible or not.
197
197
 
198
198
  Once Orbit Runner's run is over its ship, orbs and mines stand still under the game over panel, while the stars, which read the screen's clock, keep twinkling, and the ship is left out of the view; the rings, with no condition, step on, so the ripple of the last hit grows on under the panel.
199
199
 
@@ -209,22 +209,24 @@ What else a view is, it says with a small trait:
209
209
  | `Round` (`std/game/Round`) | `radius(self) -> Float`: it is the circle of that radius about its pivot (`Place.pivot`). `touches(self, other: Round) -> Bool`, given, is whether the two circles overlap (closer than the sum of the radii, centre to centre) |
210
210
  | `Touch` (`std/game/Touch`) | `touch(self) -> Touchable`: whether it takes presses. `Enabled`: it is hit where it is (when it is `Sized`) and what is under it is; `Disabled`: neither it nor anything under it is hit; `ChildrenOnly`: what is under it is, it is not. A view that says nothing is `ChildrenOnly` |
211
211
 
212
- The ready-made kinds are made with their fields named, and their fields have defaults for the usual (see [field defaults](language.md#structs)): a construction names only the others, `Label(x: 16.0, y: 12.0, text: "Score")`. Text and shapes are decoration (`Disabled`). A colour's alpha is the colour's: a box in a half-transparent red paints at half alpha. Each turns with its place: a box and a label in a turned group are drawn turned (`Gfx.drawRectEx`, `Gfx.drawTextEx`). Their `Box.draw`, `Circle.draw`, `Sprite.draw` and `Label.draw` paint the same shapes for your own kinds.
212
+ The ready-made kinds are made with their fields named, and their fields have defaults for the usual (see [field defaults](language.md#structs)): a construction names only the others, `Label(x: 16.0, y: 12.0, text: "Score")`. Text and shapes are decoration (`Disabled`). A colour's alpha is the colour's: a box in a half-transparent red paints at half alpha. Each turns with its place: a box and a label in a turned group are drawn turned (`Gfx.drawRectEx`, `Gfx.drawTextEx`). Their `Box.draw`, `Circle.draw`, `Line.draw`, `Sprite.draw` and `Label.draw` paint the same shapes for your own kinds.
213
213
 
214
214
  | Kind | Fields | Defaults |
215
215
  |---|---|---|
216
216
  | `Group` | `x, y, touch, children`: a parent that paints nothing; its children (its block) are its `view` | `x: 0.0, y: 0.0, touch: ChildrenOnly` |
217
217
  | `Box` | `x, y, w, h, color, touch` (x, y its top-left) | `x: 0.0, y: 0.0, touch: Disabled` |
218
218
  | `Circle` | `x, y, r, color, touch` (x, y its centre: its bounds are -r to r) | `x: 0.0, y: 0.0, touch: Disabled` |
219
+ | `Line` | `from, to, width, color, touch`: the segment from `from` to `to` in its holder's coordinates, `width` wide as its holder scales it; its bounds are the box around the segment widened by half the width, and it is hit within half its width of the segment (`Line.near(a, b, width, p)`, which a balloon's `hit` uses for its string) | `width: 1.0, color: Color.White, touch: Disabled` |
219
220
  | `Sprite` | `x, y, tex, w, h, srcX, srcY, srcW, srcH, frame, tint, touch`; `frame` picks the cell along a strip of `srcW`-wide cells from (`srcX`, `srcY`), and `Sprite.frameAt(clock, fps, count)` is the frame of a looping strip at a clock | `x: 0.0, y: 0.0, frame: 0, tint: Color.White, touch: Disabled` |
220
221
  | `Label` | `x, y, text, size, color, align, touch`; `align` puts the text's start (`Left`), middle (`Centre`) or end (`Right`) on `x`, by its width in the font the hosts draw with (`Label.textWidth`: Arial's advance widths, which the browser lays the text out by, so the bounds are what is drawn) | `x: 0.0, y: 0.0, size: 20.0, color: Color.White, align: Left, touch: Disabled` |
222
+ | `Blend` | `x, y, mode, touch, children`: a parent that draws its children (its block) in the host's blend mode `mode`, one of its constants `Blend.Normal`, `Add` (brightens), `Multiply` (darkens) and `Screen` (lightens), and then returns the host to `Normal` (a `Blend` under another returns to `Normal`, not to the outer mode); never hit itself, no bounds | `x: 0.0, y: 0.0, touch: ChildrenOnly` |
221
223
  | `Overlay` | `x, y, w, h, color, touch, children`: a panel that dims what is under it and takes every press inside it, left out of the view while it should not show; its children are its block | `x: 0.0, y: 0.0, color: Overlay.Shade` (black at 0.6 alpha), `touch: Enabled` |
222
224
 
223
225
  Every kind is at the origin of what it is in unless given an `x` and a `y`: an actor's own view draws at the actor's place (`Sprite(tex: self.tex, ..)`). A kind of your own that takes children has a `children: List<View>` field, last so that a block fills it, and returns it from `view`.
224
226
 
225
227
  ### How std draws a view
226
228
 
227
- The game draws the shown screen once per frame (`Game.draw`): it clears with the screen's `background()` and draws the screen's `view()`, made for the frame, through its camera's transform (the world to the window's pixels) with `Views.paint`: each visible item through its place, its `paintSelf` and then its own view, multiplying the alphas down. A screen that `culls()` is drawn with `Views.paintCulled`, which skips each `Sized` item whose bounds miss what the camera shows, with what is under it. Then the screen's `hud(window)` is drawn one unit a pixel. During a transition both screens are drawn this way, each on its own background, moved and faded. `Game.drawList()` lists what a frame draws, each item with its transform and alpha (`Drawn`), culled as the frame is, the hud's after the view's; std/game/TestRig reads it.
229
+ The game draws the shown screen once per frame (`Game.draw`): it clears with the screen's `background()` and draws the screen's `view()`, made for the frame, through its camera's transform (the world to the window's pixels) with `Views.paint`: each visible item through its place, its `paintSelf` and then its own view, multiplying the alphas down (after a `Blend`'s view, the blend mode goes back to `Normal`). A screen that `culls()` is drawn with `Views.paintCulled`, which skips each `Sized` item whose bounds miss what the camera shows, with what is under it. Then the screen's `hud(window)` is drawn one unit a pixel. During a transition both screens are drawn this way, each on its own background, moved and faded. `Game.drawList()` lists what a frame draws, each item with its transform and alpha (`Drawn`), culled as the frame is, the hud's after the view's; std/game/TestRig reads it.
228
230
 
229
231
  Nothing is kept between frames, and there is no tree: the game keeps the screens and their state, the camera's inputs (each screen's `size()`, `viewport()` and `camera`, the window's size) and the transition, and works out the rest when it needs it. One walk goes over a view for everything (draw, cull, list, hit test, find): an item, then its `view()`. The walks are the statics of `Views` in `std/game/View` (`paint`, `paintCulled`, `drawnIn`, `hitIn`, `worldIn`), with `stepAll`, `stepSome` and `stepIn` for a derived stepping.
230
232
 
@@ -313,7 +315,7 @@ Three files of `std/game` talk to the host. Each host call takes `io` first.
313
315
  | Images | `Texture.load(io, name)` gives a `Texture` with `draw(io, x, y)`, `width(io)`, `height(io)`, `setSmooth(io, smooth)`; `drawTextureEx(io, t.id, sx, sy, sw, sh, x, y, w, h, rotation, flipX, tint)` |
314
316
  | Camera | `setCamera(io, x, y, scale)`, `resetCamera(io)` |
315
317
  | Draw into an image | `Texture.create(io, w, h)`, `t.renderTarget(io)`, `renderToScreen(io)` |
316
- | Blending | `blendMode(io, m)` with `Blend.Normal`, `Blend.Add`, `Blend.Multiply`, `Blend.Screen` |
318
+ | Blending | `blendMode(io, m)` with `Blend.Normal`, `Blend.Add`, `Blend.Multiply`, `Blend.Screen` (`std/game/Blend`'s constants; in a view, a `Blend` sets and restores it) |
317
319
  | Files | `loadFile(io, name)`, the file's text; `fileExists(io, name)` |
318
320
 
319
321
  **`std/game/Input`:** keyboard, mouse and touch. The events are the input: a tick's input is an `Input(events, held, screen)`, a value, its `InputEvent`s in the order they came and what is held after them, a fold of them (`Held.after(e)`, `held.afterAll(events)`) over what was held before. A slice's subscriptions and `onPress` get the events one at a time, and its `OnHeld` gets the `Held`. No press or release is read from what is held: a key going down is its `KeyDown` (`e.isKeyDownOf(k)`), a click its `PointerDown`.
docs/std.md CHANGED
@@ -273,7 +273,7 @@ Tests live in the `tests/` mirror of the code (std's in `tests/std/...`), as the
273
273
 
274
274
  ## Game screens and slices
275
275
 
276
- A game (`std/game/Game`) is a list of screens. A screen (`std/game/Screen`) has a name and a `view(self) -> List<View>`, what the frame shows, made again from its fields every frame (`std/game/View`: stateless views, and actors, `Actor[View]`, with `step(self, dt) -> Self`, which a screen steps through its `stepped(dt)`, derived for every screen from its fields holding actors, a `List<View>` among them), and may have a `hud(window)` drawn over it one unit a pixel and a `camera(base)` (`Viewport.lookAt`); a screen with rules is a `ScreenSlice<A>` (`std/game/ScreenSlice`), in the Elm style: its fields are its state, `A` its actions, `update(self, a) -> Next<Self, A>` its one entry point (pure, with no `Io`, so the same actions from the same state give the same state), returning the next screen with what follows: the actions that follow and the commands for the game (`std/game/Cmd`: a sound, `GoTo(name: "play")`), done after the tick. Its `subscriptions(self) -> List<Sub<A>>` say which of each tick's input (`std/game/Input`: its events, and what is held after them, `Held`, their fold) and which frames become its actions: `OnFrame(|dt| ..)`, `OnKeyDown(key:, act:)`, `OnKeyUp`, `OnHeld(|h| ..)`, `OnWheel`, `OnPointerDown`, `OnPointerUp`, `OnPointerMove`, read once a tick; a press on an item that says what it means, a `Presses<A>` such as a `Button` from `std/game/Button`, is that action by default. The frame is an action: the screen steps its actors in it. std keeps the screen each `update` returns. An actor's motion is a `Body` (`std/game/Body`): `pos`, `vel`, `push`, `drag`, `edge` (`Free`, `Halt(box)`, `Bounce(box)`, `Wrap(box)`, a `Walls`), `angle`, `turn` and `faceAbove`, declared, with `step(dt)` written once in std and `place(origin)` where to draw it; a field holding one is stepped by the screen's derived `stepped` or an actor's `Steps` (any field whose type has `step(self, dt: Float) -> Self`). An actor that lists `Round` (`std/game/Round`) declares its `radius()` and is that circle about its pivot (`Place.pivot`, the point its place turns about), and `a.touches(b)` is whether two round actors overlap; under it, `Vec2.near(other, dist)` (`std/math/Vec2`) is the overlap test of two circles (`a.near(b, ra + rb)`). A run records as a `Replay` (`std/game/Replay`: the seed and a `List<Input>`, one a tick). All of it is in [the game engine](game.md).
276
+ A game (`std/game/Game`) is a list of screens. A screen (`std/game/Screen`) has a name and a `view(self) -> List<View>`, what the frame shows, made again from its fields every frame (`std/game/View`: stateless views, the ready-made `Group`, `Box`, `Circle`, `Line`, `Sprite`, `Label`, `Blend` (its children in a blend mode) and `Overlay`, and actors, `Actor[View]`, with `step(self, dt) -> Self`, which a screen steps through its `stepped(dt)`, derived for every screen from its fields holding actors, a `List<View>` among them), and may have a `hud(window)` drawn over it one unit a pixel and a `camera(base)` (`Viewport.lookAt`); a screen with rules is a `ScreenSlice<A>` (`std/game/ScreenSlice`), in the Elm style: its fields are its state, `A` its actions, `update(self, a) -> Next<Self, A>` its one entry point (pure, with no `Io`, so the same actions from the same state give the same state), returning the next screen with what follows: the actions that follow and the commands for the game (`std/game/Cmd`: a sound, `GoTo(name: "play")`), done after the tick. Its `subscriptions(self) -> List<Sub<A>>` say which of each tick's input (`std/game/Input`: its events, and what is held after them, `Held`, their fold) and which frames become its actions: `OnFrame(|dt| ..)`, `OnKeyDown(key:, act:)`, `OnKeyUp`, `OnHeld(|h| ..)`, `OnWheel`, `OnPointerDown`, `OnPointerUp`, `OnPointerMove`, read once a tick; a press on an item that says what it means, a `Presses<A>` such as a `Button` from `std/game/Button`, is that action by default. The frame is an action: the screen steps its actors in it. std keeps the screen each `update` returns. An actor's motion is a `Body` (`std/game/Body`): `pos`, `vel`, `push`, `drag`, `edge` (`Free`, `Halt(box)`, `Bounce(box)`, `Wrap(box)`, a `Walls`), `angle`, `turn` and `faceAbove`, declared, with `step(dt)` written once in std and `place(origin)` where to draw it; a field holding one is stepped by the screen's derived `stepped` or an actor's `Steps` (any field whose type has `step(self, dt: Float) -> Self`). An actor that lists `Round` (`std/game/Round`) declares its `radius()` and is that circle about its pivot (`Place.pivot`, the point its place turns about), and `a.touches(b)` is whether two round actors overlap; under it, `Vec2.near(other, dist)` (`std/math/Vec2`) is the overlap test of two circles (`a.near(b, ra + rb)`). A run records as a `Replay` (`std/game/Replay`: the seed and a `List<Input>`, one a tick). All of it is in [the game engine](game.md).
277
277
 
278
278
  ```plum
279
279
  import std/Int
examples/games/balloonpop/actors/Balloon.plum CHANGED
@@ -4,19 +4,17 @@ import std/Int
4
4
  import std/Float
5
5
  import std/Bool
6
6
  import std/Str
7
- import std/Io
8
7
  import std/collections/List
9
8
  import std/math/Aabb
10
- import std/math/Affine
11
9
  import std/math/Random
12
10
  import std/math/Vec2
13
11
  import std/math/Math
14
12
  import std/game/Color
15
- import std/game/Gfx
16
13
  import std/game/Place
17
14
  import std/game/Body
18
15
  import std/game/View
19
16
  import std/game/Circle
17
+ import std/game/Line
20
18
  import std/game/Label
21
19
  import std/game/Sized
22
20
  import std/game/Touch
@@ -62,13 +60,14 @@ struct Balloon[Actor, Sized, Touch, Presses<PopAction>, Steps](
62
60
 
63
61
  fun hit(self, p: Vec2) -> Bool =
64
62
  r := Balloon.Radius
65
- Math.hypot(p.x, p.y) <= r || Math.hypot(p.x, p.y - {r + 2.0}) <= 6.0 || nearLine(0.0, r, self.stringX(), r * 2.6, 2.0, p.x, p.y)
63
+ Math.hypot(p.x, p.y) <= r || Math.hypot(p.x, p.y - {r + 2.0}) <= 6.0 || self.string().hit(p)
66
64
 
67
65
  fun view(self) -> List<View> =
68
66
  hue := Hue.of(self.hue)
69
67
  r := Balloon.Radius
70
68
  if !self.popped()
71
69
  [
70
+ self.string()
72
71
  Circle(y: r + 2.0, r: 6.0, color: hue.color)
73
72
  Circle(r: r, color: hue.color)
74
73
  Circle(x: -r * 0.35, y: -r * 0.4, r: r * 0.22, color: Color.White.withAlpha(0.55))
@@ -82,20 +81,9 @@ struct Balloon[Actor, Sized, Touch, Presses<PopAction>, Steps](
82
81
  ..Range.until(0, 8).map(|i| spark(i, reach, hue.color.withAlpha(fade)))
83
82
  ]
84
83
 
85
- fun paintSelf(self, io: Io, m: Affine, alpha: Float) =
84
+ fun string(self) -> Line =
86
- if !self.popped()
87
- r := Balloon.Radius
85
+ r := Balloon.Radius
88
- a := m.apply(Vec2(x: 0.0, y: r))
89
- b := m.apply(Vec2(x: self.stringX(), y: r * 2.6))
90
- Gfx.drawLine(io, a.x, a.y, b.x, b.y, 2.0 * m.scaleX(), Color.rgb(0.35, 0.35, 0.35).withAlpha(alpha))
86
+ Line(from: Vec2(x: 0.0, y: r), to: Vec2(x: self.stringX(), y: r * 2.6), width: 2.0, color: Color.rgb(0.35, 0.35, 0.35))
91
-
92
- fun nearLine(x1: Float, y1: Float, x2: Float, y2: Float, thickness: Float, px: Float, py: Float) -> Bool =
93
- dx := x2 - x1
94
- dy := y2 - y1
95
- len2 := dx * dx + dy * dy
96
- t := if len2 != 0.0 then {{px - x1} * dx + {py - y1} * dy} / len2 else 0.0
97
- tc := t.max(0.0).min(1.0)
98
- Math.hypot(px - {x1 + dx * tc}, py - {y1 + dy * tc}) <= thickness.max(1.0) / 2.0
99
87
 
100
88
  fun spark(i: Int, reach: Float, color: Color) -> Circle =
101
89
  a := Float(i) * Float.Tau / 8.0
examples/games/orbitrunner/actors/Orb.plum CHANGED
@@ -3,10 +3,8 @@ module orbit_runner_orb
3
3
  import std/Int
4
4
  import std/Float
5
5
  import std/Bool
6
- import std/Io
7
6
  import std/collections/List
8
7
  import std/math/Vec2
9
- import std/math/Affine
10
8
  import std/math/Random
11
9
  import std/game/Color
12
10
  import std/game/Gfx
@@ -14,6 +12,8 @@ import std/game/Place
14
12
  import std/game/Body
15
13
  import std/game/View
16
14
  import std/game/Sprite
15
+ import std/game/Circle
16
+ import std/game/Blend
17
17
  import std/game/Round
18
18
  import OrbitRunner
19
19
  import actors/Ship
@@ -29,14 +29,13 @@ struct Orb[Actor, Round, Steps](id: Int, body: Body, clock: Float = 0.0, tex: Te
29
29
  fun place(self) -> Place = self.body.place(Sheet.Pivot)
30
30
 
31
31
  fun view(self) -> List<View> =
32
+ [
33
+ Blend(x: Sheet.Size / 2.0, y: Sheet.Size / 2.0, mode: Blend.Add) {
34
+ Circle(r: 26.0, color: Color(r: 0.35, g: 0.22, b: 0.0, a: 0.5))
35
+ Circle(r: 17.0, color: Color(r: 0.6, g: 0.4, b: 0.05, a: 0.5))
36
+ }
32
- [Sprite(tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock + Float(self.id) * 0.1, 8.0, 4))]
37
+ Sprite(tex: self.tex, w: Sheet.Size, h: Sheet.Size, srcX: 0.0, srcY: Sheet.Cell, srcW: Sheet.Cell, srcH: Sheet.Cell, frame: Sprite.frameAt(self.clock + Float(self.id) * 0.1, 8.0, 4))
38
+ ]
33
39
 
34
40
  fun step(self, dt: Float) -> Orb = Orb(..self, clock: self.clock + dt)
35
41
 
36
- fun paintSelf(self, io: Io, m: Affine, alpha: Float) =
37
- c := m.apply(Vec2(x: Sheet.Size / 2.0, y: Sheet.Size / 2.0))
38
- k := m.scaleX()
39
- Gfx.blendMode(io, Blend.Add)
40
- Gfx.drawCircle(io, c.x, c.y, 26.0 * k, Color(r: 0.35, g: 0.22, b: 0.0, a: 0.5 * alpha))
41
- Gfx.drawCircle(io, c.x, c.y, 17.0 * k, Color(r: 0.6, g: 0.4, b: 0.05, a: 0.5 * alpha))
42
- Gfx.blendMode(io, Blend.Normal)
std/game/Blend.plum ADDED
@@ -0,0 +1,39 @@
1
+ module std
2
+
3
+ import std/Int
4
+ import std/Float
5
+ import std/Io
6
+ import std/collections/List
7
+ import std/math/Affine
8
+ import std/game/Gfx
9
+ import std/game/Place
10
+ import std/game/View
11
+ import std/game/Touch
12
+
13
+ # A view that draws its children, placed in its coordinates from (x, y), in the blend
14
+ # mode `mode` and then returns the host to `Blend.Normal`; they are its block (its last
15
+ # field, `children`), as a `Group`'s are:
16
+ #
17
+ # Blend(mode: Blend.Add) {
18
+ # Circle(r: 26.0, color: Color(r: 0.35, g: 0.22, b: 0.0, a: 0.5))
19
+ # Circle(r: 17.0, color: Color(r: 0.6, g: 0.4, b: 0.05, a: 0.5))
20
+ # }
21
+ #
22
+ # The modes are its constants: `Normal` (alpha blending), `Add` (brightens), `Multiply`
23
+ # (darkens, white leaves the target unchanged) and `Screen` (lightens), the values
24
+ # `Gfx.blendMode` takes. A `Blend` under another `Blend` returns to `Normal` when it is
25
+ # done, not to the outer one's mode. Like a `Group` it is never hit itself (`touch` is
26
+ # `ChildrenOnly` unless given) and has no bounds.
27
+ struct Blend[View, Touch](x: Float = 0.0, y: Float = 0.0, mode: Int, touch: Touchable = ChildrenOnly, children: List<View>) =
28
+ const Normal = 0
29
+ const Add = 1
30
+ const Multiply = 2
31
+ const Screen = 3
32
+
33
+ fun place(self) -> Place = Place.at(self.x, self.y)
34
+
35
+ fun view(self) -> List<View> = self.children
36
+
37
+ fun touch(self) -> Touchable = self.touch
38
+
39
+ fun paintSelf(self, io: Io, m: Affine, alpha: Float) = Gfx.blendMode(io, self.mode)
std/game/Gfx.plum CHANGED
@@ -13,7 +13,7 @@ import std/Io
13
13
  # that has `update(self, io: Io, input: Input, dt: Float) -> Self` and `draw(self, io: Io)`;
14
14
  # `update` runs once per fixed 1/60 s tick (see `Ticker` in std/game/Game), `draw` once
15
15
  # per frame, and the state `update` returns is the next tick's `self`. Input is `std/game/Input`, sound is `std/game/Audio`. This file also
16
- # holds the `Blend` constants and the `Texture` handle. A path that escapes the asset root
16
+ # holds the `Texture` handle; the blend modes are `Blend`'s constants (std/game/Blend). A path that escapes the asset root
17
17
  # fails like a missing file. Coordinates are world units once `Gfx.setCamera` is set.
18
18
  #
19
19
  # Texture handles are -1 on failure. File and texture paths are relative to the asset
@@ -50,8 +50,8 @@ primitive Gfx =
50
50
  # the screen restores the screen's camera. The texture's contents persist between
51
51
  # frames; draw it like any texture once the screen is selected again.
52
52
  extern fun renderTarget(io: Io, t: Int)
53
- # The blend mode of the following draws: a `Blend` constant (other values are
53
+ # The blend mode of the following draws: a `Blend` constant (std/game/Blend; other
54
- # ignored). Every frame starts with `Blend.Normal`.
54
+ # values are ignored). Every frame starts with `Blend.Normal`.
55
55
  extern fun blendMode(io: Io, m: Int)
56
56
  # The texture at its natural size, top-left at (x, y).
57
57
  extern fun drawTexture(io: Io, t: Int, x: Float, y: Float, tint: Color)
@@ -75,14 +75,6 @@ primitive Gfx =
75
75
  crash missingAsset("file", name)
76
76
  fileLoad(io, name)
77
77
 
78
- # Blend modes for `blendMode`: alpha blending, additive (brightens), multiply
79
- # (darkens, white leaves the target unchanged) and screen (lightens).
80
- primitive Blend =
81
- const Normal = 0
82
- const Add = 1
83
- const Multiply = 2
84
- const Screen = 3
85
-
86
78
  # A texture handle; the id is the host's. A handle of -1 is no texture.
87
79
  struct Texture(id: Int) =
88
80
  # No texture: what a test's assets hold.
std/game/Line.plum ADDED
@@ -0,0 +1,53 @@
1
+ module std
2
+
3
+ import std/Int
4
+ import std/Float
5
+ import std/Bool
6
+ import std/Io
7
+ import std/math/Math
8
+ import std/math/Vec2
9
+ import std/math/Affine
10
+ import std/math/Aabb
11
+ import std/game/Color
12
+ import std/game/Gfx
13
+ import std/game/Place
14
+ import std/game/View
15
+ import std/game/Sized
16
+ import std/game/Touch
17
+
18
+ # A straight line from `from` to `to`, in its holder's coordinates, `width` wide (scaled
19
+ # as its place is) in `color` (painted at its alpha). Its bounds are the box around the
20
+ # segment, widened by half its width. It is decoration unless `touch: Enabled`
21
+ # (std/game/Touch), and then hit within half its width of the segment (at least half a
22
+ # unit), not its whole box.
23
+ struct Line[View, Sized, Touch](from: Vec2, to: Vec2, width: Float = 1.0, color: Color = Color.White, touch: Touchable = Disabled) =
24
+ fun place(self) -> Place = Place.at(0.0, 0.0)
25
+
26
+ fun bounds(self) -> Aabb =
27
+ h := self.width / 2.0
28
+ x := self.from.x.min(self.to.x) - h
29
+ y := self.from.y.min(self.to.y) - h
30
+ Aabb.of(x, y, {self.from.x - self.to.x}.abs() + self.width, {self.from.y - self.to.y}.abs() + self.width)
31
+
32
+ fun touch(self) -> Touchable = self.touch
33
+
34
+ fun paintSelf(self, io: Io, m: Affine, alpha: Float) = Line.draw(io, m, alpha * self.color.a, self.from, self.to, self.width, self.color)
35
+
36
+ fun hit(self, p: Vec2) -> Bool = Line.near(self.from, self.to, self.width, p)
37
+
38
+ # Whether `p` is within half of `width` (at least half a unit) of the segment from `a`
39
+ # to `b`.
40
+ fun near(a: Vec2, b: Vec2, width: Float, p: Vec2) -> Bool =
41
+ dx := b.x - a.x
42
+ dy := b.y - a.y
43
+ len2 := dx * dx + dy * dy
44
+ t := if len2 != 0.0 then {{p.x - a.x} * dx + {p.y - a.y} * dy} / len2 else 0.0
45
+ tc := t.max(0.0).min(1.0)
46
+ Math.hypot(p.x - {a.x + dx * tc}, p.y - {a.y + dy * tc}) <= width.max(1.0) / 2.0
47
+
48
+ # Draws the line from `a` to `b` seen through the transform `m`, `width` wide as `m`
49
+ # scales it. Paints with `alpha` in place of the colour's alpha, as `Box.draw` does.
50
+ fun draw(io: Io, m: Affine, alpha: Float, a: Vec2, b: Vec2, width: Float, color: Color) =
51
+ p := m.apply(a)
52
+ q := m.apply(b)
53
+ Gfx.drawLine(io, p.x, p.y, q.x, q.y, width * m.scaleX(), color.withAlpha(alpha))
std/game/View.plum CHANGED
@@ -21,6 +21,9 @@ import std/game/Group
21
21
  import std/game/Label
22
22
  import std/game/Circle
23
23
  import std/game/Overlay
24
+ import std/game/Blend
25
+ import std/game/Line
26
+ import std/game/Gfx
24
27
 
25
28
  # One thing a screen draws (std/game/Screen's `view`). Each kind of view is its own
26
29
  # struct, with only its own fields, that implements `View`. A `View` is stateless: it says
@@ -36,8 +39,10 @@ import std/game/Overlay
36
39
  # blinking off says false). Its screen's `stepped` still steps it
37
40
  # paintSelf what it draws itself, before its view, seen through `m` (its own coordinates
38
41
  # to the screen's world) at `alpha` (the accumulated alpha of its places, its
42
+ # own included): what std's own kinds draw (`Box.draw`, `Circle.draw`, ..).
39
- # own included): a ready-made shape, or what no ready-made view draws (an
43
+ # Nothing by default. A game says what it draws with ready-made views in its
40
- # additive glow, a line), with `Gfx` through `m`. Nothing by default
44
+ # `view` (a glow is a `Blend` of `Circle`s, a string a `Line`); `paintSelf`
45
+ # with `Gfx` through `m` is the escape hatch for what none of them draws
41
46
  #
42
47
  # A view whose state advances each tick (its place, its clock) is an `Actor`, which
43
48
  # extends `View` with `step(self, dt) -> Self`, its next version `dt` seconds on. A screen
@@ -59,8 +64,8 @@ import std/game/Overlay
59
64
  # Touch it says whether it takes presses (std/game/Touch: `Enabled`, `Disabled`,
60
65
  # `ChildrenOnly`); one that doesn't say is `ChildrenOnly`
61
66
  #
62
- # The ready-made views are `Group`, `Box`, `Circle`, `Sprite`, `Label` and `Overlay`, all
67
+ # The ready-made views are `Group`, `Box`, `Circle`, `Line`, `Sprite`, `Label`, `Blend`
63
- # stateless.
68
+ # (its children in a blend mode) and `Overlay`, all stateless.
64
69
  #
65
70
  # A view is drawn, not live: an item made inside `view` keeps nothing from one walk to the
66
71
  # next, so each takes plain values read from its holder's fields (`Sprite(.., frame: ..)`,
@@ -141,12 +146,14 @@ primitive Views =
141
146
  fun stepOne(x: View, dt: Float) -> View = match x
142
147
  Actor as a => a.step(dt)
143
148
  Group as g => Group(..g, children: Views.stepIn(g.children, dt))
149
+ Blend as b => Blend(..b, children: Views.stepIn(b.children, dt))
144
150
  Overlay as o => Overlay(..o, children: Views.stepIn(o.children, dt))
145
151
  _ => x
146
152
 
147
153
  # Draws the visible `items`, `m` and `alpha` being those of what holds them (the screen's
148
154
  # camera, or the view whose view they are): each through its own place under `m`, at
149
- # `alpha` times its place's alpha, its `paintSelf` and then its view.
155
+ # `alpha` times its place's alpha, its `paintSelf` and then its view (and, after a
156
+ # `Blend`'s view, the host's blend mode back to `Blend.Normal`).
150
157
  fun paint(io: Io, items: List<View>, m: Affine, alpha: Float) = items.each(|k| Views.paintItem(io, k, m, alpha))
151
158
 
152
159
  fun paintItem(io: Io, a: View, m: Affine, alpha: Float) =
@@ -156,6 +163,13 @@ primitive Views =
156
163
  ak := alpha * at.alpha
157
164
  a.paintSelf(io, mk, ak)
158
165
  Views.paint(io, a.view(), mk, ak)
166
+ Views.paintDone(io, a)
167
+
168
+ # What the walk does after `a`'s view is drawn: a `Blend` returns the host to
169
+ # `Blend.Normal`.
170
+ fun paintDone(io: Io, a: View) = match a
171
+ Blend as b => Gfx.blendMode(io, Blend.Normal)
172
+ _ => Unit
159
173
 
160
174
  # `paint`, skipping each `Sized` item whose bounds, through its transform, miss
161
175
  # `area` (in the coordinates `m` maps to), with what is under it.
@@ -168,6 +182,7 @@ primitive Views =
168
182
  ak := alpha * at.alpha
169
183
  a.paintSelf(io, mk, ak)
170
184
  Views.paintCulled(io, a.view(), mk, ak, area)
185
+ Views.paintDone(io, a)
171
186
  )
172
187
 
173
188
  # Pushes onto `out` what `items` draw, in the order drawn: each visible item with its
tests/std/game/Blend.plum ADDED
@@ -0,0 +1,57 @@
1
+ import std/Int
2
+ import std/Float
3
+ import std/Bool
4
+ import std/Str
5
+ import std/Option
6
+ import std/Slice
7
+ import std/collections/List
8
+ import std/Io
9
+ import std/math/Vec2
10
+ import std/math/Affine
11
+ import std/math/Aabb
12
+ import std/game/Color
13
+ import std/game/Place
14
+ import std/game/Sized
15
+ import std/game/Touch
16
+ import std/game/Circle
17
+ import std/game/Blend
18
+ import std/game/View
19
+ import std/Test
20
+
21
+ primitive BlendTest[UnitTest] =
22
+ # the modes are the host's blend mode numbers
23
+ fun theModesAreTheHostsNumbers() =
24
+ assert Blend.Normal == 0 && Blend.Add == 1 && Blend.Multiply == 2 && Blend.Screen == 3
25
+
26
+ # a blend's children are drawn under its place, and it is never hit itself
27
+ fun aBlendsChildrenAreDrawnUnderItsPlace() =
28
+ b := Blend(x: 10.0, y: 20.0, mode: Blend.Add) {
29
+ Circle(r: 5.0, color: Color.Red, touch: Enabled)
30
+ Circle(x: 3.0, r: 1.0, color: Color.Blue)
31
+ }
32
+ found := Slice<Drawn>()
33
+ Views.drawnIn([b], Affine.Identity, 1.0, found, Aabb.of(0.0, 0.0, 0.0, 0.0), false)
34
+ assert found.length() == 3
35
+ assert found.at(1).m.e == 10.0 && found.at(1).m.f == 20.0
36
+ assert found.at(2).m.e == 13.0
37
+ assert Views.hitIn([b], Vec2(x: 12.0, y: 20.0)).isSome()
38
+ assert Views.hitIn([b], Vec2(x: 30.0, y: 20.0)).isNone()
39
+ assert !Views.sizedHit(b, Vec2(x: 0.0, y: 0.0))
40
+
41
+ # stepping a blend steps the actors among its children
42
+ fun steppingABlendStepsItsActors() =
43
+ v := Views.stepOne(Blend(mode: Blend.Screen) { Clock(t: 0.0) }, 0.5)
44
+ t := match v
45
+ Blend as b => b.children.map(|k| BlendHelpers.timeOf(k))
46
+ _ => Nil
47
+ assert t == [0.5]
48
+
49
+ struct Clock[Actor](t: Float) =
50
+ fun place(self) -> Place = Place.at(0.0, 0.0)
51
+
52
+ fun step(self, dt: Float) -> Clock = Clock(t: self.t + dt)
53
+
54
+ primitive BlendHelpers =
55
+ fun timeOf(v: View) -> Float = match v
56
+ Clock as c => c.t
57
+ _ => -1.0
tests/std/game/Gfx.plum CHANGED
@@ -10,7 +10,3 @@ import std/Test
10
10
  primitive GfxTest[UnitTest] =
11
11
  fun aMissingAssetMessageNamesTheFile() =
12
12
  assert Gfx.missingAsset("texture", "ship.png") == "missing texture: ship.png"
13
-
14
- fun blendConstants() =
15
- assert Blend.Normal == 0
16
- assert Blend.Screen == 3
tests/std/game/Line.plum ADDED
@@ -0,0 +1,42 @@
1
+ import std/Int
2
+ import std/Float
3
+ import std/Bool
4
+ import std/Str
5
+ import std/Option
6
+ import std/Slice
7
+ import std/collections/List
8
+ import std/Io
9
+ import std/math/Vec2
10
+ import std/math/Affine
11
+ import std/math/Aabb
12
+ import std/game/Color
13
+ import std/game/Place
14
+ import std/game/Sized
15
+ import std/game/Touch
16
+ import std/game/Line
17
+ import std/game/View
18
+ import std/Test
19
+
20
+ primitive LineTest[UnitTest] =
21
+ # a line's bounds are the box around it, widened by half its width
22
+ fun aLinesBoundsAreTheBoxAroundIt() =
23
+ l := Line(from: Vec2(x: 10.0, y: 40.0), to: Vec2(x: 0.0, y: 0.0), width: 4.0)
24
+ assert l.bounds() == Aabb.of(-2.0, -2.0, 14.0, 44.0)
25
+ assert l.width == 4.0 && l.color == Color.White && l.touch == Disabled
26
+
27
+ # a line is hit within half its width of the segment, at least half a unit
28
+ fun aLineIsHitNearTheSegment() =
29
+ l := Line(from: Vec2(x: 0.0, y: 0.0), to: Vec2(x: 10.0, y: 0.0), width: 4.0)
30
+ assert l.hit(Vec2(x: 5.0, y: 1.9))
31
+ assert !l.hit(Vec2(x: 5.0, y: 2.1))
32
+ assert l.hit(Vec2(x: -1.0, y: 0.0))
33
+ assert !l.hit(Vec2(x: 12.5, y: 0.0))
34
+ assert Line.near(Vec2(x: 0.0, y: 0.0), Vec2(x: 0.0, y: 0.0), 0.0, Vec2(x: 0.4, y: 0.0))
35
+ assert !Line.near(Vec2(x: 0.0, y: 0.0), Vec2(x: 0.0, y: 0.0), 0.0, Vec2(x: 0.6, y: 0.0))
36
+
37
+ # a line takes presses only when enabled
38
+ fun aLineTakesPressesOnlyWhenEnabled() =
39
+ p := Vec2(x: 5.0, y: 5.0)
40
+ l := Line(from: Vec2(x: 0.0, y: 0.0), to: Vec2(x: 10.0, y: 10.0))
41
+ assert Views.hitIn([l], p).isNone()
42
+ assert Views.hitIn([Line(..l, touch: Enabled)], p).isSome()