mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -05:00
🐛 Distribute vertical spacing failing for overlapped text
The code was doing what it was designed to, however there is no reason to prevent elements with a bit of overlap to also be equally distributed. closes #3141 Signed-off-by: Dalai Felinto <dalai@blender.org>
This commit is contained in:
parent
69069afb0a
commit
395fbef19e
1 changed files with 20 additions and 23 deletions
|
@ -69,11 +69,10 @@
|
||||||
#{:horizontal :vertical})
|
#{:horizontal :vertical})
|
||||||
|
|
||||||
(defn distribute-space
|
(defn distribute-space
|
||||||
"Distribute equally the space between shapes in the given axis. If
|
"Distribute equally the space between shapes in the given axis.
|
||||||
there is no space enough, it does nothing. It takes into account
|
It takes into account the form of the shape and the rotation,
|
||||||
the form of the shape and the rotation, what is distributed is
|
what is distributed is the wrapping rectangles of the shapes.
|
||||||
the wrapping rectangles of the shapes. If any shape is a group,
|
If any shape is a group, move also all of its recursive children."
|
||||||
move also all of its recursive children."
|
|
||||||
[shapes axis objects]
|
[shapes axis objects]
|
||||||
(let [coord (if (= axis :horizontal) :x :y)
|
(let [coord (if (= axis :horizontal) :x :y)
|
||||||
other-coord (if (= axis :horizontal) :y :x)
|
other-coord (if (= axis :horizontal) :y :x)
|
||||||
|
@ -87,28 +86,26 @@
|
||||||
; The total space between shapes
|
; The total space between shapes
|
||||||
space (reduce - (size wrapper-rect) (map size wrapped-shapes))]
|
space (reduce - (size wrapper-rect) (map size wrapped-shapes))]
|
||||||
|
|
||||||
(if (<= space 0)
|
(let [unit-space (/ space (- (count wrapped-shapes) 1))
|
||||||
shapes
|
; Calculate the distance we need to move each shape.
|
||||||
(let [unit-space (/ space (- (count wrapped-shapes) 1))
|
; The new position of each one is the position of the
|
||||||
; Calculate the distance we need to move each shape.
|
; previous one plus its size plus the unit space.
|
||||||
; The new position of each one is the position of the
|
deltas (loop [shapes' wrapped-shapes
|
||||||
; previous one plus its size plus the unit space.
|
start-pos (coord wrapper-rect)
|
||||||
deltas (loop [shapes' wrapped-shapes
|
deltas []]
|
||||||
start-pos (coord wrapper-rect)
|
|
||||||
deltas []]
|
|
||||||
|
|
||||||
(let [first-shape (first shapes')
|
(let [first-shape (first shapes')
|
||||||
delta (- start-pos (coord first-shape))
|
delta (- start-pos (coord first-shape))
|
||||||
new-pos (+ start-pos (size first-shape) unit-space)]
|
new-pos (+ start-pos (size first-shape) unit-space)]
|
||||||
|
|
||||||
(if (= (count shapes') 1)
|
(if (= (count shapes') 1)
|
||||||
(conj deltas delta)
|
(conj deltas delta)
|
||||||
(recur (rest shapes')
|
(recur (rest shapes')
|
||||||
new-pos
|
new-pos
|
||||||
(conj deltas delta)))))]
|
(conj deltas delta)))))]
|
||||||
|
|
||||||
(mapcat #(recursive-move %1 {coord %2 other-coord 0} objects)
|
(mapcat #(recursive-move %1 {coord %2 other-coord 0} objects)
|
||||||
sorted-shapes deltas)))))
|
sorted-shapes deltas))))
|
||||||
|
|
||||||
;; Adjust to viewport
|
;; Adjust to viewport
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue