membrane

zihao 2025-10-05T05:59:32.962679Z

translate will not change the bounds in normal case. i dont understand why using defui make it change

(->> (ui/label "Hello World!")
       (ui/bounds))
;; [82 15]
  
(->> (ui/translate 10 10 (ui/label "Hello World!"))
     (ui/bounds))
;; still [82 15]

(defui test-ui [{:keys [label]}]
  (ui/translate 10 10
                (ui/label label)))
  
(->> (test-ui {:label "Hello World!"})
     (ui/bounds))
;; [92 25]

zihao 2025-10-07T02:56:36.710609Z

what's the reason OnXXX take drawables instead of single drawable. imo no implicit conversation here is better, since (translate x y elem) and [(translate x y elem)] has different origin and bounds

zihao 2025-10-05T06:08:18.567009Z

(ui/origin (test-ui ...)) is [0 0]. maybe it wrap another layer of "container"? (i dont know the right terminology) what should i do if i want (test-ui ...) have origin [10 10]

zihao 2025-10-05T07:21:12.137729Z

wrap on something to translate also change the bounds. https://clojurians.slack.com/archives/CVB8K7V50/p1695499993982809 IMHO only translate / scale / other layout related function will change where the element should display and how large the size. on and others like style and color shouldn't change location/size

zihao 2025-10-05T14:11:43.656489Z

after investigate the code, i see OnXXX record take drawables as parameter, and the wrapped ui's bounds became a big rect including every drawables and the empty space between them. i am building a infinite canvas UI, figuring out how to group multiple drawables and preserve the empty space

phronmophobic 2025-10-05T23:55:52.597329Z

> IMHO only translate / scale / other layout related function will change where the element should display and how large the size. on and others like style and color shouldn't change location/size consider the difference between:

(ui/on
 :mouse-down (fn [mpos])
 (ui/translate 10 20
               elem))
;; vs
(ui/translate
 10 20
 (ui/on
  :mouse-down (fn [mpos])
  elem))
These are saying two different things

zihao 2025-10-06T01:05:48.469829Z

in term of where the mouse-down can trigger. i dont think they should different. why include the top left empty space in first case? i also expect

(->> elem (translate x1 y2) (translate x2 y2) (bounds))
=
(->> elem (translate (+x1 x2) (+ y1 y2)) (bounds))

phronmophobic 2025-10-06T01:11:55.312099Z

that's maybe arguable for translate, but translation is not the only element that shifts the origin

phronmophobic 2025-10-06T01:16:19.931129Z

Another way to think about it is if you have a component with a translated child element at offset 10,20. If the child element has an origin at 10,20 and the component has an origin at 10,20, then when you generically walk the tree of elements using ui/origin and ui/children, then the offset will be double counted.

phronmophobic 2025-10-06T01:16:46.441919Z

Having the origin of the component at 0,0 ensures that the origin isn't double counted.

phronmophobic 2025-10-06T01:19:33.302439Z

Fwiw, many of the UI elements used to work the way you suggest and it caused weird bugs and edge cases due to the double counting problem.

phronmophobic 2025-10-06T01:21:31.354659Z

I still think both ui/bounds and ui/origin are overloaded in their meanings and should be split into simpler concepts, but I haven't gotten around to it yet. A workaround is that it's fairly tractable to create a new protocol that uses ui/bounds and ui/origin the way you expect and extend it to the types in membrane.ui that you care about.

phronmophobic 2025-10-06T01:23:40.309109Z

If the origin of a component is the same as the origin of it's child element, then what should ui/children return? How do you generically walk the tree of elements while keeping the current origin offset?

phronmophobic 2025-10-06T01:25:45.825899Z

I know these questions sound rhetorical, but I am actually open to new ideas here. I would like to make a "membrane.ui2" someday that is backwards compatible with membrane.ui that includes some ideas for improvement I've learned along the way.

zihao 2025-10-06T01:27:52.914419Z

thank for your information, i need to draw some diagram to see.