0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

🐛 Fix problem with border radius

This commit is contained in:
alonso.torres 2024-05-27 15:27:03 +02:00 committed by Andrey Antukh
parent 0576884a8b
commit 9498006fb8

View file

@ -13,14 +13,17 @@
[app.common.record :as crc] [app.common.record :as crc]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.text :as txt] [app.common.text :as txt]
[app.common.text :as txt]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.types.shape.radius :as ctsr]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace :as udw] [app.main.data.workspace :as udw]
[app.main.data.workspace.changes :as dwc] [app.main.data.workspace.changes :as dwc]
[app.main.data.workspace.selection :as dws] [app.main.data.workspace.selection :as dws]
[app.main.data.workspace.shape-layout :as dwsl] [app.main.data.workspace.shape-layout :as dwsl]
[app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.texts :as dwt]
[app.main.store :as st] [app.main.store :as st]
[app.plugins.flex :as flex] [app.plugins.flex :as flex]
[app.plugins.grid :as grid] [app.plugins.grid :as grid]
@ -29,6 +32,13 @@
(declare shape-proxy) (declare shape-proxy)
(defn text-props
[shape]
(d/merge
(dwt/current-root-values {:shape shape :attrs txt/root-attrs})
(dwt/current-paragraph-values {:shape shape :attrs txt/paragraph-attrs})
(dwt/current-text-values {:shape shape :attrs txt/text-node-attrs})))
(deftype ShapeProxy [$file $page $id] (deftype ShapeProxy [$file $page $id]
Object Object
(resize (resize
@ -147,37 +157,52 @@
{:name "borderRadius" {:name "borderRadius"
:get #(-> % proxy->shape :rx) :get #(-> % proxy->shape :rx)
:set (fn [self value] :set (fn [self value]
(let [id (obj/get self "$id")] (let [id (obj/get self "$id")
shape (proxy->shape self)]
(when (us/safe-int? value) (when (us/safe-int? value)
(st/emit! (dwc/update-shapes [id] #(assoc % :rx value :ry value))))))} (when (ctsr/radius-4? shape)
(st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-1)))
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-1 % value))))))}
{:name "borderRadiusTopLeft" {:name "borderRadiusTopLeft"
:get #(-> % proxy->shape :r1) :get #(-> % proxy->shape :r1)
:set (fn [self value] :set (fn [self value]
(let [id (obj/get self "$id")] (let [id (obj/get self "$id")
shape (proxy->shape self)]
(when (us/safe-int? value) (when (us/safe-int? value)
(st/emit! (dwc/update-shapes [id] #(assoc % :r1 value))))))} (when (ctsr/radius-4? shape)
(st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4)))
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r1 value))))))}
{:name "borderRadiusTopRight" {:name "borderRadiusTopRight"
:get #(-> % proxy->shape :r2) :get #(-> % proxy->shape :r2)
:set (fn [self value] :set (fn [self value]
(let [id (obj/get self "$id")] (let [id (obj/get self "$id")
shape (proxy->shape self)]
(when (us/safe-int? value) (when (us/safe-int? value)
(st/emit! (dwc/update-shapes [id] #(assoc % :r2 value))))))} (when (ctsr/radius-4? shape)
(st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4)))
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r2 value))))))}
{:name "borderRadiusBottomRight" {:name "borderRadiusBottomRight"
:get #(-> % proxy->shape :r3) :get #(-> % proxy->shape :r3)
:set (fn [self value] :set (fn [self value]
(let [id (obj/get self "$id")] (let [id (obj/get self "$id")
shape (proxy->shape self)]
(when (us/safe-int? value) (when (us/safe-int? value)
(st/emit! (dwc/update-shapes [id] #(assoc % :r3 value))))))} (when (ctsr/radius-4? shape)
(st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4)))
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r3 value))))))}
{:name "borderRadiusBottomLeft" {:name "borderRadiusBottomLeft"
:get #(-> % proxy->shape :r4) :get #(-> % proxy->shape :r4)
:set (fn [self value] :set (fn [self value]
(let [id (obj/get self "$id")] (let [id (obj/get self "$id")
shape (proxy->shape self)]
(when (us/safe-int? value) (when (us/safe-int? value)
(st/emit! (dwc/update-shapes [id] #(assoc % :r4 value))))))} (when (ctsr/radius-4? shape)
(st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4)))
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r4 value))))))}
{:name "opacity" {:name "opacity"
:get #(-> % proxy->shape :opacity) :get #(-> % proxy->shape :opacity)
@ -419,18 +444,24 @@
(obj/unset! "addFlexLayout"))) (obj/unset! "addFlexLayout")))
(cond-> (cfh/text-shape? data) (cond-> (cfh/text-shape? data)
(-> (crc/add-properties! (crc/add-properties!
{:name "characters" {:name "characters"
:get #(-> % proxy->shape :content txt/content->text) :get #(-> % proxy->shape :content txt/content->text)
:set (fn [self value] :set
(let [id (obj/get self "$id")] (fn [self value]
(st/emit! (dwc/update-shapes [id] #(txt/change-text % value)))))}) (let [id (obj/get self "$id")]
(st/emit! (dwc/update-shapes [id] #(txt/change-text % value)))))}
(crc/add-properties! {:name "growType"
{:name "growType" :get #(-> % proxy->shape :grow-type d/name)
:get #(-> % proxy->shape :grow-type d/name) :set
:set (fn [self value] (fn [self value]
(let [id (obj/get self "$id") (let [id (obj/get self "$id")
value (keyword value)] value (keyword value)]
(when (contains? #{:auto-width :auto-height :fixed} value) (when (contains? #{:auto-width :auto-height :fixed} value)
(st/emit! (dwc/update-shapes [id] #(assoc % :grow-type value))))))}))))))) (st/emit! (dwc/update-shapes [id] #(assoc % :grow-type value))))))}
{:name "fontId"
:get #(-> % proxy->shape text-props :font-id)
:set
(fn [self value])}))))))