diff --git a/src/uxbox/shapes.cljs b/src/uxbox/shapes.cljs index 1e49d63c81..f39fc72ad8 100644 --- a/src/uxbox/shapes.cljs +++ b/src/uxbox/shapes.cljs @@ -174,17 +174,51 @@ (assoc shape :rx rx :ry rx) (assoc shape :rx rx :ry ry)))) +(defn correct-shape + [shape] + (let [x1 (min (:x1 shape) (:x2 shape)) + y1 (min (:y1 shape) (:y2 shape)) + x2 (max (:x1 shape) (:x2 shape)) + y2 (max (:y1 shape) (:y2 shape))] + (assoc shape :x1 x1 :x2 x2 :y1 y1 :y2 y2))) + +(defn equalize-sides + [shape] + (let [{:keys [x1 x2 y1 y2]} shape + x-side (mth/abs (- x2 x1)) + y-side (mth/abs (- y2 y1)) + max-side (max x-side y-side)] + (cond + (and (> x1 x2) (> y1 y2)) + (assoc shape :x2 (- x1 max-side) :y2 (- y1 max-side)) + + (and (< x1 x2) (< y1 y2)) + (assoc shape :x2 (+ x1 max-side) :y2 (+ y1 max-side)) + + (and (> x1 x2) (< y1 y2)) + (assoc shape :x2 (- x1 max-side) :y2 (+ y1 max-side)) + + (and (< x1 x2) (> y1 y2)) + (assoc shape :x2 (+ x1 max-side) :y2 (- y1 max-side))))) + + (defmethod resize :builtin/rect [shape {:keys [x y lock] :as pos}] (if lock - (assoc shape :x2 x :y2 x) - (assoc shape :x2 x :y2 y))) + (-> shape + (assoc :x2 x :y2 y) + equalize-sides + correct-shape) + (correct-shape (assoc shape :x2 x :y2 y)))) (defmethod resize :builtin/text [shape {:keys [x y lock] :as pos}] (if lock - (assoc shape :x2 x :y2 x) - (assoc shape :x2 x :y2 y))) + (-> shape + (assoc :x2 x :y2 y) + equalize-sides + correct-shape) + (correct-shape (assoc shape :x2 x :y2 y)))) (defmethod resize :default [shape _]