|
158 | 158 | (load "extensions")
|
159 | 159 |
|
160 | 160 | (defmulti short-keyword-prop-help-string :type)
|
| 161 | +(defmethod short-keyword-prop-help-string :default [{:keys [type]}] |
| 162 | + (name type)) |
161 | 163 | (defn- short-prop-help-string [{:keys [type] :as prop-desc}]
|
162 | 164 | (if (symbol? type)
|
163 | 165 | (str "instance of " type)
|
164 | 166 | (short-keyword-prop-help-string prop-desc)))
|
165 |
| -(defmethod short-keyword-prop-help-string :default [{:keys [type]}] |
166 |
| - (name type)) |
167 |
| -(defmethod short-keyword-prop-help-string :desc [{:keys [of]}] |
168 |
| - (str "cljfx desc of " of)) |
169 |
| -(defmethod short-keyword-prop-help-string :enum [{:keys [of]}] |
170 |
| - (let [options (into (sorted-set) |
171 |
| - (map #(keyword (str/replace (str/lower-case (.name ^Enum %)) #"_" "-"))) |
172 |
| - (.getEnumConstants (resolve of)))] |
173 |
| - (str "either of: " (str/join ", " options)))) |
174 |
| - |
175 |
| -(defmethod short-keyword-prop-help-string :coll [{:keys [item]}] |
176 |
| - (str "coll of " (short-keyword-prop-help-string item))) |
177 |
| - |
178 |
| -(defmethod short-keyword-prop-help-string :add-props [{:keys [to props]}] |
179 |
| - (str (short-keyword-prop-help-string to) " with extra props (" (str/join ", "(sort (keys props))) ")")) |
180 | 167 |
|
181 |
| -(defmethod short-keyword-prop-help-string :pref-or-computed-size-double [_] |
182 |
| - (str "number, :use-computed-size or :use-pref-size")) |
183 |
| -(defmethod short-keyword-prop-help-string :computed-size-double [_] |
184 |
| - (str "number or :use-computed-size")) |
185 |
| -(defmethod short-keyword-prop-help-string :animation [_] |
186 |
| - (str "number or :indefinite")) |
187 |
| -(defmethod short-keyword-prop-help-string :animation-status [_] |
188 |
| - "either of: :running, :paused, :stopped") |
189 |
| -(defmethod short-keyword-prop-help-string :map [{:keys [key value]}] |
190 |
| - (str "map from " (short-keyword-prop-help-string key) " to " (short-keyword-prop-help-string value))) |
191 |
| -(defmethod short-keyword-prop-help-string :media-player-state [_] |
192 |
| - "either of: :playing, :paused, :stopped") |
193 |
| - |
194 |
| -(defmulti long-keyword-prop-help-string :type) |
195 |
| -(defmethod long-keyword-prop-help-string :default [prop] |
| 168 | +(defmulti long-keyword-prop-help-syntax :type) |
| 169 | +(defmethod long-keyword-prop-help-syntax :default [prop] |
196 | 170 | (short-keyword-prop-help-string prop))
|
197 |
| -(defn long-prop-help-string [{:keys [type] :as prop}] |
| 171 | +(defn long-prop-help-syntax [{:keys [type] :as prop}] |
198 | 172 | (if (symbol? type)
|
199 | 173 | (str "Instance of:\n" type)
|
200 |
| - (long-keyword-prop-help-string prop))) |
201 |
| -(defmethod long-keyword-prop-help-string :enum [{:keys [of]}] |
202 |
| - (let [consts (.getEnumConstants (resolve of))] |
203 |
| - (str "Enum:\n" |
204 |
| - of |
205 |
| - "\n\nIdiomatic values:\n- " |
206 |
| - (->> consts |
207 |
| - (map #(keyword (str/replace (str/lower-case (.name ^Enum %)) #"_" "-"))) |
208 |
| - (into (sorted-set)) |
209 |
| - (str/join "\n- ")) |
210 |
| - "\n\nAlso works:\n- " |
211 |
| - (->> consts |
212 |
| - (map #(str of "/" (.name ^Enum %))) |
213 |
| - sort |
214 |
| - (str/join "\n- "))))) |
215 |
| -(defmethod long-keyword-prop-help-string :insets [_] |
216 |
| - "Insets, either: |
217 |
| -- number |
218 |
| -- map with optional keys - :top, :bottom, :left, :right - numbers |
219 |
| -- literal - :empty |
220 |
| -- instance of javafx.geometry.Insets") |
221 |
| -(defmethod long-keyword-prop-help-string :image [_] |
222 |
| - "Image, either: |
223 |
| -- instance of javafx.scene.image.Image |
224 |
| -- string: either a resource path or URL string pointing to image |
225 |
| -- map with required :url (url string) or :is (input stream) keys and optional :requested-width (number), :requested-height (number), :preserve-ratio (boolean), :smooth (boolean) and :background-loading (boolean) keys") |
226 |
| -(defmethod long-keyword-prop-help-string :duration [_] |
227 |
| - "Duration, either: |
228 |
| -- tuple of number and time unit (:ms, :s, :m, or :h), e.g. [10 :s] |
229 |
| -- string in the format [number][ms|s|m|h], e.g. 10s |
230 |
| -- number (ms) |
231 |
| -- literal - :zero, :one (ms), :indefinite or :unknown |
232 |
| -- instance of javafx.util.Duration") |
233 |
| -(defmethod long-keyword-prop-help-string :font [_] |
234 |
| - "Font, either: |
235 |
| -- string, font family name |
236 |
| -- number, font size (of a default font) |
237 |
| -- literal - :default |
238 |
| -- map with required :family key (string) and optional :weight, :posture and :size (number) keys |
239 |
| -- instance of javafx.scene.text.Font") |
240 |
| - |
241 |
| -(comment |
242 |
| - (sort |
243 |
| - (clojure.set/difference |
244 |
| - (set (keys (.getMethodTable ^clojure.lang.MultiFn keyword-prop->spec-form))) |
245 |
| - (into #{:int :ifn :any :string :boolean} |
246 |
| - (keys (.getMethodTable ^clojure.lang.MultiFn long-keyword-prop-help-string)))))) |
| 174 | + (long-keyword-prop-help-syntax prop))) |
247 | 175 |
|
248 |
| -(defn- print-table [items & columns] |
249 |
| - (let [columns (vec columns) |
250 |
| - column-strs (mapv #(into [(:label %)] (map (comp str (:fn %))) items) columns) |
251 |
| - max-lengths (mapv #(transduce (map count) max 0 %) column-strs)] |
252 |
| - (dotimes [i (inc (count items))] |
253 |
| - (let [row (mapv #(% i) column-strs)] |
254 |
| - (println |
255 |
| - (str/join |
256 |
| - " " |
257 |
| - (map (fn [max-length item] |
258 |
| - (str item (str/join (repeat (- max-length (count item)) \space)))) |
259 |
| - max-lengths row))))))) |
| 176 | +(load "help") |
260 | 177 |
|
261 | 178 | (defn help
|
262 | 179 | ([fx-type]
|
|
265 | 182 | (let [r @registry
|
266 | 183 | props (get-in r [:props fx-type])
|
267 | 184 | type (get-in r [:types fx-type])]
|
| 185 | + (println "Cljfx type:") |
| 186 | + (println fx-type) |
| 187 | + (println) |
268 | 188 | (when (symbol? (:of type))
|
269 |
| - (println "Class:") |
| 189 | + (println "Instance class:") |
270 | 190 | (println (:of type))
|
271 | 191 | (println))
|
272 | 192 | (when (:req type)
|
|
278 | 198 | (println (str/join ", " (sort (:req type))))))
|
279 | 199 | (println))
|
280 | 200 | (when props
|
281 |
| - (print-table |
282 |
| - (sort (keys props)) |
283 |
| - {:label "Props" :fn identity} |
284 |
| - {:label "Value type" :fn #(-> % props short-prop-help-string)})) |
| 201 | + (println |
| 202 | + (str-table |
| 203 | + (sort (keys props)) |
| 204 | + {:label "Props" :fn identity} |
| 205 | + {:label "Value type" :fn #(-> % props short-prop-help-string)}))) |
285 | 206 | (when (and (not props) (:spec type))
|
286 | 207 | (println "Spec:")
|
287 | 208 | (println (s/form (:spec type))))
|
288 | 209 | (when (and (not type) (not props))
|
289 | 210 | (println '???)))
|
290 | 211 |
|
291 | 212 | (or (simple-symbol? fx-type) (class? fx-type))
|
292 |
| - (let [cls (if (symbol? fx-type) (resolve fx-type) fx-type) |
293 |
| - r @registry |
294 |
| - ts (->> r |
295 |
| - :types |
296 |
| - vals |
297 |
| - (filter (fn [{:keys [of]}] |
298 |
| - (and (symbol? of) |
299 |
| - (isa? (resolve of) cls)))) |
300 |
| - (sort-by (comp str :id)))] |
| 213 | + (let [ts (known-types-of fx-type)] |
301 | 214 | (println "Class:")
|
302 |
| - (println cls) |
| 215 | + (println fx-type) |
303 | 216 | (println)
|
304 | 217 | (when (seq ts)
|
305 |
| - (println "Known cljfx types:") |
306 |
| - (print-table |
307 |
| - ts |
308 |
| - {:label "Cljfx type" :fn :id} |
309 |
| - {:label "Class" :fn :of}))) |
| 218 | + (println "Fitting cljfx types:") |
| 219 | + (println |
| 220 | + (str-table |
| 221 | + ts |
| 222 | + {:label "Cljfx type" :fn :id} |
| 223 | + {:label "Class" :fn :of})))) |
310 | 224 |
|
311 | 225 | (*type->id* fx-type)
|
312 | 226 | (recur (*type->id* fx-type))
|
|
319 | 233 | (let [r @registry
|
320 | 234 | prop (get-in r [:props fx-type prop-kw])]
|
321 | 235 | (if prop
|
322 |
| - (println (long-prop-help-string prop)) |
| 236 | + (do |
| 237 | + (println (str "Prop of " fx-type " - " prop-kw)) |
| 238 | + (println) |
| 239 | + (println (convert-help-syntax-to-string (long-prop-help-syntax prop)))) |
323 | 240 | (println '???)))
|
324 | 241 |
|
325 | 242 | :else
|
326 | 243 | (println '???))))
|
327 | 244 |
|
328 |
| -(comment |
329 |
| - |
330 |
| - (help :image-view :image) |
331 |
| - (help :grid-pane :children) |
332 |
| - (help :grid-pane :node-orientation) |
333 |
| - (help :grid-pane :accessible-role) |
334 |
| - |
335 |
| - (help :text-formatter) |
336 |
| - (help :labeled :font)) |
337 |
| - |
338 | 245 | ;; next steps:
|
339 | 246 | ;; 1. api for looking up type and prop information:
|
340 |
| -;; - extended prop description |
341 | 247 | ;; - generic help?
|
342 | 248 | ;; 2. dev cljfx type->lifecycle wrapper that validates and contextualizes errors
|
343 | 249 | ;; in terms of a cljfx component hierarchy
|
|
0 commit comments