mirror of
https://github.com/penpot/penpot.git
synced 2025-07-24 07:47:22 +02:00
♻️ Refactor selrec generation
This commit is contained in:
parent
ed9400912c
commit
0f54e85b36
18 changed files with 187 additions and 186 deletions
|
@ -395,8 +395,8 @@
|
|||
srect (gsh/selection-rect shapes)
|
||||
local (assoc local :vport size :zoom 1)]
|
||||
(cond
|
||||
(or (not (mth/finite? (:width srect)))
|
||||
(not (mth/finite? (:height srect))))
|
||||
(or (not (d/num? (:width srect)))
|
||||
(not (d/num? (:height srect))))
|
||||
(assoc local :vbox (assoc size :x 0 :y 0))
|
||||
|
||||
(or (> (:width srect) width)
|
||||
|
|
|
@ -32,9 +32,7 @@
|
|||
(defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
|
||||
|
||||
(defn- assert-valid-num [attr num]
|
||||
(when (or (nil? num)
|
||||
(mth/nan? num)
|
||||
(not (mth/finite? num))
|
||||
(when (or (not (d/num? num))
|
||||
(>= num max-safe-int )
|
||||
(<= num min-safe-int))
|
||||
(ex/raise (str (d/name attr) " attribute invalid: " num)))
|
||||
|
@ -229,14 +227,9 @@
|
|||
(let [points (-> (gsh/rect->points rect-data)
|
||||
(gsh/transform-points transform))
|
||||
|
||||
center (gsh/center-points points)
|
||||
|
||||
rect-shape (-> (gsh/make-centered-rect center (:width rect-data) (:height rect-data))
|
||||
(update :width max 1)
|
||||
(update :height max 1))
|
||||
|
||||
selrect (gsh/rect->selrect rect-shape)
|
||||
|
||||
center (gsh/center-points points)
|
||||
rect-shape (gsh/center->rect center (:width rect-data) (:height rect-data))
|
||||
selrect (gsh/rect->selrect rect-shape)
|
||||
rect-points (gsh/rect->points rect-shape)
|
||||
|
||||
[shape-transform shape-transform-inv rotation]
|
||||
|
|
|
@ -181,9 +181,12 @@
|
|||
:ignore-tree ignore-tree
|
||||
;; Attributes that can change in the transform. This way we don't have to check
|
||||
;; all the attributes
|
||||
:attrs [:selrect :points
|
||||
:x :y
|
||||
:width :height
|
||||
:attrs [:selrect
|
||||
:points
|
||||
:x
|
||||
:y
|
||||
:width
|
||||
:height
|
||||
:content
|
||||
:transform
|
||||
:transform-inverse
|
||||
|
|
|
@ -59,15 +59,14 @@
|
|||
(defn- calculate-dimensions
|
||||
[{:keys [objects] :as data} vport]
|
||||
(let [shapes (cph/get-immediate-children objects)
|
||||
to-finite (fn [val fallback] (if (not (mth/finite? val)) fallback val))
|
||||
rect (cond->> (gsh/selection-rect shapes)
|
||||
(some? vport)
|
||||
(gal/adjust-to-viewport vport))]
|
||||
(-> rect
|
||||
(update :x to-finite 0)
|
||||
(update :y to-finite 0)
|
||||
(update :width to-finite 100000)
|
||||
(update :height to-finite 100000))))
|
||||
(update :x mth/finite 0)
|
||||
(update :y mth/finite 0)
|
||||
(update :width mth/finite 100000)
|
||||
(update :height mth/finite 100000))))
|
||||
|
||||
(declare shape-wrapper-factory)
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@
|
|||
snap-list (d/concat-vec lt-snap gt-snap between-snap)
|
||||
min-snap (reduce best-snap ##Inf snap-list)]
|
||||
|
||||
(if (mth/finite? min-snap) [0 min-snap] nil)))
|
||||
(if (d/num? min-snap) [0 min-snap] nil)))
|
||||
|
||||
(defn search-snap-distance [selrect coord shapes-lt shapes-gt zoom]
|
||||
(->> (rx/combine-latest shapes-lt shapes-gt)
|
||||
|
|
|
@ -28,10 +28,6 @@
|
|||
min-val (get params :min)
|
||||
max-val (get params :max)
|
||||
|
||||
num? (fn [val] (and (number? val)
|
||||
(not (mth/nan? val))
|
||||
(mth/finite? val)))
|
||||
|
||||
emit-blur? (mf/use-ref nil)
|
||||
font-size-wrapper-ref (mf/use-ref)
|
||||
|
||||
|
@ -103,8 +99,8 @@
|
|||
new-value (+ value increment)
|
||||
|
||||
new-value (cond
|
||||
(and (num? min-val) (< new-value min-val)) min-val
|
||||
(and (num? max-val) (> new-value max-val)) max-val
|
||||
(and (d/num? min-val) (< new-value min-val)) min-val
|
||||
(and (d/num? max-val) (> new-value max-val)) max-val
|
||||
:else new-value)]
|
||||
|
||||
(set-value new-value)))))))
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
(ns app.main.ui.components.numeric-input
|
||||
(:require
|
||||
[app.main.ui.formats :as fmt]
|
||||
[app.common.data :as d]
|
||||
[app.common.spec :as us]
|
||||
[app.main.ui.formats :as fmt]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.keyboard :as kbd]
|
||||
|
@ -18,11 +18,6 @@
|
|||
[rumext.alpha :as mf])
|
||||
(:import goog.events.EventType))
|
||||
|
||||
(defn num? [val]
|
||||
(and (number? val)
|
||||
(not (mth/nan? val))
|
||||
(mth/finite? val)))
|
||||
|
||||
(mf/defc numeric-input
|
||||
{::mf/wrap-props false
|
||||
::mf/forward-ref true}
|
||||
|
@ -81,15 +76,15 @@
|
|||
(let [input-node (mf/ref-val ref)
|
||||
new-value (-> (dom/get-value input-node)
|
||||
(sm/expr-eval value))]
|
||||
(when (num? new-value)
|
||||
(when (d/num? new-value)
|
||||
(-> new-value
|
||||
(cljs.core/max us/min-safe-int)
|
||||
(cljs.core/min us/max-safe-int)
|
||||
(cond->
|
||||
(num? min-val)
|
||||
(d/num? min-val)
|
||||
(cljs.core/max min-val)
|
||||
|
||||
(num? max-val)
|
||||
(d/num? max-val)
|
||||
(cljs.core/min max-val)))))))
|
||||
|
||||
update-input
|
||||
|
@ -120,18 +115,18 @@
|
|||
|
||||
new-value (+ current-value increment)
|
||||
new-value (cond
|
||||
(and wrap-value? (num? max-val) (num? min-val)
|
||||
(and wrap-value? (d/num? max-val min-val)
|
||||
(> new-value max-val) up?)
|
||||
(-> new-value (- max-val) (+ min-val) (- step-val))
|
||||
|
||||
(and wrap-value? (num? min-val) (num? max-val)
|
||||
(and wrap-value? (d/num? max-val min-val)
|
||||
(< new-value min-val) down?)
|
||||
(-> new-value (- min-val) (+ max-val) (+ step-val))
|
||||
|
||||
(and (num? min-val) (< new-value min-val))
|
||||
(and (d/num? min-val) (< new-value min-val))
|
||||
min-val
|
||||
|
||||
(and (num? max-val) (> new-value max-val))
|
||||
(and (d/num? max-val) (> new-value max-val))
|
||||
max-val
|
||||
|
||||
:else new-value)]
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
(ns app.main.ui.workspace.viewport.gradients
|
||||
"Gradients handlers and renders"
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
|
@ -300,7 +301,7 @@
|
|||
(let [scale-factor-y (/ gradient-length (/ height 2))
|
||||
norm-dist (/ (gpt/distance point from-p)
|
||||
(* (/ width 2) scale-factor-y))]
|
||||
(when (and norm-dist (mth/finite? norm-dist))
|
||||
(when (and norm-dist (d/num? norm-dist))
|
||||
(change! {:width norm-dist})))))]
|
||||
|
||||
(when (and gradient
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
(ns app.main.ui.workspace.viewport.scroll-bars
|
||||
(:require
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.rect :as gpr]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.store :as st]
|
||||
|
@ -169,7 +168,7 @@
|
|||
:y2 (+ vbox-y (:height vbox))
|
||||
:width (:width vbox)
|
||||
:height (:height vbox)}
|
||||
containing-rect (gpr/join-selrects [base-objects-rect vbox-rect])
|
||||
containing-rect (gsh/join-selrects [base-objects-rect vbox-rect])
|
||||
height-factor (/ (:height containing-rect) vbox-height)
|
||||
width-factor (/ (:width containing-rect) vbox-width)]
|
||||
(mf/set-ref-val! start-ref start-pt)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
(ns app.util.geom.grid
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.math :as mth]))
|
||||
|
||||
|
@ -39,7 +40,7 @@
|
|||
|
||||
gutter (if (= :stretch type)
|
||||
(let [gutter (/ (- width (* width' size) (* margin 2)) (dec size))]
|
||||
(if (mth/finite? gutter) gutter 0))
|
||||
(if (d/num? gutter) gutter 0))
|
||||
gutter)
|
||||
|
||||
next-v (fn [cur-val]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue