mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 05:46:11 +02:00
Merge pull request #2989 from penpot/alotor-fix-position-absolute-auto
Fix position absolute auto
This commit is contained in:
commit
0b9bef066b
9 changed files with 112 additions and 75 deletions
|
@ -133,7 +133,9 @@
|
||||||
(-> (get-shape-filter-bounds shape)
|
(-> (get-shape-filter-bounds shape)
|
||||||
(add-padding (calculate-padding shape true))))
|
(add-padding (calculate-padding shape true))))
|
||||||
|
|
||||||
bounds (if (or (:masked-group? shape) (cph/frame-shape? shape))
|
bounds (if (or (:masked-group? shape)
|
||||||
|
(and (cph/frame-shape? shape)
|
||||||
|
(not (:show-content shape))))
|
||||||
[(calculate-base-bounds shape)]
|
[(calculate-base-bounds shape)]
|
||||||
(cph/reduce-objects
|
(cph/reduce-objects
|
||||||
objects
|
objects
|
||||||
|
|
|
@ -117,7 +117,9 @@
|
||||||
|
|
||||||
child-bounds))]
|
child-bounds))]
|
||||||
|
|
||||||
(->> children (map get-child-bounds))))
|
(->> children
|
||||||
|
(remove ctl/layout-absolute?)
|
||||||
|
(map get-child-bounds))))
|
||||||
|
|
||||||
(defn layout-content-bounds
|
(defn layout-content-bounds
|
||||||
[bounds {:keys [layout-padding] :as parent} children]
|
[bounds {:keys [layout-padding] :as parent} children]
|
||||||
|
|
|
@ -96,7 +96,6 @@
|
||||||
"Propagates the modifiers from a parent too its children applying constraints if necesary"
|
"Propagates the modifiers from a parent too its children applying constraints if necesary"
|
||||||
[modif-tree children objects bounds parent transformed-parent-bounds ignore-constraints]
|
[modif-tree children objects bounds parent transformed-parent-bounds ignore-constraints]
|
||||||
(let [modifiers (dm/get-in modif-tree [(:id parent) :modifiers])]
|
(let [modifiers (dm/get-in modif-tree [(:id parent) :modifiers])]
|
||||||
|
|
||||||
;; Move modifiers don't need to calculate constraints
|
;; Move modifiers don't need to calculate constraints
|
||||||
(if (ctm/only-move? modifiers)
|
(if (ctm/only-move? modifiers)
|
||||||
(loop [modif-tree modif-tree
|
(loop [modif-tree modif-tree
|
||||||
|
@ -205,14 +204,14 @@
|
||||||
(let [origin (gpo/origin @parent-bounds)
|
(let [origin (gpo/origin @parent-bounds)
|
||||||
scale-width (/ auto-width (gpo/width-points @parent-bounds))]
|
scale-width (/ auto-width (gpo/width-points @parent-bounds))]
|
||||||
(-> modifiers
|
(-> modifiers
|
||||||
(ctm/resize-parent (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent)))))
|
(ctm/resize (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent)))))
|
||||||
|
|
||||||
set-parent-auto-height
|
set-parent-auto-height
|
||||||
(fn [modifiers auto-height]
|
(fn [modifiers auto-height]
|
||||||
(let [origin (gpo/origin @parent-bounds)
|
(let [origin (gpo/origin @parent-bounds)
|
||||||
scale-height (/ auto-height (gpo/height-points @parent-bounds))]
|
scale-height (/ auto-height (gpo/height-points @parent-bounds))]
|
||||||
(-> modifiers
|
(-> modifiers
|
||||||
(ctm/resize-parent (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))
|
(ctm/resize (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))
|
||||||
|
|
||||||
children (->> (cph/get-immediate-children objects parent-id)
|
children (->> (cph/get-immediate-children objects parent-id)
|
||||||
(remove :hidden))
|
(remove :hidden))
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.geom.shapes.bounds :as gsb]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[clojure.spec.alpha :as s]))
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
@ -362,6 +363,7 @@
|
||||||
|
|
||||||
(defn calc-overlay-position
|
(defn calc-overlay-position
|
||||||
[interaction ;; interaction data
|
[interaction ;; interaction data
|
||||||
|
objects ;; the objects tree
|
||||||
relative-to-shape ;; the interaction position is realtive to this sape
|
relative-to-shape ;; the interaction position is realtive to this sape
|
||||||
base-frame ;; the base frame of the current interaction
|
base-frame ;; the base frame of the current interaction
|
||||||
dest-frame ;; the frame to display with this interaction
|
dest-frame ;; the frame to display with this interaction
|
||||||
|
@ -371,7 +373,7 @@
|
||||||
(assert (has-overlay-opts interaction))
|
(assert (has-overlay-opts interaction))
|
||||||
(if (nil? dest-frame)
|
(if (nil? dest-frame)
|
||||||
(gpt/point 0 0)
|
(gpt/point 0 0)
|
||||||
(let [overlay-size (:selrect dest-frame)
|
(let [overlay-size (gsb/get-object-bounds objects dest-frame)
|
||||||
base-frame-size (:selrect base-frame)
|
base-frame-size (:selrect base-frame)
|
||||||
relative-to-shape-size (:selrect relative-to-shape)
|
relative-to-shape-size (:selrect relative-to-shape)
|
||||||
relative-to-adjusted-to-base-frame {:x (- (:x relative-to-shape-size) (:x base-frame-size))
|
relative-to-adjusted-to-base-frame {:x (- (:x relative-to-shape-size) (:x base-frame-size))
|
||||||
|
|
|
@ -346,24 +346,6 @@
|
||||||
(defn align-self-stretch? [{:keys [layout-item-align-self]}]
|
(defn align-self-stretch? [{:keys [layout-item-align-self]}]
|
||||||
(= :stretch layout-item-align-self))
|
(= :stretch layout-item-align-self))
|
||||||
|
|
||||||
(defn change-h-sizing?
|
|
||||||
[frame-id objects children-ids]
|
|
||||||
(and (layout? objects frame-id)
|
|
||||||
(auto-width? objects frame-id)
|
|
||||||
(or (and (col? objects frame-id)
|
|
||||||
(every? (partial fill-width? objects) children-ids))
|
|
||||||
(and (row? objects frame-id)
|
|
||||||
(some (partial fill-width? objects) children-ids)))))
|
|
||||||
|
|
||||||
(defn change-v-sizing?
|
|
||||||
[frame-id objects children-ids]
|
|
||||||
(and (layout? objects frame-id)
|
|
||||||
(auto-height? objects frame-id)
|
|
||||||
(or (and (col? objects frame-id)
|
|
||||||
(some (partial fill-height? objects) children-ids))
|
|
||||||
(and (row? objects frame-id)
|
|
||||||
(every? (partial fill-height? objects) children-ids)))))
|
|
||||||
|
|
||||||
(defn layout-absolute?
|
(defn layout-absolute?
|
||||||
([objects id]
|
([objects id]
|
||||||
(layout-absolute? (get objects id)))
|
(layout-absolute? (get objects id)))
|
||||||
|
@ -376,6 +358,28 @@
|
||||||
([shape]
|
([shape]
|
||||||
(or (:layout-item-z-index shape) 0)))
|
(or (:layout-item-z-index shape) 0)))
|
||||||
|
|
||||||
|
(defn change-h-sizing?
|
||||||
|
[frame-id objects children-ids]
|
||||||
|
(and (layout? objects frame-id)
|
||||||
|
(auto-width? objects frame-id)
|
||||||
|
(or (and (col? objects frame-id)
|
||||||
|
(->> children-ids
|
||||||
|
(remove (partial layout-absolute? objects))
|
||||||
|
(every? (partial fill-width? objects))))
|
||||||
|
(and (row? objects frame-id)
|
||||||
|
(->> children-ids
|
||||||
|
(remove (partial layout-absolute? objects))
|
||||||
|
(some (partial fill-width? objects)))))))
|
||||||
|
|
||||||
|
(defn change-v-sizing?
|
||||||
|
[frame-id objects children-ids]
|
||||||
|
(and (layout? objects frame-id)
|
||||||
|
(auto-height? objects frame-id)
|
||||||
|
(or (and (col? objects frame-id)
|
||||||
|
(some (partial fill-height? objects) children-ids))
|
||||||
|
(and (row? objects frame-id)
|
||||||
|
(every? (partial fill-height? objects) children-ids)))))
|
||||||
|
|
||||||
(defn remove-layout-container-data
|
(defn remove-layout-container-data
|
||||||
[shape]
|
[shape]
|
||||||
(dissoc shape
|
(dissoc shape
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns common-tests.types-shape-interactions-test
|
(ns common-tests.types-shape-interactions-test
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
|
@ -275,26 +276,38 @@
|
||||||
new-interaction (ctsi/set-position-relative-to i3 relative-to-id)]
|
new-interaction (ctsi/set-position-relative-to i3 relative-to-id)]
|
||||||
(t/is (= relative-to-id (:position-relative-to new-interaction)))))))
|
(t/is (= relative-to-id (:position-relative-to new-interaction)))))))
|
||||||
|
|
||||||
|
(defn setup-selrect [{:keys [x y width height] :as obj}]
|
||||||
|
(let [rect (gsh/make-rect x y width height)
|
||||||
|
center (gsh/center-rect rect)
|
||||||
|
selrect (gsh/rect->selrect rect)
|
||||||
|
points (gsh/rect->points rect)]
|
||||||
|
(-> obj
|
||||||
|
(assoc :selrect selrect)
|
||||||
|
(assoc :points points))))
|
||||||
|
|
||||||
(t/deftest calc-overlay-position
|
(t/deftest calc-overlay-position
|
||||||
(let [base-frame (-> (cts/make-minimal-shape :frame)
|
(let [base-frame (-> (cts/make-minimal-shape :frame)
|
||||||
(assoc-in [:selrect :width] 100)
|
(assoc :width 100)
|
||||||
(assoc-in [:selrect :height] 100))
|
(assoc :height 100)
|
||||||
|
(setup-selrect))
|
||||||
popup (-> (cts/make-minimal-shape :frame)
|
popup (-> (cts/make-minimal-shape :frame)
|
||||||
(assoc-in [:selrect :width] 50)
|
(assoc :width 50)
|
||||||
(assoc-in [:selrect :height] 50)
|
(assoc :height 50)
|
||||||
(assoc-in [:selrect :x] 10)
|
(assoc :x 10)
|
||||||
(assoc-in [:selrect :y] 10))
|
(assoc :y 10)
|
||||||
|
(setup-selrect))
|
||||||
|
|
||||||
rect (-> (cts/make-minimal-shape :rect)
|
rect (-> (cts/make-minimal-shape :rect)
|
||||||
(assoc-in [:selrect :width] 50)
|
(assoc :width 50)
|
||||||
(assoc-in [:selrect :height] 50)
|
(assoc :height 50)
|
||||||
(assoc-in [:selrect :x] 10)
|
(assoc :x 10)
|
||||||
(assoc-in [:selrect :y] 10))
|
(assoc :y 10)
|
||||||
|
(setup-selrect))
|
||||||
|
|
||||||
overlay-frame (-> (cts/make-minimal-shape :frame)
|
overlay-frame (-> (cts/make-minimal-shape :frame)
|
||||||
(assoc-in [:selrect :width] 30)
|
(assoc :width 30)
|
||||||
(assoc-in [:selrect :height] 20))
|
(assoc :height 20)
|
||||||
|
(setup-selrect))
|
||||||
|
|
||||||
objects {(:id base-frame) base-frame
|
objects {(:id base-frame) base-frame
|
||||||
(:id popup) popup
|
(:id popup) popup
|
||||||
|
@ -311,49 +324,49 @@
|
||||||
interaction-rect (ctsi/set-position-relative-to interaction (:id rect))]
|
interaction-rect (ctsi/set-position-relative-to interaction (:id rect))]
|
||||||
(t/testing "Overlay top-left relative to auto"
|
(t/testing "Overlay top-left relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :top-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :top-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 0))
|
(t/is (= (:x overlay-pos) 0))
|
||||||
(t/is (= (:y overlay-pos) 0))))
|
(t/is (= (:y overlay-pos) 0))))
|
||||||
|
|
||||||
(t/testing "Overlay top-center relative to auto"
|
(t/testing "Overlay top-center relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :top-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :top-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 0))))
|
(t/is (= (:y overlay-pos) 0))))
|
||||||
|
|
||||||
(t/testing "Overlay top-right relative to auto"
|
(t/testing "Overlay top-right relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :top-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :top-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 70))
|
(t/is (= (:x overlay-pos) 70))
|
||||||
(t/is (= (:y overlay-pos) 0))))
|
(t/is (= (:y overlay-pos) 0))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-left relative to auto"
|
(t/testing "Overlay bottom-left relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :bottom-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :bottom-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 0))
|
(t/is (= (:x overlay-pos) 0))
|
||||||
(t/is (= (:y overlay-pos) 80))))
|
(t/is (= (:y overlay-pos) 80))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-center relative to auto"
|
(t/testing "Overlay bottom-center relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :bottom-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :bottom-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 80))))
|
(t/is (= (:y overlay-pos) 80))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-right relative to auto"
|
(t/testing "Overlay bottom-right relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :bottom-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :bottom-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 70))
|
(t/is (= (:x overlay-pos) 70))
|
||||||
(t/is (= (:y overlay-pos) 80))))
|
(t/is (= (:y overlay-pos) 80))))
|
||||||
|
|
||||||
(t/testing "Overlay center relative to auto"
|
(t/testing "Overlay center relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 40))))
|
(t/is (= (:y overlay-pos) 40))))
|
||||||
|
|
||||||
(t/testing "Overlay manual relative to auto"
|
(t/testing "Overlay manual relative to auto"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-auto :center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 40))))
|
(t/is (= (:y overlay-pos) 40))))
|
||||||
|
|
||||||
|
@ -361,49 +374,49 @@
|
||||||
(let [i2 (-> interaction-auto
|
(let [i2 (-> interaction-auto
|
||||||
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
||||||
(ctsi/set-overlay-position (gpt/point 12 62)))
|
(ctsi/set-overlay-position (gpt/point 12 62)))
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 17))
|
(t/is (= (:x overlay-pos) 17))
|
||||||
(t/is (= (:y overlay-pos) 67))))
|
(t/is (= (:y overlay-pos) 67))))
|
||||||
|
|
||||||
(t/testing "Overlay top-left relative to base-frame"
|
(t/testing "Overlay top-left relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :top-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :top-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 5))
|
(t/is (= (:x overlay-pos) 5))
|
||||||
(t/is (= (:y overlay-pos) 5))))
|
(t/is (= (:y overlay-pos) 5))))
|
||||||
|
|
||||||
(t/testing "Overlay top-center relative to base-frame"
|
(t/testing "Overlay top-center relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :top-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :top-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 40))
|
(t/is (= (:x overlay-pos) 40))
|
||||||
(t/is (= (:y overlay-pos) 5))))
|
(t/is (= (:y overlay-pos) 5))))
|
||||||
|
|
||||||
(t/testing "Overlay top-right relative to base-frame"
|
(t/testing "Overlay top-right relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :top-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :top-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 75))
|
(t/is (= (:x overlay-pos) 75))
|
||||||
(t/is (= (:y overlay-pos) 5))))
|
(t/is (= (:y overlay-pos) 5))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-left relative to base-frame"
|
(t/testing "Overlay bottom-left relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :bottom-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :bottom-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 5))
|
(t/is (= (:x overlay-pos) 5))
|
||||||
(t/is (= (:y overlay-pos) 85))))
|
(t/is (= (:y overlay-pos) 85))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-center relative to base-frame"
|
(t/testing "Overlay bottom-center relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :bottom-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :bottom-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 40))
|
(t/is (= (:x overlay-pos) 40))
|
||||||
(t/is (= (:y overlay-pos) 85))))
|
(t/is (= (:y overlay-pos) 85))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-right relative to base-frame"
|
(t/testing "Overlay bottom-right relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :bottom-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :bottom-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 75))
|
(t/is (= (:x overlay-pos) 75))
|
||||||
(t/is (= (:y overlay-pos) 85))))
|
(t/is (= (:y overlay-pos) 85))))
|
||||||
|
|
||||||
(t/testing "Overlay center relative to base-frame"
|
(t/testing "Overlay center relative to base-frame"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-base-frame :center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 40))
|
(t/is (= (:x overlay-pos) 40))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
|
@ -411,49 +424,49 @@
|
||||||
(let [i2 (-> interaction-base-frame
|
(let [i2 (-> interaction-base-frame
|
||||||
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
||||||
(ctsi/set-overlay-position (gpt/point 12 62)))
|
(ctsi/set-overlay-position (gpt/point 12 62)))
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 base-frame base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects base-frame base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 17))
|
(t/is (= (:x overlay-pos) 17))
|
||||||
(t/is (= (:y overlay-pos) 67))))
|
(t/is (= (:y overlay-pos) 67))))
|
||||||
|
|
||||||
(t/testing "Overlay top-left relative to popup"
|
(t/testing "Overlay top-left relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 15))
|
(t/is (= (:x overlay-pos) 15))
|
||||||
(t/is (= (:y overlay-pos) 15))))
|
(t/is (= (:y overlay-pos) 15))))
|
||||||
|
|
||||||
(t/testing "Overlay top-center relative to popup"
|
(t/testing "Overlay top-center relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 25))
|
(t/is (= (:x overlay-pos) 25))
|
||||||
(t/is (= (:y overlay-pos) 15))))
|
(t/is (= (:y overlay-pos) 15))))
|
||||||
|
|
||||||
(t/testing "Overlay top-right relative to popup"
|
(t/testing "Overlay top-right relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 15))))
|
(t/is (= (:y overlay-pos) 15))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-left relative to popup"
|
(t/testing "Overlay bottom-left relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :bottom-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :bottom-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 15))
|
(t/is (= (:x overlay-pos) 15))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-center relative to popup"
|
(t/testing "Overlay bottom-center relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :bottom-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :bottom-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 25))
|
(t/is (= (:x overlay-pos) 25))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-right relative to popup"
|
(t/testing "Overlay bottom-right relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :bottom-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :bottom-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
(t/testing "Overlay center relative to popup"
|
(t/testing "Overlay center relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 25))
|
(t/is (= (:x overlay-pos) 25))
|
||||||
(t/is (= (:y overlay-pos) 30))))
|
(t/is (= (:y overlay-pos) 30))))
|
||||||
|
|
||||||
|
@ -461,49 +474,49 @@
|
||||||
(let [i2 (-> interaction-popup
|
(let [i2 (-> interaction-popup
|
||||||
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
||||||
(ctsi/set-overlay-position (gpt/point 12 62)))
|
(ctsi/set-overlay-position (gpt/point 12 62)))
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 27))
|
(t/is (= (:x overlay-pos) 27))
|
||||||
(t/is (= (:y overlay-pos) 77))))
|
(t/is (= (:y overlay-pos) 77))))
|
||||||
|
|
||||||
(t/testing "Overlay top-left relative to popup"
|
(t/testing "Overlay top-left relative to popup"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-popup :top-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 popup base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects popup base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 15))
|
(t/is (= (:x overlay-pos) 15))
|
||||||
(t/is (= (:y overlay-pos) 15))))
|
(t/is (= (:y overlay-pos) 15))))
|
||||||
|
|
||||||
(t/testing "Overlay top-center relative to rect"
|
(t/testing "Overlay top-center relative to rect"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :top-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :top-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 25))
|
(t/is (= (:x overlay-pos) 25))
|
||||||
(t/is (= (:y overlay-pos) 15))))
|
(t/is (= (:y overlay-pos) 15))))
|
||||||
|
|
||||||
(t/testing "Overlay top-right relative to rect"
|
(t/testing "Overlay top-right relative to rect"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :top-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :top-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 15))))
|
(t/is (= (:y overlay-pos) 15))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-left relative to rect"
|
(t/testing "Overlay bottom-left relative to rect"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :bottom-left base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :bottom-left base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 15))
|
(t/is (= (:x overlay-pos) 15))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-center relative to rect"
|
(t/testing "Overlay bottom-center relative to rect"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :bottom-center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :bottom-center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 25))
|
(t/is (= (:x overlay-pos) 25))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
(t/testing "Overlay bottom-right relative to rect"
|
(t/testing "Overlay bottom-right relative to rect"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :bottom-right base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :bottom-right base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 35))
|
(t/is (= (:x overlay-pos) 35))
|
||||||
(t/is (= (:y overlay-pos) 45))))
|
(t/is (= (:y overlay-pos) 45))))
|
||||||
|
|
||||||
(t/testing "Overlay center relative to rect"
|
(t/testing "Overlay center relative to rect"
|
||||||
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :center base-frame objects)
|
(let [i2 (ctsi/set-overlay-pos-type interaction-rect :center base-frame objects)
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 25))
|
(t/is (= (:x overlay-pos) 25))
|
||||||
(t/is (= (:y overlay-pos) 30))))
|
(t/is (= (:y overlay-pos) 30))))
|
||||||
|
|
||||||
|
@ -511,7 +524,7 @@
|
||||||
(let [i2 (-> interaction-rect
|
(let [i2 (-> interaction-rect
|
||||||
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
(ctsi/set-overlay-pos-type :manual base-frame objects)
|
||||||
(ctsi/set-overlay-position (gpt/point 12 62)))
|
(ctsi/set-overlay-position (gpt/point 12 62)))
|
||||||
overlay-pos (ctsi/calc-overlay-position i2 rect base-frame overlay-frame frame-offset)]
|
overlay-pos (ctsi/calc-overlay-position i2 objects rect base-frame overlay-frame frame-offset)]
|
||||||
(t/is (= (:x overlay-pos) 17))
|
(t/is (= (:x overlay-pos) 17))
|
||||||
(t/is (= (:y overlay-pos) 67))))))
|
(t/is (= (:y overlay-pos) 67))))))
|
||||||
|
|
||||||
|
|
|
@ -349,7 +349,10 @@
|
||||||
col? (ctl/col? parent)
|
col? (ctl/col? parent)
|
||||||
row? (ctl/row? parent)
|
row? (ctl/row? parent)
|
||||||
|
|
||||||
all-children (->> parent :shapes (map (d/getf objects)))]
|
all-children (->> parent
|
||||||
|
:shapes
|
||||||
|
(map (d/getf objects))
|
||||||
|
(remove ctl/layout-absolute?))]
|
||||||
|
|
||||||
(cond-> shape
|
(cond-> shape
|
||||||
;; If the parent is hug width and the direction column
|
;; If the parent is hug width and the direction column
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
overlays-ids (set (map :id overlays))
|
overlays-ids (set (map :id overlays))
|
||||||
relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame)
|
relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame)
|
||||||
position (ctsi/calc-overlay-position interaction
|
position (ctsi/calc-overlay-position interaction
|
||||||
|
viewer-objects
|
||||||
relative-to-shape
|
relative-to-shape
|
||||||
relative-to-base-frame
|
relative-to-base-frame
|
||||||
dest-frame
|
dest-frame
|
||||||
|
@ -90,6 +91,7 @@
|
||||||
overlays-ids (set (map :id overlays))
|
overlays-ids (set (map :id overlays))
|
||||||
relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame)
|
relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame)
|
||||||
position (ctsi/calc-overlay-position interaction
|
position (ctsi/calc-overlay-position interaction
|
||||||
|
objects
|
||||||
relative-to-shape
|
relative-to-shape
|
||||||
relative-to-base-frame
|
relative-to-base-frame
|
||||||
dest-frame
|
dest-frame
|
||||||
|
@ -154,6 +156,7 @@
|
||||||
overlays-ids (set (map :id overlays))
|
overlays-ids (set (map :id overlays))
|
||||||
relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame)
|
relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame)
|
||||||
position (ctsi/calc-overlay-position interaction
|
position (ctsi/calc-overlay-position interaction
|
||||||
|
objects
|
||||||
relative-to-shape
|
relative-to-shape
|
||||||
relative-to-base-frame
|
relative-to-base-frame
|
||||||
dest-frame
|
dest-frame
|
||||||
|
|
|
@ -84,13 +84,22 @@
|
||||||
selection-parents (mf/deref selection-parents-ref)
|
selection-parents (mf/deref selection-parents-ref)
|
||||||
|
|
||||||
flex-child? (->> selection-parents (some ctl/layout?))
|
flex-child? (->> selection-parents (some ctl/layout?))
|
||||||
|
absolute? (ctl/layout-absolute? shape)
|
||||||
flex-container? (ctl/layout? shape)
|
flex-container? (ctl/layout? shape)
|
||||||
flex-auto-width? (ctl/auto-width? shape)
|
flex-auto-width? (ctl/auto-width? shape)
|
||||||
flex-fill-width? (ctl/fill-width? shape)
|
flex-fill-width? (ctl/fill-width? shape)
|
||||||
flex-auto-height? (ctl/auto-height? shape)
|
flex-auto-height? (ctl/auto-height? shape)
|
||||||
flex-fill-height? (ctl/fill-height? shape)
|
flex-fill-height? (ctl/fill-height? shape)
|
||||||
|
|
||||||
|
disabled-position-x? (and flex-child? (not absolute?))
|
||||||
|
disabled-position-y? (and flex-child? (not absolute?))
|
||||||
|
disabled-width-sizing? (and (or flex-child? flex-container?)
|
||||||
|
(or flex-auto-width? flex-fill-width?)
|
||||||
|
(not absolute?))
|
||||||
|
disabled-height-sizing? (and (or flex-child? flex-container?)
|
||||||
|
(or flex-auto-height? flex-fill-height?)
|
||||||
|
(not absolute?))
|
||||||
|
|
||||||
;; To show interactively the measures while the user is manipulating
|
;; To show interactively the measures while the user is manipulating
|
||||||
;; the shape with the mouse, generate a copy of the shapes applying
|
;; the shape with the mouse, generate a copy of the shapes applying
|
||||||
;; the transient transformations.
|
;; the transient transformations.
|
||||||
|
@ -309,7 +318,7 @@
|
||||||
:placeholder "--"
|
:placeholder "--"
|
||||||
:on-click select-all
|
:on-click select-all
|
||||||
:on-change on-width-change
|
:on-change on-width-change
|
||||||
:disabled (and (or flex-child? flex-container?) (or flex-auto-width? flex-fill-width?))
|
:disabled disabled-width-sizing?
|
||||||
:value (:width values)}]]
|
:value (:width values)}]]
|
||||||
|
|
||||||
[:div.input-element.height {:title (tr "workspace.options.height")}
|
[:div.input-element.height {:title (tr "workspace.options.height")}
|
||||||
|
@ -318,7 +327,7 @@
|
||||||
:placeholder "--"
|
:placeholder "--"
|
||||||
:on-click select-all
|
:on-click select-all
|
||||||
:on-change on-height-change
|
:on-change on-height-change
|
||||||
:disabled (and (or flex-child? flex-container?) (or flex-auto-height? flex-fill-height?))
|
:disabled disabled-height-sizing?
|
||||||
:value (:height values)}]]
|
:value (:height values)}]]
|
||||||
|
|
||||||
[:div.lock-size {:class (dom/classnames
|
[:div.lock-size {:class (dom/classnames
|
||||||
|
@ -338,13 +347,13 @@
|
||||||
:placeholder "--"
|
:placeholder "--"
|
||||||
:on-click select-all
|
:on-click select-all
|
||||||
:on-change on-pos-x-change
|
:on-change on-pos-x-change
|
||||||
:disabled flex-child?
|
:disabled disabled-position-x?
|
||||||
:value (:x values)}]]
|
:value (:x values)}]]
|
||||||
[:div.input-element.Yaxis {:title (tr "workspace.options.y")}
|
[:div.input-element.Yaxis {:title (tr "workspace.options.y")}
|
||||||
[:> numeric-input {:no-validate true
|
[:> numeric-input {:no-validate true
|
||||||
:placeholder "--"
|
:placeholder "--"
|
||||||
:on-click select-all
|
:on-click select-all
|
||||||
:disabled flex-child?
|
:disabled disabled-position-y?
|
||||||
:on-change on-pos-y-change
|
:on-change on-pos-y-change
|
||||||
:value (:y values)}]]])
|
:value (:y values)}]]])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue