0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00

🐛 Fixed problems with lines selrect

This commit is contained in:
alonso.torres 2021-01-14 08:20:56 +01:00
parent a14686c9f3
commit ba7b2fd270
2 changed files with 67 additions and 41 deletions

View file

@ -120,9 +120,13 @@
extremities (mapcat calc-extremities extremities (mapcat calc-extremities
content content
(d/concat [nil] content))] (d/concat [nil] content))
(gpr/points->selrect extremities))) selrect (gpr/points->selrect extremities)]
(-> selrect
(update :width #(if (mth/almost-zero? %) 1 %))
(update :height #(if (mth/almost-zero? %) 1 %)))))
(defn transform-content [content transform] (defn transform-content [content transform]
(let [set-tr (fn [params px py] (let [set-tr (fn [params px py]

View file

@ -42,6 +42,7 @@
(def selection-rect-color-normal "#1FDEA7") (def selection-rect-color-normal "#1FDEA7")
(def selection-rect-color-component "#00E0FF") (def selection-rect-color-component "#00E0FF")
(def selection-rect-width 1) (def selection-rect-width 1)
(def min-selrect-side 10)
(mf/defc selection-rect [{:keys [transform rect zoom color]}] (mf/defc selection-rect [{:keys [transform rect zoom color]}]
(when rect (when rect
@ -57,56 +58,65 @@
:fill "transparent"}}]))) :fill "transparent"}}])))
(defn- handlers-for-selection [{:keys [x y width height]}] (defn- handlers-for-selection [{:keys [x y width height]}]
[;; TOP-LEFT (->>
{:type :rotation [ ;; TOP-LEFT
:position :top-left {:type :rotation
:props {:cx x :cy y}} :position :top-left
:props {:cx x :cy y}}
{:type :resize-point (when (and (> width min-selrect-side) (> height min-selrect-side))
:position :top-left {:type :resize-point
:props {:cx x :cy y}} :position :top-left
:props {:cx x :cy y}})
{:type :rotation {:type :rotation
:position :top-right :position :top-right
:props {:cx (+ x width) :cy y}} :props {:cx (+ x width) :cy y}}
{:type :resize-point (when (and (> width min-selrect-side) (> height min-selrect-side))
:position :top-right {:type :resize-point
:props {:cx (+ x width) :cy y}} :position :top-right
:props {:cx (+ x width) :cy y}})
{:type :rotation {:type :rotation
:position :bottom-right :position :bottom-right
:props {:cx (+ x width) :cy (+ y height)}} :props {:cx (+ x width) :cy (+ y height)}}
{:type :resize-point (when (and (> width min-selrect-side) (> height min-selrect-side))
:position :bottom-right {:type :resize-point
:props {:cx (+ x width) :cy (+ y height)}} :position :bottom-right
:props {:cx (+ x width) :cy (+ y height)}})
{:type :rotation {:type :rotation
:position :bottom-left :position :bottom-left
:props {:cx x :cy (+ y height)}} :props {:cx x :cy (+ y height)}}
{:type :resize-point (when (and (> width min-selrect-side) (> height min-selrect-side))
:position :bottom-left {:type :resize-point
:props {:cx x :cy (+ y height)}} :position :bottom-left
:props {:cx x :cy (+ y height)}})
{:type :resize-side (when (> height min-selrect-side)
:position :top {:type :resize-side
:props {:x x :y y :length width :angle 0 }} :position :top
:props {:x x :y y :length width :angle 0 }})
{:type :resize-side (when (> width min-selrect-side)
:position :right {:type :resize-side
:props {:x (+ x width) :y y :length height :angle 90 }} :position :right
:props {:x (+ x width) :y y :length height :angle 90 }})
{:type :resize-side (when (> height min-selrect-side)
:position :bottom {:type :resize-side
:props {:x (+ x width) :y (+ y height) :length width :angle 180 }} :position :bottom
:props {:x (+ x width) :y (+ y height) :length width :angle 180 }})
{:type :resize-side (when (> width min-selrect-side)
:position :left {:type :resize-side
:props {:x x :y (+ y height) :length height :angle 270 }} :position :left
:props {:x x :y (+ y height) :length height :angle 270 }})]
]) (filterv (comp not nil?))))
(mf/defc rotation-handler [{:keys [cx cy transform position rotation zoom on-rotate]}] (mf/defc rotation-handler [{:keys [cx cy transform position rotation zoom on-rotate]}]
(let [size (/ rotation-handler-size zoom) (let [size (/ rotation-handler-size zoom)
@ -171,6 +181,17 @@
:cursor (if (#{:left :right} position) :cursor (if (#{:left :right} position)
(cur/resize-ew rotation) (cur/resize-ew rotation)
(cur/resize-ns rotation)) }}])) (cur/resize-ns rotation)) }}]))
(defn minimum-selrect [{:keys [x y width height] :as selrect}]
(let [final-width (max width min-selrect-side)
final-height (max height min-selrect-side)
offset-x (/ (- final-width width) 2)
offset-y (/ (- final-height height) 2)]
{:x (- x offset-x)
:y (- y offset-y)
:width final-width
:height final-height}))
(mf/defc controls (mf/defc controls
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
@ -181,7 +202,8 @@
on-rotate (obj/get props "on-rotate") on-rotate (obj/get props "on-rotate")
current-transform (mf/deref refs/current-transform) current-transform (mf/deref refs/current-transform)
selrect (:selrect shape) selrect (-> (:selrect shape)
minimum-selrect)
transform (geom/transform-matrix shape {:no-flip true})] transform (geom/transform-matrix shape {:no-flip true})]
(when (not (#{:move :rotate} current-transform)) (when (not (#{:move :rotate} current-transform))