Skip to content

Commit d13fdc2

Browse files
committed
Add long prop help to all prop kinds
1 parent 9bd17b0 commit d13fdc2

File tree

3 files changed

+573
-133
lines changed

3 files changed

+573
-133
lines changed

src/cljfx/definitions.clj

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'[javafx.scene.input KeyCombination KeyCode]
1919
'[javafx.scene.effect FloatMap]
2020
'[javafx.scene.shape VertexFormat]
21-
'[javafx.geometry Insets Point3D Side BoundingBox]
21+
'[javafx.geometry Insets Point3D Side BoundingBox Rectangle2D]
2222
'[javafx.scene Cursor])
2323

2424
(defmethod keyword-prop->spec-form :pref-or-computed-size-double [_]
@@ -970,7 +970,7 @@
970970
(register-composite! :combo-box
971971
:parent :combo-box-base
972972
:props '{:button-cell {:type :ifn}
973-
:cell-factory {:type :cell-factory}
973+
:cell-factory {:type :cell-factory :of javafx.scene.control.ListCell}
974974
:converter {:type :string-converter}
975975
:items {:type :coll :item {:type :any}}
976976
:placeholder {:type :desc :of javafx.scene.Node}
@@ -1072,7 +1072,7 @@
10721072
:parent :combo-box-base
10731073
:props '{:chronology {:type :chronology}
10741074
:converter {:type :string-converter}
1075-
:day-cell-factory {:type :cell-factory}
1075+
:day-cell-factory {:type :cell-factory :of javafx.scene.control.DateCell}
10761076
:show-week-numbers {:type :boolean}}
10771077
:of 'javafx.scene.control.DatePicker)
10781078

@@ -1307,7 +1307,8 @@
13071307
`(s/or :map (s/keys :req-un [:cljfx.rectangle/min-x
13081308
:cljfx.rectangle/min-y
13091309
:cljfx.rectangle/width
1310-
:cljfx.rectangle/height])))
1310+
:cljfx.rectangle/height])
1311+
:instance (instance-of Rectangle2D)))
13111312

13121313
(register-composite! :image-view
13131314
:parent :node
@@ -1411,7 +1412,7 @@
14111412

14121413
(register-composite! :list-view
14131414
:parent :control
1414-
:props '{:cell-factory {:type :cell-factory}
1415+
:props '{:cell-factory {:type :cell-factory :of javafx.scene.control.ListCell}
14151416
:editable {:type :boolean}
14161417
:fixed-cell-size {:type :number}
14171418
:items {:type :coll :item {:type :any}}
@@ -2125,11 +2126,11 @@
21252126

21262127
(defmethod keyword-prop->spec-form :cell-value-factory [_]
21272128
`(s/or :fn ifn?
2128-
:instance Callback))
2129+
:instance (instance-of Callback)))
21292130

21302131
(register-composite! :table-column
21312132
:parent :table-column-base
2132-
:props '{:cell-factory {:type :cell-factory}
2133+
:props '{:cell-factory {:type :cell-factory :of javafx.scene.control.TableCell}
21332134
:cell-value-factory {:type :cell-value-factory}
21342135
:columns {:type :coll
21352136
:item {:type :add-props
@@ -2172,7 +2173,7 @@
21722173
:on-selected-item-changed {:type :event-handler :of javafx.beans.value.ChangeListener}
21732174
:on-sort {:type :event-handler :of javafx.event.EventHandler}
21742175
:placeholder {:type :desc :of javafx.scene.Node}
2175-
:row-factory {:type :cell-factory}
2176+
:row-factory {:type :cell-factory :of javafx.scene.control.TableRow}
21762177
:selection-mode {:type :enum :of javafx.scene.control.SelectionMode}
21772178
:sort-order {:type :coll
21782179
:item {:type :add-props
@@ -2355,7 +2356,7 @@
23552356

23562357
(register-composite! :tree-table-column
23572358
:parent :table-column-base
2358-
:props '{:cell-factory {:type :cell-factory}
2359+
:props '{:cell-factory {:type :cell-factory :of javafx.scene.control.TreeTableCell}
23592360
:cell-value-factory {:type :cell-value-factory}
23602361
:columns {:type :coll
23612362
:item {:type :add-props
@@ -2387,7 +2388,7 @@
23872388
:on-sort {:type :event-handler :of javafx.event.EventHandler}
23882389
:placeholder {:type :desc :of javafx.scene.Node}
23892390
:root {:type :desc :of javafx.scene.control.TreeItem}
2390-
:row-factory {:type :cell-factory}
2391+
:row-factory {:type :cell-factory :of javafx.scene.control.TreeTableRow}
23912392
:selection-mode {:type :enum :of javafx.scene.control.SelectionMode}
23922393
:show-root {:type :boolean}
23932394
:sort-mode {:type :enum :of javafx.scene.control.TreeSortMode}
@@ -2402,7 +2403,7 @@
24022403

24032404
(register-composite! :tree-view
24042405
:parent :control
2405-
:props '{:cell-factory {:type :cell-factory}
2406+
:props '{:cell-factory {:type :cell-factory :of javafx.scene.control.TreeCell}
24062407
:editable {:type :boolean}
24072408
:fixed-cell-size {:type :number}
24082409
:on-edit-cancel {:type :event-handler :of javafx.event.EventHandler}

src/cljfx/dev.clj

Lines changed: 28 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -158,105 +158,22 @@
158158
(load "extensions")
159159

160160
(defmulti short-keyword-prop-help-string :type)
161+
(defmethod short-keyword-prop-help-string :default [{:keys [type]}]
162+
(name type))
161163
(defn- short-prop-help-string [{:keys [type] :as prop-desc}]
162164
(if (symbol? type)
163165
(str "instance of " type)
164166
(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))) ")"))
180167

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]
196170
(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}]
198172
(if (symbol? type)
199173
(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)))
247175

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")
260177

261178
(defn help
262179
([fx-type]
@@ -265,8 +182,11 @@
265182
(let [r @registry
266183
props (get-in r [:props fx-type])
267184
type (get-in r [:types fx-type])]
185+
(println "Cljfx type:")
186+
(println fx-type)
187+
(println)
268188
(when (symbol? (:of type))
269-
(println "Class:")
189+
(println "Instance class:")
270190
(println (:of type))
271191
(println))
272192
(when (:req type)
@@ -278,35 +198,29 @@
278198
(println (str/join ", " (sort (:req type))))))
279199
(println))
280200
(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)})))
285206
(when (and (not props) (:spec type))
286207
(println "Spec:")
287208
(println (s/form (:spec type))))
288209
(when (and (not type) (not props))
289210
(println '???)))
290211

291212
(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)]
301214
(println "Class:")
302-
(println cls)
215+
(println fx-type)
303216
(println)
304217
(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}))))
310224

311225
(*type->id* fx-type)
312226
(recur (*type->id* fx-type))
@@ -319,25 +233,17 @@
319233
(let [r @registry
320234
prop (get-in r [:props fx-type prop-kw])]
321235
(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))))
323240
(println '???)))
324241

325242
:else
326243
(println '???))))
327244

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-
338245
;; next steps:
339246
;; 1. api for looking up type and prop information:
340-
;; - extended prop description
341247
;; - generic help?
342248
;; 2. dev cljfx type->lifecycle wrapper that validates and contextualizes errors
343249
;; in terms of a cljfx component hierarchy

0 commit comments

Comments
 (0)