From 37fdf51eafc88cf987bf5c122d70b4c5647431fb Mon Sep 17 00:00:00 2001 From: Eva Date: Thu, 5 May 2022 14:42:22 +0200 Subject: [PATCH] :bug: Fix copying layout values with only multiple decimals --- .../ui/viewer/handoff/attributes/layout.cljs | 23 ++++++++++--------- frontend/src/app/util/code_gen.cljs | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/main/ui/viewer/handoff/attributes/layout.cljs b/frontend/src/app/main/ui/viewer/handoff/attributes/layout.cljs index fe748716c..06e87bce7 100644 --- a/frontend/src/app/main/ui/viewer/handoff/attributes/layout.cljs +++ b/frontend/src/app/main/ui/viewer/handoff/attributes/layout.cljs @@ -8,9 +8,9 @@ (:require [app.common.spec.radius :as ctr] [app.main.ui.components.copy-button :refer [copy-button]] + [app.main.ui.formats :as fmt] [app.util.code-gen :as cg] [app.util.i18n :refer [tr]] - [app.util.strings :as ust] [cuerdas.core :as str] [rumext.alpha :as mf])) @@ -35,50 +35,51 @@ (mf/defc layout-block [{:keys [shape]}] (let [selrect (:selrect shape) + _ (prn shape) {:keys [width height x y]} selrect] [:* [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.width")] - [:div.attributes-value (ust/format-precision width 2) "px"] + [:div.attributes-value (fmt/format-pixels width)] [:& copy-button {:data (copy-data selrect :width)}]] [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.height")] - [:div.attributes-value (ust/format-precision height 2) "px"] + [:div.attributes-value (fmt/format-pixels height)] [:& copy-button {:data (copy-data selrect :height)}]] (when (not= (:x shape) 0) [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.left")] - [:div.attributes-value (ust/format-precision x 2) "px"] + [:div.attributes-value (fmt/format-pixels x)] [:& copy-button {:data (copy-data selrect :x)}]]) (when (not= (:y shape) 0) [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.top")] - [:div.attributes-value (ust/format-precision y 2) "px"] + [:div.attributes-value (fmt/format-pixels y)] [:& copy-button {:data (copy-data selrect :y)}]]) (when (ctr/radius-1? shape) [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.radius")] - [:div.attributes-value (ust/format-precision (:rx shape 0) 2) "px"] + [:div.attributes-value (fmt/format-pixels (:rx shape 0))] [:& copy-button {:data (copy-data shape :rx)}]]) (when (ctr/radius-4? shape) [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.radius")] [:div.attributes-value - (ust/format-precision (:r1 shape) 2) ", " - (ust/format-precision (:r2 shape) 2) ", " - (ust/format-precision (:r3 shape) 2) ", " - (ust/format-precision (:r4 shape) 2) "px"] + (fmt/format-number (:r1 shape)) ", " + (fmt/format-number (:r2 shape)) ", " + (fmt/format-number (:r3 shape))", " + (fmt/format-pixels (:r4 shape))] [:& copy-button {:data (copy-data shape :r1)}]]) (when (not= (:rotation shape 0) 0) [:div.attributes-unit-row [:div.attributes-label (tr "handoff.attributes.layout.rotation")] - [:div.attributes-value (ust/format-precision (:rotation shape) 2) "deg"] + [:div.attributes-value (fmt/format-number (:rotation shape)) "deg"] [:& copy-button {:data (copy-data shape :rotation)}]])])) diff --git a/frontend/src/app/util/code_gen.cljs b/frontend/src/app/util/code_gen.cljs index 3c9162378..dbaf51da2 100644 --- a/frontend/src/app/util/code_gen.cljs +++ b/frontend/src/app/util/code_gen.cljs @@ -8,6 +8,7 @@ (:require [app.common.data :as d] [app.common.text :as txt] + [app.main.ui.formats :as fmt] [app.util.color :as uc] [cuerdas.core :as str])) @@ -108,7 +109,7 @@ (every? #(or (nil? %) (= % 0)) value) (or (nil? value) (= value 0)))) - default-format (fn [value] (str value "px")) + default-format (fn [value] (str (fmt/format-pixels value))) format-property (fn [prop] (let [css-prop (or (prop to-prop) (name prop)) format-fn (or (prop format) default-format)