Skip to content

Commit

Permalink
WIP top left labels
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Jun 23, 2024
1 parent 7438222 commit 86bf7fb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Binary file added public/img/top-left-label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions src/bean/frames.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,32 @@
[r* c*]))
(sort-by (fn [[[r _] _]] r) labels)))

(defn debug [x] (prn x) x)

(defn- top-left-blocking-label [sheet [r c] labels]
(prn "labels for" [r c])
(or (debug
(some
(fn [[[r* c*] {:keys [dirn]}]]
(when (= dirn :top-left)
(cond
(and (= r* (last-row [r c] sheet))
(> c* (last-col [r c] sheet))) [nil c*]
(and (= c* (last-col [r c] sheet))
(> r* (last-row [r c] sheet))) [r* nil]
(and (> r* (last-row [r c] sheet))
(> c* (last-col [r c] sheet))) [r* c*])))
(sort-by (fn [[[r _] _]] r) (dissoc labels [r c]))))
(top-blocking-label sheet [r c] labels)
(left-blocking-label sheet [r c] labels)))

(defn blocking-label [sheet frame-name label]
(let [{:keys [labels] :as frame} (get-frame sheet frame-name)
{:keys [dirn]} (get-in frame [:labels label])]
(case dirn
:top (top-blocking-label sheet label labels)
;; haha
:top-left (top-left-blocking-label sheet label labels)
:left (left-blocking-label sheet label labels))))

(defn label->cells [sheet frame-name label]
Expand All @@ -121,12 +142,14 @@
(as->
(area/area->addresses
{:start label
:end (let [[br bc] (blocking-label sheet frame-name label)]
:end (let [[br bc] (blocking-label sheet frame-name label)]
(case dirn
:top [(if br (dec br) frame-end-r)
(min (last-col label sheet) frame-end-c)]
:left [(min (last-row label sheet) frame-end-r)
(if bc (dec bc) frame-end-c)]))}) cells
(if bc (dec bc) frame-end-c)]
:top-left [(if br br frame-end-r)
(if bc bc frame-end-c)]))}) cells
(apply disj cells (filter #(get labels %) cells))
(apply disj cells merged-with-labels)))))

Expand Down
26 changes: 21 additions & 5 deletions src/bean/ui/views/sheet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
(let [g (new pixi/Graphics)]
(.lineStyle g 2 0xcccccc 1 0.5)
(.beginFill g 0xffffff)
(.drawRoundedRect g 0 0 30 112 5)
(.drawRoundedRect g 0 0 30 137 5)
(set! (.-eventMode g) "static")
(.on g "pointerdown" #(.stopPropagation %))
(button! (new pixi/Sprite (:add-top-label icons))
Expand All @@ -457,11 +457,14 @@
(button! (new pixi/Sprite (:add-left-label icons))
g 5 30 20
#(add-label frame-name selection :left))
(button! (new pixi/Sprite (:add-skip-label icons))
(button! (new pixi/Sprite (:add-top-left-label icons))
g 5 55 20
#(add-label frame-name selection :top-left))
(button! (new pixi/Sprite (:add-skip-label icons))
g 5 80 20
#(mark-skip-cells frame-name selection))
(button! (new pixi/Sprite (:trash-label icons))
g 5 80 20
g 5 105 20
#(remove-label frame-name selection))
g))

Expand All @@ -477,6 +480,11 @@
(set! (.. bg -tileScale -y) 1.7)
(.addChild g bg))))

(defn- draw-top-left-label-indicator [^js g cell-end-x cell-end-y]
(.drawRect g (- cell-end-x 15) (- cell-end-y 15) 15 15)
(.drawRect g (- cell-end-x 10) (- cell-end-y 10) 10 10)
(.drawRect g (- cell-end-x 3) (- cell-end-y 3) 3 3))

(defn- draw-label-bounds [textures sheet frame-name labels row-heights col-widths]
(let [xs (reductions + 0 col-widths)
ys (reductions + 0 row-heights)
Expand All @@ -495,12 +503,19 @@
:left (when (= r label-r)
(.drawRect g
(nth xs c) (+ (nth ys r) label-r)
(nth col-widths c) 4))))
(nth col-widths c) 4))
:top-left nil))
(.beginFill g color 0.25)
(.drawRect g
(nth xs label-c) (nth ys label-r)
(cell-w label-c (get-in sheet [:grid label-r label-c]) col-widths)
(cell-h label-r (get-in sheet [:grid label-r label-c]) row-heights)))
(cell-h label-r (get-in sheet [:grid label-r label-c]) row-heights))
(when (= dirn :top-left)
(draw-top-left-label-indicator g
(+ (nth xs label-c)
(cell-w label-c (get-in sheet [:grid label-r label-c]) col-widths))
(+ (nth ys label-r)
(cell-h label-r (get-in sheet [:grid label-r label-c]) row-heights)))))
(draw-skipped-cells g textures sheet skipped-cells row-heights col-widths xs ys)
(.endFill g))
g))
Expand Down Expand Up @@ -774,6 +789,7 @@
:corner corner
:textures {:add-top-label (.from pixi/Texture "/img/top-label.png")
:add-left-label (.from pixi/Texture "/img/left-label.png")
:add-top-left-label (.from pixi/Texture "/img/top-left-label.png")
:add-skip-label (.from pixi/Texture "/img/skip-label.png")
:stripes (.from pixi/Texture "/img/stripes.jpg")
:trash-label (.from pixi/Texture "/img/trash-label.png")}})
Expand Down

0 comments on commit 86bf7fb

Please sign in to comment.