0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 04:49:03 -05:00

Add align facilities.

This commit is contained in:
Andrey Antukh 2016-03-02 18:10:08 +02:00
parent 4499dfc787
commit 5d66a7e967
3 changed files with 24 additions and 7 deletions

View file

@ -56,6 +56,7 @@
{:family [sc/string] {:family [sc/string]
:style [sc/string] :style [sc/string]
:weight [sc/string] :weight [sc/string]
:align [sc/string]
:size [sc/number]}) :size [sc/number]})
(def ^:static +shape-radius-attrs-schema+ (def ^:static +shape-radius-attrs-schema+
@ -166,13 +167,14 @@
(when opacity {:opacity opacity}))))) (when opacity {:opacity opacity})))))
(defn update-font-attrs (defn update-font-attrs
[sid {:keys [family style weight size] :as opts}] [sid {:keys [family style weight size align] :as opts}]
(sc/validate! +shape-font-attrs-schema+ opts) (sc/validate! +shape-font-attrs-schema+ opts)
(reify (reify
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(update-in state [:shapes-by-id sid :font] (update-in state [:shapes-by-id sid :font]
merge merge
(when align {:align align})
(when family {:family family}) (when family {:family family})
(when style {:style style}) (when style {:style style})
(when weight {:weight weight}) (when weight {:weight weight})

View file

@ -135,12 +135,14 @@
(defn- build-style (defn- build-style
[{:keys [font]}] [{:keys [font]}]
(let [{:keys [family weight style size] (let [{:keys [family weight style size align]
:or {family "sourcesanspro" :or {family "sourcesanspro"
weight "normal" weight "normal"
style "normal" style "normal"
align "left"
size 16}} font] size 16}} font]
{:fontSize (str size "px") {:fontSize (str size "px")
:textAlign align
:fontFamily family :fontFamily family
:fontWeight weight :fontWeight weight
:fontStyle style})) :fontStyle style}))

View file

@ -511,6 +511,10 @@
params {:size (parse-int value)} params {:size (parse-int value)}
sid (:id shape)] sid (:id shape)]
(rs/emit! (uds/update-font-attrs sid params)))) (rs/emit! (uds/update-font-attrs sid params))))
(on-font-align-change [event value]
(let [params {:align value}
sid (:id shape)]
(rs/emit! (uds/update-font-attrs sid params))))
(on-font-style-change [event] (on-font-style-change [event]
(let [value (dom/event->value event) (let [value (dom/event->value event)
[weight style] (read-string value) [weight style] (read-string value)
@ -518,8 +522,9 @@
params {:style style params {:style style
:weight weight}] :weight weight}]
(rs/emit! (uds/update-font-attrs sid params))))] (rs/emit! (uds/update-font-attrs sid params))))]
(let [{:keys [family style weight size] (let [{:keys [family style weight size align]
:or {family "sourcesanspro" :or {family "sourcesanspro"
align "left"
style "normal" style "normal"
weight "normal" weight "normal"
size 16}} font size 16}} font
@ -553,10 +558,18 @@
[:span "Text align"] [:span "Text align"]
[:div.row-flex.align-icons [:div.row-flex.align-icons
[:span.current i/align-left] [:span {:class (when (= align "left") "current")
[:span i/align-right] :on-click #(on-font-align-change % "left")}
[:span i/align-center] i/align-left]
[:span i/align-justify] [:span {:class (when (= align "right") "current")
:on-click #(on-font-align-change % "right")}
i/align-right]
[:span {:class (when (= align "center") "current")
:on-click #(on-font-align-change % "center")}
i/align-center]
[:span {:class (when (= align "justify") "current")
:on-click #(on-font-align-change % "justify")}
i/align-justify]
]]])))) ]]]))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;