mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
✨ Add keep aspect ratio flag to image fills
This commit is contained in:
parent
63e74545ab
commit
ea2173bd30
11 changed files with 71 additions and 22 deletions
|
@ -22,8 +22,8 @@
|
||||||
:proportion (/ width height)
|
:proportion (/ width height)
|
||||||
:proportion-lock true)))
|
:proportion-lock true)))
|
||||||
|
|
||||||
(defn setup-proportions-svg
|
(defn setup-proportions-size
|
||||||
[{:keys [width height] :as shape}]
|
[{{:keys [width height]} :selrect :as shape}]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:proportion (/ width height)
|
:proportion (/ width height)
|
||||||
:proportion-lock true))
|
:proportion-lock true))
|
||||||
|
@ -35,9 +35,11 @@
|
||||||
:proportion-lock false))
|
:proportion-lock false))
|
||||||
|
|
||||||
(defn setup-proportions
|
(defn setup-proportions
|
||||||
[shape]
|
[{:keys [type] :as shape}]
|
||||||
(case (:type shape)
|
(let [image-fill? (every? #(some? (:fill-image %)) (:fills shape))]
|
||||||
:svg-raw (setup-proportions-svg shape)
|
(cond
|
||||||
:image (setup-proportions-image shape)
|
(= type :svg-raw) (setup-proportions-size shape)
|
||||||
:text shape
|
(= type :image) (setup-proportions-image shape)
|
||||||
(setup-proportions-const shape)))
|
image-fill? (setup-proportions-size shape)
|
||||||
|
(= type :text) shape
|
||||||
|
:else (setup-proportions-const shape))))
|
||||||
|
|
|
@ -52,7 +52,8 @@
|
||||||
[:width :int]
|
[:width :int]
|
||||||
[:height :int]
|
[:height :int]
|
||||||
[:mtype {:optional true} [:maybe :string]]
|
[:mtype {:optional true} [:maybe :string]]
|
||||||
[:id ::sm/uuid]])
|
[:id ::sm/uuid]
|
||||||
|
[:keep-aspect-ratio {:optional true} :boolean]])
|
||||||
|
|
||||||
(sm/define! ::gradient
|
(sm/define! ::gradient
|
||||||
[:map {:title "Gradient"}
|
[:map {:title "Gradient"}
|
||||||
|
|
|
@ -72,7 +72,8 @@
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:mtype mtype
|
:mtype mtype
|
||||||
:id id}}]}]
|
:id id
|
||||||
|
:keep-aspect-ratio true}}]}]
|
||||||
(rx/of (dwsh/create-and-add-shape :rect x y shape))))))
|
(rx/of (dwsh/create-and-add-shape :rect x y shape))))))
|
||||||
|
|
||||||
(defn svg-uploaded
|
(defn svg-uploaded
|
||||||
|
@ -358,7 +359,8 @@
|
||||||
:id id
|
:id id
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:mtype mtype}}]
|
:mtype mtype
|
||||||
|
:keep-aspect-ratio true}}]
|
||||||
:name name
|
:name name
|
||||||
:frame-id (:id frame-shape)
|
:frame-id (:id frame-shape)
|
||||||
:parent-id (:id frame-shape)})]
|
:parent-id (:id frame-shape)})]
|
||||||
|
|
|
@ -117,9 +117,10 @@
|
||||||
:style style}]
|
:style style}]
|
||||||
(if (:fill-image value)
|
(if (:fill-image value)
|
||||||
(let [uri (cf/resolve-file-media (:fill-image value))
|
(let [uri (cf/resolve-file-media (:fill-image value))
|
||||||
|
keep-ar? (-> value :fill-image :keep-aspect-ratio)
|
||||||
image-props #js {:id (dm/str "fill-image-" render-id "-" fill-index)
|
image-props #js {:id (dm/str "fill-image-" render-id "-" fill-index)
|
||||||
:href (get uris uri uri)
|
:href (get uris uri uri)
|
||||||
:preserveAspectRatio "xMidYMid slice"
|
:preserveAspectRatio (if keep-ar? "xMidYMid slice" "none")
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:key (dm/str fill-index)
|
:key (dm/str fill-index)
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
grid-template-areas: "left-sidebar viewport right-sidebar";
|
grid-template-areas: "left-sidebar viewport right-sidebar";
|
||||||
grid-template-rows: 1fr;
|
grid-template-rows: 1fr;
|
||||||
grid-template-columns: auto 1fr auto;
|
grid-template-columns: auto 1fr auto;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
.workspace-loader {
|
.workspace-loader {
|
||||||
@include flexCenter;
|
@include flexCenter;
|
||||||
|
|
|
@ -84,7 +84,10 @@
|
||||||
on-fill-image-success
|
on-fill-image-success
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [image]
|
(fn [image]
|
||||||
(st/emit! (dc/update-colorpicker-color {:image (select-keys image [:id :width :height :mtype :name])} (not @drag?)))))
|
(st/emit! (dc/update-colorpicker-color
|
||||||
|
{:image (-> (select-keys image [:id :width :height :mtype :name])
|
||||||
|
(assoc :keep-aspect-ratio true))}
|
||||||
|
(not @drag?)))))
|
||||||
|
|
||||||
on-fill-image-click
|
on-fill-image-click
|
||||||
(mf/use-callback #(dom/click (mf/ref-val fill-image-ref)))
|
(mf/use-callback #(dom/click (mf/ref-val fill-image-ref)))
|
||||||
|
@ -94,6 +97,16 @@
|
||||||
(fn [file]
|
(fn [file]
|
||||||
(st/emit! (dwm/upload-fill-image file on-fill-image-success))))
|
(st/emit! (dwm/upload-fill-image file on-fill-image-success))))
|
||||||
|
|
||||||
|
handle-change-keep-aspect-ratio
|
||||||
|
(mf/use-fn
|
||||||
|
(mf/deps current-color)
|
||||||
|
(fn []
|
||||||
|
(let [keep-aspect-ratio? (-> current-color :image :keep-aspect-ratio not)]
|
||||||
|
(st/emit! (dc/update-colorpicker-color
|
||||||
|
{:image (-> (:image current-color)
|
||||||
|
(assoc :keep-aspect-ratio keep-aspect-ratio?))}
|
||||||
|
true)))))
|
||||||
|
|
||||||
set-tab!
|
set-tab!
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [event]
|
(fn [event]
|
||||||
|
@ -248,11 +261,23 @@
|
||||||
:on-select-stop handle-change-stop}])
|
:on-select-stop handle-change-stop}])
|
||||||
|
|
||||||
(if (= selected-mode :image)
|
(if (= selected-mode :image)
|
||||||
(let [uri (cfg/resolve-file-media (:image current-color))]
|
(let [uri (cfg/resolve-file-media (:image current-color))
|
||||||
|
keep-aspect-ratio? (-> current-color :image :keep-aspect-ratio)]
|
||||||
[:div {:class (stl/css :select-image)}
|
[:div {:class (stl/css :select-image)}
|
||||||
[:div {:class (stl/css :content)}
|
[:div {:class (stl/css :content)}
|
||||||
(when (:image current-color)
|
(when (:image current-color)
|
||||||
[:img {:src uri}])]
|
[:img {:src uri}])]
|
||||||
|
|
||||||
|
[:div {:class (stl/css :checkbox-option)}
|
||||||
|
[:label {:for "keep-aspect-ratio"
|
||||||
|
:class (stl/css-case :global/checked keep-aspect-ratio?)}
|
||||||
|
[:span {:class (stl/css-case :global/checked keep-aspect-ratio?)}
|
||||||
|
(when keep-aspect-ratio? i/status-tick-refactor)]
|
||||||
|
(tr "media.keep-aspect-ratio")
|
||||||
|
[:input {:type "checkbox"
|
||||||
|
:id "keep-aspect-ratio"
|
||||||
|
:checked keep-aspect-ratio?
|
||||||
|
:on-change handle-change-keep-aspect-ratio}]]]
|
||||||
[:button
|
[:button
|
||||||
{:class (stl/css :choose-image)
|
{:class (stl/css :choose-image)
|
||||||
:title (tr "media.choose-image")
|
:title (tr "media.choose-image")
|
||||||
|
|
|
@ -166,3 +166,8 @@
|
||||||
margin-top: $s-12;
|
margin-top: $s-12;
|
||||||
height: $s-32;
|
height: $s-32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.checkbox-option {
|
||||||
|
@extend .input-checkbox;
|
||||||
|
margin: $s-16 0 0 0;
|
||||||
|
}
|
||||||
|
|
|
@ -166,16 +166,16 @@
|
||||||
:y -11
|
:y -11
|
||||||
:width (max 0 (- text-width text-pos-x))
|
:width (max 0 (- text-width text-pos-x))
|
||||||
:height 20
|
:height 20
|
||||||
:class "workspace-frame-label"
|
:class (stl/css :workspace-frame-label-wrapper)
|
||||||
:style {:fill color}
|
:style {:fill color}
|
||||||
:visibility (if show-artboard-names? "visible" "hidden")
|
:visibility (if show-artboard-names? "visible" "hidden")}
|
||||||
:on-pointer-down on-pointer-down
|
|
||||||
:on-double-click on-double-click
|
|
||||||
:on-context-menu on-context-menu
|
|
||||||
:on-pointer-enter on-pointer-enter
|
|
||||||
:on-pointer-leave on-pointer-leave}
|
|
||||||
[:div {:class (stl/css :workspace-frame-label)
|
[:div {:class (stl/css :workspace-frame-label)
|
||||||
:style {:color color}}
|
:style {:color color}
|
||||||
|
:on-pointer-down on-pointer-down
|
||||||
|
:on-double-click on-double-click
|
||||||
|
:on-context-menu on-context-menu
|
||||||
|
:on-pointer-enter on-pointer-enter
|
||||||
|
:on-pointer-leave on-pointer-leave}
|
||||||
(if show-id?
|
(if show-id?
|
||||||
(dm/str (dm/str (:id frame)) " - " (:name frame))
|
(dm/str (dm/str (:id frame)) " - " (:name frame))
|
||||||
(:name frame))]]])))
|
(:name frame))]]])))
|
||||||
|
|
|
@ -63,10 +63,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.workspace-frame-label-wrapper {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.workspace-frame-label {
|
.workspace-frame-label {
|
||||||
font-size: $fs-12;
|
font-size: $fs-12;
|
||||||
color: black;
|
color: black;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
max-width: fit-content;
|
||||||
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5074,6 +5074,9 @@ msgstr "Gradient"
|
||||||
msgid "media.choose-image"
|
msgid "media.choose-image"
|
||||||
msgstr "Choose image"
|
msgstr "Choose image"
|
||||||
|
|
||||||
|
msgid "media.keep-aspect-ratio"
|
||||||
|
msgstr "Keep aspect ratio"
|
||||||
|
|
||||||
msgid "workspace.options.guides.title"
|
msgid "workspace.options.guides.title"
|
||||||
msgstr "Guides"
|
msgstr "Guides"
|
||||||
|
|
||||||
|
|
|
@ -5158,6 +5158,9 @@ msgstr "Gradiente"
|
||||||
msgid "media.choose-image"
|
msgid "media.choose-image"
|
||||||
msgstr "Elegir imagen"
|
msgstr "Elegir imagen"
|
||||||
|
|
||||||
|
msgid "media.keep-aspect-ratio"
|
||||||
|
msgstr "Mantener la proporción"
|
||||||
|
|
||||||
msgid "workspace.options.guides.title"
|
msgid "workspace.options.guides.title"
|
||||||
msgstr "Guías"
|
msgstr "Guías"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue