Rework multi edit of measures values

This commit is contained in:
Andrés Moya 2022-05-12 14:10:31 +02:00 committed by Alonso Torres
parent 180c355340
commit 95a2da5ebc
8 changed files with 100 additions and 36 deletions

View file

@ -187,8 +187,8 @@
update-fn
(fn [shape]
(if (some? (:content shape))
(update-text-content shape txt/is-root-node? attrs/merge attrs)
(assoc shape :content (attrs/merge {:type "root"} attrs))))
(update-text-content shape txt/is-root-node? d/txt-merge attrs)
(assoc shape :content (d/txt-merge {:type "root"} attrs))))
shape-ids (cond (cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
@ -240,7 +240,7 @@
shape-ids (cond
(cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids #(update-text-content % update-node? attrs/merge attrs))))))))
(rx/of (dch/update-shapes shape-ids #(update-text-content % update-node? d/txt-merge attrs))))))))
(defn migrate-node
[node]

View file

@ -6,7 +6,6 @@
(ns app.main.ui.workspace.shapes.text.viewport-texts
(:require
[app.common.attrs :as attrs]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
@ -50,7 +49,7 @@
(cond-> shape
(and (some? shape) (some? editor-content))
(assoc :content (attrs/merge content editor-content)))))
(assoc :content (d/txt-merge content editor-content)))))
(defn- update-text-shape
[{:keys [grow-type id]} node]

View file

@ -25,10 +25,12 @@
[:proportion-lock
:width :height
:x :y
:ox :oy
:rotation
:rx :ry
:r1 :r2 :r3 :r4
:selrect])
:selrect
:points])
(def ^:private type->options
{:bool #{:size :position :rotation}
@ -46,7 +48,7 @@
;; -- User/drawing coords
(mf/defc measures-menu
[{:keys [ids ids-with-children values type all-types shape] :as props}]
(let [options (if (= type :multiple)
(reduce #(union %1 %2) (map #(get type->options %) all-types))
(get type->options type))
@ -58,20 +60,36 @@
[shape])
frames (map #(deref (refs/object-by-id (:frame-id %))) old-shapes)
;; To show interactively the measures while the user is manipulating
;; the shape with the mouse, generate a copy of the shapes applying
;; the transient tranformations.
shapes (as-> old-shapes $
(map gsh/transform-shape $)
(map gsh/translate-to-frame $ frames))
values (let [{:keys [x y]} (-> shapes first :points gsh/points->selrect)]
;; For rotated or stretched shapes, the origin point we show in the menu
;; is not the (:x :y) shape attribute, but the top left coordinate of the
;; wrapping rectangle.
values (let [{:keys [x y]} (gsh/selection-rect [(first shapes)])]
(cond-> values
(not= (:x values) :multiple) (assoc :x x)
(not= (:y values) :multiple) (assoc :y y)))
(not= (:y values) :multiple) (assoc :y y)
;; In case of multiple selection, the origin point has been already
;; calculated and given in the fake :ox and :oy attributes. See
;; common/src/app/common/attrs.cljc
(some? (:ox values)) (assoc :x (:ox values))
(some? (:oy values)) (assoc :y (:oy values))))
;; For :height and :width we take those in the :selrect attribute, because
;; not all shapes have an own :width and :height (e. g. paths). Here the
;; rotation is ignored (selrect always has the original size excluding
;; transforms).
values (let [{:keys [width height]} (-> shapes first :selrect)]
(cond-> values
(not= (:width values) :multiple) (assoc :width width)
(not= (:height values) :multiple) (assoc :height height)))
;; The :rotation, however, does use the transforms.
values (let [{:keys [rotation] :or {rotation 0}} (-> shapes first)]
(cond-> values
(not= (:rotation values) :multiple) (assoc :rotation rotation)))
@ -85,7 +103,6 @@
radius-multi? (mf/use-state nil)
radius-input-ref (mf/use-ref nil)
on-preset-selected
(fn [width height]
(st/emit! (udw/update-dimensions ids :width width)