Skip to content

Commit 4458b44

Browse files
committed
Added animation auto-start control and deleting
1 parent 21ce26c commit 4458b44

File tree

8 files changed

+108
-8
lines changed

8 files changed

+108
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kiibohd-configurator",
33
"productName": "Kiibohd Configurator",
4-
"version": "0.1.0-alpha7",
4+
"version": "0.1.0-beta1",
55
"description": "Configuration utility for Input Club keyboards",
66
"keywords": [],
77
"dependencies": {

resources/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kiibohd-configurator",
33
"productName": "Kiibohd Configurator",
4-
"version": "0.1.0-alpha7",
4+
"version": "0.1.0-beta1",
55
"main": "main.js",
66
"description": "Configuration utility for Input Club keyboards",
77
"author": "Jeremy Bondeson <[email protected]> (https://input.club)",

src/kii/ui/conf/components/customize_canned.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
;; Add the animation & perform replacements
112112
(=>> [:conf/add-animation (keyword @name)
113113
{:settings (replace-all settings @values configurable)
114+
:type (:type animation)
114115
:frames (mapv #(replace-all % @values configurable) frames)}])
115116
;; Append the required custom-kll
116117
(when-not (str/empty-or-nil? (:custom-kll animation))

src/kii/ui/conf/components/main.cljs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[kii.ui.conf.components.config-visuals :refer [config-visuals]]
1414
[kii.ui.conf.components.static-colors :refer [static-colors]]
1515
[kii.ui.conf.components.customize-canned :refer [customize-canned]]
16+
[kii.ui.conf.components.manage-animations :refer [manage-animations]]
1617
))
1718

1819
(defn main-comp [active-tab mode]
@@ -45,7 +46,10 @@
4546
[kii.ui.conf.animation-visualize.components/visualizer]
4647
[:div
4748
[kii.ui.conf.config-tabs.components/config-tabs
48-
[{:id :customize-canned
49+
[{:id :manage-animations
50+
:icon "settings"
51+
:tab manage-animations}
52+
{:id :customize-canned
4953
:icon "build"
5054
:tab customize-canned}
5155
{:id :custom-animation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
(ns kii.ui.conf.components.manage-animations
2+
(:require [reagent.core :as r]
3+
[taoensso.timbre :as timbre :refer-macros [log logf]]
4+
[kii.ui.re-frame :refer [<<= <== =>> >=>]]
5+
[cljs-react-material-ui.reagent :as mui]
6+
[cljs-react-material-ui.icons :as mui-icons]
7+
[cuerdas.core :as str]
8+
[kii.util :as util]
9+
))
10+
11+
(defn alter-settings
12+
[setting f]
13+
(as-> setting x
14+
(str/split x ",")
15+
(f x)
16+
(str/join "," x)))
17+
18+
(defn manage-animations
19+
[]
20+
(let [animations (<<= [:conf/animations])]
21+
[:div
22+
[:h3 "Manage Visualizations"]
23+
[mui/table {:selectable false
24+
:wrapper-style {:margin-right "20px"}
25+
}
26+
[mui/table-header {:display-select-all false
27+
:adjust-for-checkbox false}
28+
[mui/table-row
29+
[mui/table-header-column "Name"]
30+
[mui/table-header-column "Auto-start?"]
31+
[mui/table-header-column "Actions"]
32+
]
33+
]
34+
[mui/table-body {:display-row-checkbox false}
35+
(for [[key animation] (seq animations)]
36+
^{:key key}
37+
[mui/table-row
38+
[mui/table-row-column (name key)]
39+
[mui/table-row-column
40+
[mui/toggle
41+
{:default-toggled (str/includes? (:settings animation) "start")
42+
:disabled (= "reaction" (:type animation))
43+
:on-toggle (fn [_ toggled]
44+
(>=> [:conf/partial-update-animation
45+
{:settings (alter-settings
46+
(:settings animation)
47+
(if toggled
48+
#(conj % "start")
49+
(fn [x] (filter #(not= (str/trim %) "start") x))))}
50+
key])
51+
)
52+
}]
53+
]
54+
[mui/table-row-column
55+
[mui/icon-button
56+
{:on-click #(>=> [:conf/delete-animation key])}
57+
[mui-icons/action-delete
58+
{:color "gray"
59+
:hover-color "black"}
60+
]
61+
]
62+
]
63+
]
64+
)]]
65+
]))

src/kii/ui/conf/handlers.cljs

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(ns kii.ui.conf.handlers
22
(:require [re-frame.core :as rf]
33
[kii.env :as env]
4+
[kii.util :refer [update-values]]
5+
[taoensso.timbre :as timbre :refer-macros [log logf]]
46
[kii.device.keyboard :as keyboard]
57
[kii.keys.firmware.map :as fw]
68
[kii.keys.core :as keys]
@@ -16,7 +18,7 @@
1618
[kii.ui.conf.custom-kll.handlers]
1719
[kii.ui.conf.subscriptions :as conf-sub]
1820
[kii.ui.conf.layer-select.subscriptions :as ls-sub]
19-
))
21+
[cuerdas.core :as str]))
2022

2123
(def default-conf
2224
{:mode :keymap
@@ -108,11 +110,35 @@
108110
(rf/reg-event-db :conf/add-animation add-animation)
109111

110112
(defn partial-update-animation
111-
[db [_ data]]
112-
(let [selected (-> db :conf :selected-animation)]
113-
(-> db (update-in [:conf :kll :animations selected] merge data))))
113+
[db [_ data name]]
114+
(let [name (or name (-> db :conf :selected-animation))]
115+
(-> db (update-in [:conf :kll :animations name] merge data))))
114116
(rf/reg-event-db :conf/partial-update-animation partial-update-animation)
115117

118+
(defn contains-animation
119+
[name line]
120+
(or
121+
(str/includes? line (str/fmt "A[%s]" name))
122+
(str/includes? line (str/fmt "A[%s," name))))
123+
124+
(defn delete-animation
125+
[db [_ name]]
126+
(-> db
127+
(update-in [:conf :kll :animations] #(dissoc % name))
128+
(update-in [:conf :kll :custom] (fn [m]
129+
(update-values
130+
m
131+
(fn [value]
132+
(as-> value x
133+
(str/rtrim x)
134+
(str/split x ";")
135+
(filterv #(not (contains-animation (clojure.core/name name) %)) x)
136+
(conj x "")
137+
(str/join ";" x))))))))
138+
139+
140+
(rf/reg-event-db :conf/delete-animation delete-animation)
141+
116142
;; === Triggers === ;;
117143

118144

src/kii/ui/conf/mode_select/components.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
[:button {:class (str (:btn mode-select-style) (if (= mode :visuals) " active"))
4747
:disabled (false? (:visuals-enabled? active-keyboard))
4848
:on-click #(when-not (= mode :visuals)
49-
(rf/dispatch [:conf/set-active-config-tab :custom-animation])
49+
(rf/dispatch [:conf/set-active-config-tab :manage-animations])
5050
(rf/dispatch [:conf/mode-update :visuals]))}
5151
"visuals"]])
5252

src/kii/util.cljs

+4
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@
4343
[s]
4444
(js/parseFloat s))
4545

46+
(defn update-values
47+
"Creates a new map by applying the function to the values in the map."
48+
[m f & args]
49+
(into {} (for [[k v] m] [k (apply f v args)])))

0 commit comments

Comments
 (0)