nandi/jolt-nativepublic Fork 0
65272e3e9431369b8ac5bf985825fb43c8a7048a
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

core.clj · 537 lines · 23.8 KBClojure Blame HistoryRaw
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago1(ns glimmer-jvui.core
2 "A glimmer backend that renders through [jvui](../../../jvui).
3
4 glimmer owns the reactive core — ratoms, components, the reconciler — and
5 knows nothing about any toolkit. glimmer-gtk fills that in with GtkWidgets,
6 glimmer-vidya with a Rust node arena painted by egui, glimmer-gfx with a
7 software rasterizer it writes itself. This fills it in with jvui, and so is
8 the smallest of the four: everything a backend usually has to supply — the
9 measuring, the placing, the hit testing, the painting — is already a toolkit
10 one directory over.
11
12 What is left is the half an immediate-mode library does not have: a tree to
13 hold still between frames. The reconciler needs somewhere to put a widget it
14 created and to append a child to, and jvui's widgets draw and return within
15 one call. So a node here is an atom of {:tag :props :children :key}, about
16 thirty lines of it, and once a frame `emit!` walks that tree and calls the
17 jvui widget each node names.
18
19 # The walk is the closure
20
21 glimmer-vidya's README explains why its tree lives in Rust: `ScrollArea` and
22 `Frame` take an `FnOnce(&mut Ui)` and keep their begin/end private, so a
23 push/pop ABI cannot scroll a page. jvui's containers take a body function
24 for the same reason, and here the recursion *is* that function — `emit!` on
25 a container passes `emit-children!` as the body, and the nesting takes care
26 of itself.
27
28 # Why every node carries a key
29
30 jvui identifies a widget by its parent and its index among its siblings,
31 unless it is given a `:key`, which replaces the index. A reconciler reorders
32 children; an identity built on the index would hand each widget after the
33 moved one the caret, the scroll offset and the drag of whichever widget used
34 to sit at its index. So every node gets a serial number at creation and
35 passes it as its key, and the identity follows the node rather than its
36 position. That is the bug class zvui's README describes from the backend
37 side, closed here at the other end."
38 (:require [glimmer.backend :as b]
39 [jvui.app :as app]
40 [jvui.core :as c]
41 [jvui.theme :as theme]
Give jvui a picture from somewhere else, and a clock 32fae8d nandi 9d ago42 [jvui.widgets :as w]
Answer the rest of what a client asks its window 0b92f67 nandi 9d ago43 [jvui.frames :as frames]
44 [jvui.host :as host]))
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago45
46;; --- the retained tree -------------------------------------------------------
47
48(defonce ^:private serial (atom 0))
49
50(defn- create! [tag props]
51 (atom {:tag tag :props props :children [] :key (swap! serial inc)}))
52
53(defn- apply-props! [_tag n props] (swap! n assoc :props props) nil)
54(defn- append-child! [_t parent child] (swap! parent update :children conj child) nil)
55(defn- remove-child! [_t parent child]
56 (swap! parent update :children #(vec (remove #{child} %))) nil)
57(defn- replace-child! [_t parent old new]
58 (swap! parent update :children #(mapv (fn [c] (if (= c old) new c)) %)) nil)
59(defn- reorder-child! [_t parent child sibling]
60 (swap! parent update :children
61 (fn [cs]
62 (let [cs (vec (remove #{child} cs))
63 i (if (nil? sibling) 0 (inc (.indexOf cs sibling)))]
64 (vec (concat (subvec cs 0 i) [child] (subvec cs i))))))
65 nil)
66
67;; --- props -------------------------------------------------------------------
68
69(defn- txt [props] (str (or (:label props) (:text props) "")))
70
71(defn- num [v default] (if (number? v) (double v) default))
72
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago73(defn- fills-height?
74 "Does any child of `n` ask to fill the height?
75
76 A row is only as tall as what is in it, and frq marks the PANES with
77 :fill-height rather than the row that holds them — egui gives a
78 horizontal layout the available height and the panes fill that, so
79 there is nothing there to mark. Here the row has to be told, and its
80 own children are what know: a row holding something that wants the
81 height wants the height.
82
83 Asked of the tree rather than inferred from the layout, because the
84 layout answers a frame too late — a row that learns it should be tall
85 from what happened last frame is a row that is the wrong height on
86 the frame anybody looks at."
87 [n]
88 (boolean (some #(:fill-height (:props (deref %))) (:children (deref n)))))
89
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago90(defn- box-opts
91 "The container options shared by every container tag."
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago92 ([props key] (box-opts props key false))
93 ([props key fill-height?]
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago94 (cond-> {:key key
Let a container fill its parent, and report "end" as the word e72d7b0 nandi 9d ago95 :dir (if (= :horizontal (:orientation props)) :horizontal :vertical)
96 ;; A CONTAINER fills its parent's cross axis by default. Without
97 ;; this every box shrink-wraps its children, and frq's chat
98 ;; column came out a couple of hundred points wide in a
99 ;; five-hundred-point window with every message wrapped to
100 ;; match — the tree is nested boxes, and each one only as wide
101 ;; as what is in it.
102 ;;
103 ;; :cross and not :horizontal: in a ROW, :horizontal means take
104 ;; a share of the slack, and a line of buttons would stretch to
105 ;; fill the window.
106 :expand :cross}
Let the pane that fills take the room, and a viewport the height it is in 5fcbb42 nandi 9d ago107 ;; :fill-height is frq's way of saying "this is the pane that takes
108 ;; what is left". It is the messages column in the row that also
109 ;; holds the people panel, and without it that column claims no slack
110 ;; at all — the backlog ends up as wide as the widest message and the
111 ;; scrollbar sits in the middle of the window.
112 ;;
113 ;; :both rather than :vertical, despite the name: in a ROW the space
114 ;; to be taken is horizontal, and a pane that fills the height of a
115 ;; row it does not fill the width of is not what anyone means by it.
116 ;; The panes that do NOT ask for it stay :cross and keep their own
117 ;; size, which is what leaves the slack to be taken.
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago118 (or (:fill-height props) fill-height?) (assoc :expand :both)
Let the pane that fills take the room, and a viewport the height it is in 5fcbb42 nandi 9d ago119 ;; A minimum, not a size: the messages column asks for one only while
120 ;; the people panel is beside it.
121 (:width-request props)
122 (assoc :min-size [(num (:width-request props) 0.0) 0.0])
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago123 (:spacing props) (assoc :spacing (num (:spacing props) 0.0))
124 (:padding props) (assoc :padding (num (:padding props) 0.0))
125 (:margin props) (assoc :margin (num (:margin props) 0.0))
Fire :on-activate with nothing, wrap a row, and break a word that cannot fit 2271a91 nandi 9d ago126 (:expand props) (assoc :expand (:expand props))
127 ;; A row whose children start a new line when they run out of room —
128 ;; a line of reaction pills is the case that needs it.
129 (:wrap props) (assoc :wrap true)
130 ;; Cross-axis placement: :start :center :end, as a gravity.
131 (:align props) (assoc :gravity (case (:align props)
132 (:center "center") [0.0 0.5]
133 (:end "end") [0.0 1.0]
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago134 [0.0 0.0])))))
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago135
136(defn- fire! [n k & args]
137 (when-let [f (get (:props @n) k)] (apply f args)))
138
139;; --- the walk ----------------------------------------------------------------
140
141(def ^:dynamic *record-rects?*
142 "When true, each node keeps the rectangle jvui gave it, under `:rect`.
143
144 Off in a running window, where it would be a `swap!` per node per frame for
145 nobody's benefit. On under `render-once`, so a test can click the centre of
146 a button the way a person would, rather than guessing at a coordinate and
147 re-guessing every time a padding changes."
148 false)
149
150(declare emit!)
151
152(defn- record! [n id]
153 (when *record-rects?* (swap! n assoc :rect (c/rect-of id)))
154 nil)
155
wip hover card 65272e3 nandi 9d ago156(def ^:private hovering
157 "Which widgets the pointer was on last frame.
158
159 The toolkit answers `:hover?` as a state — the pointer is over this
160 rectangle — and a component wants the two EVENTS at its edges. The
161 difference is a set, and it is kept here rather than on the node because
162 a node is replaced by the reconciler and the pointer has not moved."
163 (atom #{}))
164
165(defn- hover!
166 "Turn `over?` into on-hover and on-unhover, once each per crossing.
167
168 Only on the pass that paints: hover is derived from where the pointer is
169 rather than delivered as an event, so it is true on the settling passes
170 too, and a handler called from one of those fires two or three times for
171 one crossing."
172 [n id over?]
173 (when (c/draw-pass?)
174 (let [was (contains? @hovering id)]
175 (cond
176 (and over? (not was)) (do (swap! hovering conj id) (fire! n :on-hover))
177 (and was (not over?)) (do (swap! hovering disj id) (fire! n :on-unhover))))))
178
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago179(defn- emit-children! [n]
180 (fn [_id _rect] (doseq [c (:children @n)] (emit! c))))
181
182(defn- emit!
183 "Render one node, and through it everything below it.
184
185 A widget answers what the person did to it, and that answer is turned back
186 into the callback prop the component registered — which is the whole seam
187 between an immediate-mode toolkit and a retained, callback-shaped one."
188 [n]
189 (let [{:keys [tag props key]} @n
190 s (txt props)]
191 (case tag
192 :page (w/page* (cond-> {:key key}
193 (:max-width props) (assoc :max-width (:max-width props)))
194 (emit-children! n))
195
196 (:card :frame) (w/card* (box-opts props key) (emit-children! n))
197
Make a list follow what arrives in it 95540ef nandi 9d ago198 ;; A list that follows what arrives in it. Everything here beyond
199 ;; :height is a prop frq writes and this used to drop on the floor —
200 ;; the chat did not follow new messages, and switching channels
201 ;; carried the previous one's scroll across.
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago202 ;; :expand is forced rather than left to box-opts, whose default is
203 ;; :cross — and a viewport that fills only the width asks its column
204 ;; for no height, is given none, and shows nothing at all. It is the
205 ;; one container that always fills both ways.
206 :scroll (w/scroll* (cond-> (assoc (box-opts props key) :expand :both)
Make a list follow what arrives in it 95540ef nandi 9d ago207 (:height props)
208 (assoc :height (num (:height props) 200.0))
209 (:reserve props)
210 (assoc :reserve (num (:reserve props) 0.0))
211 (:scroll-key props)
212 (assoc :scroll-key (str (:scroll-key props)))
213 (:stick-to-bottom props)
214 (assoc :stick-to-bottom true)
215 (:scroll-to-bottom props)
216 (assoc :scroll-to-bottom (num (:scroll-to-bottom props) 0.0))
Let a container fill its parent, and report "end" as the word e72d7b0 nandi 9d ago217 ;; "end" or "away", the STRING libvidya emits —
218 ;; frq's handler is (= "end" %) and a boolean
219 ;; makes it permanently false.
220 ;;
221 ;; :on-scroll is deliberately not fired here.
222 ;; It is the channel for backends that report an
223 ;; OFFSET rather than a place — the terminal's —
224 ;; and frq turns one into the other with
225 ;; `scrolled!`. A window that reports where it
226 ;; ended up has nothing to say on it.
227 (:on-change props)
Make a list follow what arrives in it 95540ef nandi 9d ago228 (assoc :on-at-end
229 (fn [at-end?]
Let a container fill its parent, and report "end" as the word e72d7b0 nandi 9d ago230 (fire! n :on-change (if at-end? "end" "away")))))
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago231 (emit-children! n))
232
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago233 :hbox (c/box* (assoc (box-opts props key (fills-height? n)) :dir :horizontal)
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago234 (emit-children! n))
235
Fill the window's height, and find a glyph the UI font has not got 7d907d0 nandi 9d ago236 (:vbox :box) (c/box* (box-opts props key (fills-height? n))
237 (emit-children! n))
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago238
Take the eight tags a client still had nowhere to put d5dfd53 nandi 9d ago239 ;; ONE tag for both kinds of picture: `:feed` is live pixels pushed
240 ;; in under a name and re-uploaded as they arrive, `:src` is a file
241 ;; decoded once and kept by path. Everything downstream — the fit, the
242 ;; bounds, the click — is the same, which is why libvidya makes this a
243 ;; prop and not a second tag, and why frq writes [:image {:feed k}]
244 ;; for a call tile and [:image {:src p}] for an attachment.
245 ;;
246 ;; The pixels never go through the reconciler either way: a frame
247 ;; arrives when the network says so, and a props diff at thirty a
248 ;; second would be a re-render per frame per peer.
249 :image (let [id (c/next-id key)
250 rect (w/image {:feed (:feed props) :src (:src props)}
251 {:fit (:fit props)
252 :max-width (:max-width props)
253 :max-height (:max-height props)
254 :size (:size props)
255 :expand (:expand props)})]
256 (record! n id)
257 (when (:clicked? (c/interact! id rect)) (fire! n :on-click)))
258
259 :title-2 (w/title-2 s)
260
261 :status (w/status s (boolean (:live props)))
262
263 :spinner (w/spinner s)
264
265 :link (let [id (c/next-id key)]
266 (record! n id)
267 (when (w/link s {:key key}) (fire! n :on-click)))
268
269 :emoji (w/emoji (or (:emoji props) s) (:size props))
270
271 :avatar (w/avatar (or (:label props) s)
272 (cond-> {}
273 (:src props) (assoc :src (:src props))
274 (:size props) (assoc :size (:size props))))
275
276 :reaction (let [id (c/next-id key)
wip hover card 65272e3 nandi 9d ago277 glyph (or (:emoji props) s)
278 r (w/reaction glyph {:count (or (:count props) 0)
Take the eight tags a client still had nowhere to put d5dfd53 nandi 9d ago279 :mine? (boolean (:mine props))
280 :size (:size props)
wip hover card 65272e3 nandi 9d ago281 :key key})]
282 (record! n id)
283 (when (:clicked? r) (fire! n :on-click))
284 (hover! n id (:hover? r))
285 ;; Whatever the client hung under the pill is its hover
286 ;; card, and a card is drawn over the row rather than in
287 ;; it — see c/overlay!. Under the pill and a little to its
288 ;; right, which is where a pointer that is on the pill is
289 ;; not.
290 (when (and (:hover? r) (seq (:children @n)))
291 (let [[x y _ h] (:rect r)]
292 (c/overlay! id [x (+ y h 4.0)]
293 #(w/card* {:expand :none :key id}
294 (emit-children! n))))))
Give jvui a picture from somewhere else, and a clock 32fae8d nandi 9d ago295
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago296 :title (w/title s)
297
298 :label (if (:dim props) (w/dim-label s) (w/label s))
299 :dim-label (w/dim-label s)
300
301 :button (let [id (c/next-id key)
302 hit? (w/button s {:key key :kind (or (:kind props) :normal)})]
303 (record! n id)
304 (when hit? (fire! n :on-click)))
305
Take :checkbutton, which is :checkbox under another name 26defff nandi 9d ago306 ;; :checkbutton is the same widget under GTK's name for it, which is
307 ;; what libvidya calls it too — `"checkbutton" | "checkbox"` is one
308 ;; arm of its tag table. frq writes both.
Read :active, and keep a field's text inside the field c131fc6 nandi 9d ago309 ;; :active is what frq and libvidya call it — `props.bool("active")`
310 ;; in libvidya's tag table — and :checked is what this backend called
311 ;; it first. Both are read, because a client written against either
312 ;; should not render a permanently empty tick; :active wins where
313 ;; both appear.
314 ;;
315 ;; Likewise both events fire. libvidya emits "toggled"; :on-change is
316 ;; what the checkbox here answered to before.
317 (:checkbox :checkbutton)
318 (let [was (boolean (if (contains? props :active)
319 (:active props)
320 (:checked props)))
321 id (c/next-id key)
322 now (w/checkbox was s {:key key})]
323 (record! n id)
324 (when (not= now was)
325 (fire! n :on-toggled now)
326 (fire! n :on-change now)))
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago327
328 :slider (let [was (num (:value props) 0.0)
329 id (c/next-id key)
330 now (w/slider was {:key key
331 :min (num (:min props) 0.0)
332 :max (num (:max props) 100.0)})]
333 ;; == and not not=, because a component holding a long 0 must
334 ;; not be told every frame that its slider moved to 0.0
335 (record! n id)
336 (when-not (== now was) (fire! n :on-change now)))
337
338 (:entry :text-entry)
339 (let [was (str (or (:value props) (:text props) ""))
340 id (c/next-id key)
Report Enter from a field, and take its width request c03a752 nandi 9d ago341 now (w/text-entry was {:key key
342 :placeholder (:placeholder props)
343 ;; :width-request is what frq and
344 ;; libvidya call a minimum width;
345 ;; :hexpand says take the rest of the
346 ;; row, which is this widget's default.
347 :min-width (:width-request props)
348 :expand (if (false? (:hexpand props))
349 :none :horizontal)})]
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago350 (record! n id)
Report Enter from a field, and take its width request c03a752 nandi 9d ago351 (when (not= now was) (fire! n :on-change now))
352 ;; Enter, which a field must not swallow as input: frq sends its
353 ;; message on it, and without this the compose box accepted text
354 ;; and had no way to say it was finished.
Fire :on-activate with nothing, wrap a row, and break a word that cannot fit 2271a91 nandi 9d ago355 ;;
356 ;; NO ARGUMENT. libvidya emits activate with an empty string, and
357 ;; frq's handlers are thunks — `s/send-draft!` takes none, and
358 ;; handing it the text is an arity error the moment somebody
359 ;; presses Enter. The text is already theirs; they got it from
360 ;; :on-change.
361 (when (w/entry-activated? id) (fire! n :on-activate)))
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago362
363 :progress (w/progress (num (:value props) 0.0))
364 :separator (w/separator)
365 (:spacer :gap) (w/spacer {:size (num (:size props) 8.0)
366 :expand (:expand props :none)})
367
368 ;; An unknown tag is a container rather than an error, so a tree written
369 ;; against a richer backend still shows its contents here — the same
370 ;; bargain jolt-zvui makes with the tags it does not know.
371 (c/box* (box-opts props key) (emit-children! n)))))
372
373;; --- the loop ----------------------------------------------------------------
374
375(defonce ^:private pending (atom []))
376
377(defn- schedule! [work] (swap! pending conj work) nil)
378
Give jvui a picture from somewhere else, and a clock 32fae8d nandi 9d ago379;; --- timers -----------------------------------------------------------------
380;; A client needs somewhere to run work that is not a reaction to anything:
381;; frq drives its whole media plane from `(every! 16 pump!)`, and a decoded
382;; frame arrives because a timer asked for it rather than because a person
383;; clicked. There is no other hook of the right shape — a component body runs
384;; when its state changes, which for a video feed is never.
385;;
386;; Run from the same `:before` as the reconciler's queue, and for the same
387;; reason: a callback that patches the tree must not do it mid-walk.
388
389(defonce ^:private timers (atom {}))
390(defonce ^:private next-timer (atom 0))
391
392(defn- now-ms [] (System/currentTimeMillis))
393
394(defn after!
395 "Run `f` once, at least `ms` from now. Answers a handle for `cancel!`."
396 [ms f]
397 (let [id (swap! next-timer inc)]
398 (swap! timers assoc id {:at (+ (now-ms) ms) :every nil :f f})
399 id))
400
401(defn every!
402 "Run `f` every `ms`. Answers a handle for `cancel!`.
403
404 Every `ms` AT MOST, not exactly: it fires on the first frame after the
405 deadline, so a 16ms timer on a 60Hz window runs once a frame and on a
406 slower one runs less often. That is the right failure — a timer that tried
407 to catch up would run twice in a row on a stutter, and for a pump that
408 means two frames decoded and one shown."
409 [ms f]
410 (let [id (swap! next-timer inc)]
411 (swap! timers assoc id {:at (+ (now-ms) ms) :every ms :f f})
412 id))
413
414(defn cancel!
415 "Stop a timer."
416 [id]
417 (swap! timers dissoc id)
418 nil)
419
420(defn- run-timers! []
421 (let [t (now-ms)
422 due (filter (fn [[_ v]] (<= (:at v) t)) @timers)]
423 (doseq [[id {:keys [every f]}] due]
424 (if every
425 (swap! timers assoc-in [id :at] (+ t every))
426 (swap! timers dissoc id))
427 ;; A throwing timer is cancelled rather than allowed to throw every
428 ;; frame for the rest of the session, which is unreadable and stops
429 ;; the ones behind it.
430 (try (f)
431 (catch Exception e
432 (swap! timers dissoc id)
433 (println "glimmer-jvui: timer failed, cancelled:" (ex-message e)))))))
434
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago435(defn- drain-pending! []
Give jvui a picture from somewhere else, and a clock 32fae8d nandi 9d ago436 (run-timers!)
Write dvui's shape in jolt, on SDL3, with no shared object 109c7e4 Veronika Winters 9d ago437 (let [[ws] (reset-vals! pending [])]
438 (doseq [w ws] (w))))
439
440(defn- run!
441 "glimmer.backend's :run. Creates the root page, mounts into it, then hands the
442 loop to jvui.
443
444 The reconciler's queued work is drained by jvui's `:before` hook rather than
445 inside the walk: a re-render patches the tree, and patching a tree while it
446 is being walked is how a frame ends up half old and half new."
447 [opts mount-root!]
448 (let [{:keys [title width height max-width theme frames auto-quit-ms shot]
449 :or {title "glimmer" width 720 height 520}} opts
450 root (create! :page (cond-> {} max-width (assoc :max-width max-width)))]
451 (mount-root! root :page)
452 (reset! b/loop-running? true)
453 (try
454 (app/run! (fn [] (emit! root))
455 {:title title :width width :height height
456 :theme (or theme theme/dark)
457 :before drain-pending!
458 :frames frames :auto-quit-ms auto-quit-ms :shot shot})
459 (finally (reset! b/loop-running? false)))))
460
461;; --- registration ------------------------------------------------------------
462
463(def backend
464 {:name :jvui
465 :create! create! :apply-props! apply-props!
466 :append-child! append-child! :remove-child! remove-child!
467 :replace-child! replace-child! :reorder-child! reorder-child!
468 :schedule schedule! :run run!})
469
470(b/register! backend)
471
472;; --- headless driving, for tests ---------------------------------------------
473
474(defn root-node
475 "A bare root page, for mounting into without a window."
476 [] (create! :page {}))
477
478(defn render-once
479 "Walk `root` through jvui with no window, no font and no display.
480
481 `cx` is a `jvui.core/context`; `evs` the events that frame. Answers the
482 context, whose `:data` is every rectangle the walk placed — which is enough
483 for a test to assert about a layout and to click on it."
484 ([root cx] (render-once root cx []))
485 ([root cx evs]
486 (drain-pending!)
487 (swap! cx assoc :events evs)
488 (swap! cx c/apply-input evs)
489 (binding [*record-rects?* true]
490 (c/frame! cx (fn [] (emit! root))))
491 cx))
Give jvui a picture from somewhere else, and a clock 32fae8d nandi 9d ago492
493;; --- feeds ------------------------------------------------------------------
494;; The same three calls glimmer-vidya exposes, so a client that paints a call
495;; does not care which backend is under it. They are not part of the
496;; reconciler and deliberately so: pixels arrive between frames, and the tree
497;; only ever holds the key.
498
499(defn frame-rgba!
500 "Hand feed `key` a new picture: `w` by `h` RGBA at FOREIGN pointer `px`.
501
502 The pointer is read during this call and not kept, so a caller may reuse
503 or free it immediately afterwards — which is what a decoder handing out a
504 borrowed buffer needs."
505 [key w h px]
506 (frames/put! key w h px))
507
508(defn frame-drop!
509 "Forget a feed and release its texture — someone left, or turned a camera
510 off."
511 [key]
512 (frames/drop! key))
513
514(defn feed-keys
515 "Every feed with a picture."
516 []
517 (frames/keys*))
Answer the rest of what a client asks its window 0b92f67 nandi 9d ago518
519;; --- the platform -----------------------------------------------------------
520;; The rest of what glimmer-vidya answers, so a client can ask its backend
521;; about the window it is in without knowing which backend that is. Thin on
522;; purpose: every one of these is jvui.host, and the indirection exists so
523;; the client requires one namespace rather than two.
524
525(def set-title! host/set-title!)
526(def window-width host/window-width)
527(def screen-size host/screen-size)
528(def quit! host/quit!)
529(def open-url! host/open-url!)
530(def clipboard-image-png! host/clipboard-image-png!)
531
532;; False and nil on a desktop, which is the right answer rather than a gap:
533;; the chooser exists so a phone can hand back a grant for one picture, and
534;; a caller reads the false and offers a file browser instead. glimmer-vidya
535;; says the same thing here.
536(def pick-image! host/pick-image!)
537(def picked-image! host/picked-image!)