mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 08:20:45 -05:00
Implement properly the multiselection handler.
This commit is contained in:
parent
1a44b75790
commit
e2af1a451b
3 changed files with 24 additions and 35 deletions
|
@ -79,7 +79,7 @@
|
|||
:on-mouse-down on-mouse-down
|
||||
:on-mouse-up on-mouse-up}
|
||||
(uusc/render-shape shape #(uusc/shape %))
|
||||
(when selected?
|
||||
(when (and selected? (= (count selected) 1))
|
||||
(handlers shape))])))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
(background)
|
||||
(grid 1)
|
||||
[:svg.page-layout {}
|
||||
#_(shapes-selection shapes-selected)
|
||||
(shapes-selection)
|
||||
[:g.main {}
|
||||
(for [item (:shapes page)]
|
||||
(-> (uus/shape item)
|
||||
|
|
|
@ -1,45 +1,34 @@
|
|||
(ns uxbox.ui.workspace.canvas.selection
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[rum.core :as rum]
|
||||
[beicon.core :as rx]
|
||||
[cats.labs.lens :as l]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.shapes :as sh]
|
||||
[uxbox.state :as ust]
|
||||
[uxbox.shapes :as ush]
|
||||
[uxbox.util.lens :as ul]
|
||||
[uxbox.ui.workspace.base :as wb]
|
||||
[uxbox.ui.mixins :as mx]
|
||||
[uxbox.util.dom :as dom]))
|
||||
[uxbox.ui.mixins :as mx]))
|
||||
|
||||
(def ^:private selection-circle-style
|
||||
{:fillOpacity "0.5"
|
||||
:strokeWidth "1px"
|
||||
:vectorEffect "non-scaling-stroke"})
|
||||
|
||||
(def ^:private default-selection-props
|
||||
{:r 5 :style selection-circle-style
|
||||
:fill "#333"
|
||||
:stroke "#333"})
|
||||
(def ^:const selected-shapes-l
|
||||
(letfn [(getter [state]
|
||||
(let [selected (get-in state [:workspace :selected])]
|
||||
(mapv #(get-in state [:shapes-by-id %]) selected)))]
|
||||
(as-> (ul/getter getter) $
|
||||
(l/focus-atom $ ust/state))))
|
||||
|
||||
(defn shapes-selection-render
|
||||
[own shapes]
|
||||
(when (seq shapes)
|
||||
(let [{:keys [width height x y]} (sh/outer-rect shapes)]
|
||||
(html
|
||||
[:g.controls
|
||||
[:rect {:x x :y y :width width :height height :stroke-dasharray "5,5"
|
||||
:style {:stroke "#333" :fill "transparent"
|
||||
:stroke-opacity "1"}}]
|
||||
[:circle.top-left (merge default-selection-props
|
||||
{:cx x :cy y})]
|
||||
[:circle.top-right (merge default-selection-props
|
||||
{:cx (+ x width) :cy y})]
|
||||
[:circle.bottom-left (merge default-selection-props
|
||||
{:cx x :cy (+ y height)})]
|
||||
[:circle.bottom-right (merge default-selection-props
|
||||
{:cx (+ x width) :cy (+ y height)})]]))))
|
||||
[own]
|
||||
(let [shapes (rum/react selected-shapes-l)]
|
||||
(when (> (count shapes) 1)
|
||||
(let [{:keys [width height x y]} (ush/outer-rect shapes)]
|
||||
(html
|
||||
[:g.controls
|
||||
[:rect {:x x :y y :width width :height height
|
||||
:stroke-dasharray "5,5"
|
||||
:style {:stroke "#333" :fill "transparent"
|
||||
:stroke-opacity "1"}}]])))))
|
||||
|
||||
(def ^:static shapes-selection
|
||||
(def ^:const shapes-selection
|
||||
(mx/component
|
||||
{:render shapes-selection-render
|
||||
:name "shapes-selection"
|
||||
:mixins [mx/static]}))
|
||||
:mixins [rum/reactive mx/static]}))
|
||||
|
|
Loading…
Reference in a new issue