At the moment, viscous creates a new window every time inspect is called. How can I reuse the same window for new calls to inspect? e.g.
(viscous/inspect 1) ;; creates a new window
(viscous/inspect 2) ;; creates a 2nd window. but I want it to use the firstThe viscous viewer is a reusable component. I typically use it via https://github.com/phronmophobic/spreadsheet which is very alpha, but I use it regularly. I'm not exactly sure what other APIs folks might find useful. Below is a sketch for something that seems to match your intended usage. If you have some thoughts on what the API should look like, I can work to include it as part of viscous.
(require '[com.phronemophobic.viscous :as viscous])
(require 'membrane.component)
(require 'membrane.toolkit)
(require 'membrane.ui)
(defonce viscous-atom (atom nil))
(defn open
"Open an inspector window to view obj."
([]
(let [width 80
height 40
_ (reset! viscous-atom
{:obj (viscous/wrap nil)
:width width
:show-context? true
:height height})
app (membrane.component/make-app #'viscous/inspector
viscous-atom)
[empty-width empty-height] (membrane.ui/bounds
((membrane.component/make-app #'viscous/inspector
{:obj (viscous/wrap nil)
:width 0
:height 0})))
window-width (+ 50
(max empty-width
(* @viscous/cell-width width)))
window-height (+ 100
empty-height
height
(* @viscous/cell-height (inc height)))
sync? false
run (if sync?
membrane.toolkit/run-sync
membrane.toolkit/run)]
(run @viscous/toolkit
app
{:window-title "Inspect"
:window-start-width window-width
:window-start-height window-height}))))
(defn inspect [obj]
(swap! viscous-atom assoc :obj (viscous/wrap obj))
nil)
Usage:
(open)
(inspect 1)
(inspect 2)How do I make an element fill the width of a view? Such that I can resize the window and still see the full width.
And I’d like for it to be an aspect scale. 😃
Something like this should work:
(defn aspect-fill [[w h] elem]
(let [[ew eh] (ui/bounds elem)
sx (/ w ew)
sy (/ h eh)
s (min sx sy)]
(ui/scale s s
elem)))
(def mpos (atom nil))
(defn debug [window-info]
(let [size [400 600]
[cw ch] (:container-size window-info)]
(ui/on
:mouse-move
(fn [pos]
(reset! mpos pos)
nil)
(aspect-fill
[cw ch]
(ui/vertical-layout
(ui/label @mpos)
(ui/label (pr-str (select-keys window-info [:container-size])))
(crop
(compose (ui/image "mybackground.png")
{:width 1160
:title "ImageMagick + Pango + Babashka = ♥️"
:author "Peter Strömberg"
:description "Where there's a will there's a way. I can now hack on my ImageMagick + Pango script in my Babashka REPL on my Mac."}
)) []
(ui/filled-rectangle [1 0 0]
10 10))))))
(comment
(skia/run
#'debug
{:include-container-info true})
(skia/run (constantly
(ui/label "hello world")))
,)the key changes are:
• the aspect-fill function
• pass :include-container-info to skia/run as an option
• debug now takes a single argument with the window info that includes a :container-size key with the container size as [w h]
Thanks! Works like a charm.
And, yes. It was the debug view I wanted it for. 😃