Skip to content

Commit

Permalink
Remove input for naming tables, call them frames
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Mar 4, 2024
1 parent 0273dc5 commit 2b5c850
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/bean/grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
:representation "f"}
"hget" {:scalar functions/bean-hget
:representation "f"}
"table" {:scalar functions/bean-table
"frame" {:scalar functions/bean-table
:representation "f"}
"filter" {:scalar functions/bean-filter
:representation "f"}
Expand Down
1 change: 0 additions & 1 deletion src/bean/ui/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
:row-heights (vec (repeat num-rows (:cell-h styles/sizes)))
:col-widths (vec (repeat num-cols (:cell-w styles/sizes)))}))
:ui {:help-display false
:making-table nil
:grid {:editing-cell nil
:selection nil
:selected-table nil}}}))
19 changes: 8 additions & 11 deletions src/bean/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@
(fn [db [_ selection]]
(assoc-in db [:ui :grid :selection] selection)))

(rf/reg-event-db
::making-table
(fn making-table [db [_]]
(assoc-in db [:ui :making-table] true)))

(rf/reg-event-fx
::select-table
(fn select-table [{:keys [db]} [_ table-name]]
Expand All @@ -115,12 +110,14 @@
(when start {:fx [[:dispatch [::edit-cell start]]]})))))

(rf/reg-event-fx
::make-table
(fn make-table [{:keys [db]} [_ table-name area]]
{:db (-> db
(assoc-in [:ui :making-table] false)
(update-in [:sheet] #(tables/make-table % table-name area)))
:fx [[:dispatch [::select-table table-name]]]}))
::make-frame
(fn make-frame [{:keys [db]} [_ area]]
(let [frame-number (inc (get-in db [:sheet :last-table-number]))
frame-name (str "Frame " frame-number)]
{:db (-> db
(assoc-in [:sheet :last-table-number] frame-number)
(update-in [:sheet] #(tables/make-table % frame-name area)))
:fx [[:dispatch [::select-table frame-name]]]})))

(rf/reg-event-db
::add-labels
Expand Down
6 changes: 2 additions & 4 deletions src/bean/ui/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
:cell-error-color 0xb93333
:selection 0x888888
:selection-alpha 0.06
:table-border 0xaaaaaa
:table-highlight 0x3b5aa3
:table-highlight-hover 0x8190b5
:table-name 0xffffff})
:table-border 0x3b5aa3
:table-name 0x3b5aa3})

(def colors light)

Expand Down
40 changes: 13 additions & 27 deletions src/bean/ui/views/sheet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,19 @@
grid)
g))

(defn- draw-table-highlight [^js g table-name x y w h & [hover?]]
(defn- draw-table-name [^js g table-name x y]
(let [font-size (:table-name-font styles/sizes)
text-bitmap (new pixi/BitmapText table-name
#js {:fontName "SpaceGrotesk"
:tint (:table-name styles/colors)
:fontSize font-size})
color (if hover?
(:table-highlight-hover styles/colors)
(:table-highlight styles/colors))
padding (:table-name-padding styles/sizes)
padded #(+ (* 2 padding) %)]
(.lineStyle g (:table-highlight styles/sizes) color 1 0.5)
(.drawRect g x y w h)
(.beginFill g color 1)
(.beginFill g 0xffffff 1)
(.drawRect g x
(- y (padded font-size))
(padded (.-width text-bitmap))
(padded font-size))
(.beginFill g 0x0000000 0)
(dec (padded font-size)))
(set! (.-x text-bitmap) (+ x padding))
(set! (.-y text-bitmap) (- y (padded font-size)))
(.addChild g text-bitmap)
Expand Down Expand Up @@ -436,12 +430,11 @@
(.drawRect g
(nth xs c) (+ (nth ys r) label-r)
(nth col-widths c) 4))))
(let [[r c] label]
(.beginFill g color 0.25)
(.drawRect g
(nth xs c) (nth ys r)
(cell-w c (get-in sheet [:grid r c]) col-widths)
(cell-h r (get-in sheet [:grid r c]) row-heights))))
(.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)))
(draw-skipped-cells g textures sheet skipped-cells row-heights col-widths xs ys)
(.endFill g))
g))
Expand All @@ -454,30 +447,23 @@
(let [[x y w h] (area->xywh table-data row-heights col-widths)
border (new pixi/Graphics)
highlight (new pixi/Graphics)
highlight-on-hover
(fn []
(.on border "pointerover"
#(draw-table-highlight highlight table-name x y w h true))
(.on border "pointerout"
#(-> highlight (.clear) (.removeChildren))))
extra-hitarea-y (+ (* 2 (:table-name-padding styles/sizes))
(:table-name-font styles/sizes))]
(-> g (.addChild border) (.addChild highlight))
(set! (.-eventMode border) "static")
(set! (.-hitArea border) (new pixi/Rectangle
x (- y extra-hitarea-y)
w (+ h extra-hitarea-y)))
(.lineStyle border (:table-border styles/sizes) (:table-border styles/colors) 1 0.5)
(.lineStyle border (:table-border styles/sizes) (:table-border styles/colors) 0.5 0.5)
(.drawRect border x y w h)
(draw-table-name highlight table-name x y)
(.addChild g (draw-label-bounds textures sheet table-name (:labels table-data) row-heights col-widths))

(if (= selected-table table-name)
(when (= selected-table table-name)
(let [label-controls (draw-label-controls textures table-name selection)]
(draw-table-highlight highlight table-name x y w h)
(.addChild g (draw-label-bounds textures sheet table-name (:labels table-data) row-heights col-widths))
(.addChild g label-controls)
(set! (.-x label-controls) (+ x w 5))
(set! (.-y label-controls) y))
(highlight-on-hover))))))
(set! (.-y label-controls) y)))))))

(defn- draw-cell-backgrounds
([] (let [g (new pixi/Graphics)]
Expand Down
66 changes: 24 additions & 42 deletions src/bean/ui/views/sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,32 @@
[bean.area :as area]))

(defn tables-list []
(let [table-name (atom nil)]
(fn []
(let [tables @(rf/subscribe [::subs/tables])
selection @(rf/subscribe [::subs/selection])
making-table (:making-table @(rf/subscribe [::subs/ui]))]
(fn []
(let [tables @(rf/subscribe [::subs/tables])
selection @(rf/subscribe [::subs/selection])]
[:div
[:div {:class :tables-header}
[:img {:src "img/table-icon.png"
:class :table-icon}]
[:p {:style {:line-height "1.2rem"}}
"Frames"]
[:button {:class :controls-btn
:style {:margin-left :auto
:margin-right "3px"}
:disabled (area/area-empty? selection)
:on-click #(rf/dispatch [::events/make-frame selection])}
"Make frame"]]
[:div {:class :tables-list-items}
[:div
[:div {:class :tables-header}
[:img {:src "img/table-icon.png"
:class :table-icon}]
[:p {:style {:line-height "1.2rem"}}
"Tables"]
[:button {:class :controls-btn
:style {:margin-left :auto
:margin-right "3px"}
:disabled (area/area-empty? selection)
:on-click #(rf/dispatch [::events/making-table])}
"Make Table"]]
[:div {:class :tables-list-items}
[:div
(doall
(for [[table-name] tables]
[:div {:key table-name
:class :tables-list-item}
(doall
(for [[table-name] tables]
[:div {:key table-name
:class :tables-list-item}

[:a {:on-click #(rf/dispatch [::events/select-table table-name])}
[:img {:src "img/made-table-icon.png"
:class :table-icon}]
table-name]]))
(when (and making-table (not (area/area-empty? selection)))
[:div {:class :tables-list-item}
[:form
{:on-submit #(.preventDefault %)
:class [:make-table-form]}
[:input {:class :make-table-input
:auto-focus true
:on-change #(reset! table-name (-> % .-target .-value))
:placeholder "Table name"}]
[:button {:class :controls-btn
:style {:margin-left "-3px"
:margin-right "0"
:height "26px"}
:type :submit
:on-click #(rf/dispatch [::events/make-table @table-name selection])}
"Create Table"]]])]]]))))
[:a {:on-click #(rf/dispatch [::events/select-table table-name])}
[:img {:src "img/made-table-icon.png"
:class :table-icon}]
table-name]]))]]])))

(defn sidebar []
[:div {:class :sidebar}
Expand Down

0 comments on commit 2b5c850

Please sign in to comment.