From 2b5c850c96a39c477a610711bf4082d36045e0e9 Mon Sep 17 00:00:00 2001 From: prabhanshuguptagit Date: Sun, 3 Mar 2024 11:59:37 +0530 Subject: [PATCH] Remove input for naming tables, call them frames --- src/bean/grid.cljs | 2 +- src/bean/ui/db.cljs | 1 - src/bean/ui/events.cljs | 19 +++++----- src/bean/ui/styles.cljs | 6 ++-- src/bean/ui/views/sheet.cljs | 40 +++++++-------------- src/bean/ui/views/sidebar.cljs | 66 +++++++++++++--------------------- 6 files changed, 48 insertions(+), 86 deletions(-) diff --git a/src/bean/grid.cljs b/src/bean/grid.cljs index 0f60b6e..a0cb723 100644 --- a/src/bean/grid.cljs +++ b/src/bean/grid.cljs @@ -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"} diff --git a/src/bean/ui/db.cljs b/src/bean/ui/db.cljs index 8ad4fdf..488ff02 100644 --- a/src/bean/ui/db.cljs +++ b/src/bean/ui/db.cljs @@ -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}}})) diff --git a/src/bean/ui/events.cljs b/src/bean/ui/events.cljs index 82c9c8f..ce2a87e 100644 --- a/src/bean/ui/events.cljs +++ b/src/bean/ui/events.cljs @@ -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]] @@ -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 diff --git a/src/bean/ui/styles.cljs b/src/bean/ui/styles.cljs index 262c4d4..bd87faa 100644 --- a/src/bean/ui/styles.cljs +++ b/src/bean/ui/styles.cljs @@ -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) diff --git a/src/bean/ui/views/sheet.cljs b/src/bean/ui/views/sheet.cljs index 00326ad..3febb42 100644 --- a/src/bean/ui/views/sheet.cljs +++ b/src/bean/ui/views/sheet.cljs @@ -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) @@ -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)) @@ -454,12 +447,6 @@ (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)) @@ -467,17 +454,16 @@ (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)] diff --git a/src/bean/ui/views/sidebar.cljs b/src/bean/ui/views/sidebar.cljs index 2e1a7ea..64f6fcb 100644 --- a/src/bean/ui/views/sidebar.cljs +++ b/src/bean/ui/views/sidebar.cljs @@ -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}