Skip to content

Commit 7c9e0cc

Browse files
committed
Some updates for widgets v8
1 parent c69f304 commit 7c9e0cc

File tree

9 files changed

+570
-563
lines changed

9 files changed

+570
-563
lines changed

src/packages.lisp

Lines changed: 352 additions & 342 deletions
Large diffs are not rendered by default.

src/widgets/checkbox.lisp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
:accessor widget-indent
88
:documentation "Indent the control to align with other controls with a description."
99
:trait :bool))
10-
(:default-initargs
11-
:%model-name "CheckboxModel"
12-
:%view-name "CheckboxView")
10+
(:default-initargs :%model-name "CheckboxModel"
11+
:%view-name "CheckboxView"
12+
:style (make-instance 'checkbox-style))
1313
(:documentation "Displays a boolean `value` in the form of a checkbox."))
1414

1515

src/widgets/combobox.lisp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33

44
(defwidget combobox (description-widget continuous-update-slot disabled-slot placeholder-slot
5-
string-value-slot)
6-
((ensure-option
7-
:initarg :ensure-option
8-
:initform t
9-
:accessor widget-ensure-option
10-
:documentation "If set, ensure value is in options. Implies continuous_update=False."
11-
:trait :bool)
12-
(options
13-
:initarg :options
14-
:initform nil
15-
:accessor widget-options
16-
:documentation "Dropdown options for the combobox"
17-
:trait :string-list))
18-
(:default-initargs
19-
:%model-name "ComboboxModel"
20-
:%view-name "ComboboxView"))
5+
string-value-slot)
6+
((ensure-option :initarg :ensure-option
7+
:initform t
8+
:accessor widget-ensure-option
9+
:documentation "If set, ensure value is in options. Implies continuous_update=False."
10+
:trait :bool)
11+
(options :initarg :options
12+
:initform nil
13+
:accessor widget-options
14+
:documentation "Dropdown options for the combobox"
15+
:trait :string-list))
16+
(:default-initargs :%model-name "ComboboxModel"
17+
:%view-name "ComboboxView"
18+
:style (make-instance 'text-style)))
2119

2220

2321

src/widgets/dom-widget.lisp

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,29 @@
1919
:accessor widget-align-self
2020
:documentation "The align-self CSS attribute."
2121
:trait :string)
22-
(border
23-
:initarg :border
22+
(border-bottom
23+
:initarg :border-bottom
2424
:initform nil
25-
:accessor widget-border
26-
:documentation "The border CSS attribute."
25+
:accessor widget-border-bottom
26+
:documentation "The border botom CSS attribute."
27+
:trait :string)
28+
(border-left
29+
:initarg :border-left
30+
:initform nil
31+
:accessor widget-border-left
32+
:documentation "The border left CSS attribute."
33+
:trait :string)
34+
(border-right
35+
:initarg :border-right
36+
:initform nil
37+
:accessor widget-border-right
38+
:documentation "The border right CSS attribute."
39+
:trait :string)
40+
(border-top
41+
:initarg :border-top
42+
:initform nil
43+
:accessor widget-border-top
44+
:documentation "The border top CSS attribute."
2745
:trait :string)
2846
(bottom
2947
:initarg :bottom
@@ -187,18 +205,6 @@
187205
:accessor widget-overflow
188206
:documentation "The overflow CSS attribute."
189207
:trait :string)
190-
(overflow-x
191-
:initarg :overflow-x
192-
:initform nil
193-
:accessor widget-overflow-x
194-
:documentation "The overflow-x CSS attribute."
195-
:trait :string)
196-
(overflow-y
197-
:initarg :overflow-y
198-
:initform nil
199-
:accessor widget-overflow-y
200-
:documentation "The overflow-y CSS attribute."
201-
:trait :string)
202208
(padding
203209
:initarg :padding
204210
:initform nil
@@ -245,21 +251,45 @@ https://developer.mozilla.org/en-US/docs/Web/CSS/Reference
245251
When a property is also accessible via a shorthand property, we only
246252
expose the shorthand."))
247253

254+
(defun widget-border (instance)
255+
(reduce (lambda (prev current)
256+
(when (equal prev current)
257+
prev))
258+
(list (widget-border-bottom instance)
259+
(widget-border-left instance)
260+
(widget-border-right instance)
261+
(widget-border-top instance))))
248262

263+
(defun (setf widget-border) (new-value instance)
264+
(setf (widget-border-bottom instance) new-value
265+
(widget-border-left instance) new-value
266+
(widget-border-right instance) new-value
267+
(widget-border-top instance) new-value)
268+
new-value)
249269

270+
(defmethod initialize-instance :after ((instance layout) &rest rest &key border)
271+
(setf (widget-border instance) border))
250272

251273
(defwidget dom-widget (widget)
252-
((%dom-classes
253-
:initarg :%dom-classes
254-
:accessor widget-%dom-classes
255-
:documentation "CSS classes applied to widget DOM element"
256-
:trait :string-list)
257-
(layout
258-
:initarg :layout
259-
:initform (make-instance 'layout)
260-
:accessor widget-layout
261-
:documentation "Reference to layout widget."
262-
:trait :widget))
274+
((%dom-classes :initarg :%dom-classes
275+
:accessor widget-%dom-classes
276+
:documentation "CSS classes applied to widget DOM element"
277+
:trait :string-list)
278+
(layout :initarg :layout
279+
:initform (make-instance 'layout)
280+
:accessor widget-layout
281+
:documentation "Reference to layout widget."
282+
:trait :widget)
283+
(tabbable :initarg :tabbable
284+
:initform nil
285+
:accessor widget-tabbable
286+
:documentation "Is widget tabbable?"
287+
:trait :boolean)
288+
(tooltip :initarg :tooltip
289+
:initform ""
290+
:accessor widget-tooltip
291+
:documentation "A tooltip caption."
292+
:trait :string))
263293
(:default-initargs
264294
;:%model-name "DOMWidgetModel"
265295
:%model-module +controls-module+

src/widgets/file-upload.lisp

Lines changed: 22 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,26 @@
22

33

44
(defwidget file-upload (description-widget button-style-slot disabled-slot icon-slot)
5-
((accept
6-
:initarg :accept
7-
:initform ""
8-
:accessor widget-accept
9-
:documentation "If set, ensure value is in options. Implies continuous_update=False. File types to accept, empty string for all."
10-
:trait :string)
11-
(data
12-
:initarg :data
13-
:initform nil
14-
:accessor widget-data
15-
:documentation "List of file content (bytes)"
16-
:trait :buffer-list)
17-
(error
18-
:initarg :error
19-
:initform ""
20-
:accessor widget-error
21-
:documentation "Error message"
22-
:trait :string)
23-
(metadata
24-
:initarg :metadata
25-
:initform nil
26-
:accessor widget-metadata
27-
:documentation "List of file metadata"
28-
:trait :json)
29-
(multiple
30-
:initarg :multiple
31-
:initform nil
32-
:accessor widget-multiple
33-
:documentation "If True, allow for multiple files upload"
34-
:trait :bool))
35-
(:default-initargs
36-
:%model-name "FileUploadModel"
37-
:%view-name "FileUploadView"))
38-
39-
40-
41-
42-
(defmethod widget-value ((instance file-upload))
43-
(map 'vector
44-
(lambda (content metadata)
45-
(let ((table (alexandria:copy-hash-table metadata)))
46-
(setf (gethash "content" table) content)
47-
table))
48-
(widget-data instance) (widget-metadata instance)))
49-
50-
51-
(defun file-upload-value-notify (instance)
52-
(when (and (slot-boundp instance 'data)
53-
(slot-boundp instance 'metadata)
54-
(= (length (widget-data instance)) (length (widget-metadata instance)))
55-
(every (lambda (content metadata)
56-
(= (length content) (gethash "size" metadata)))
57-
(widget-data instance) (widget-metadata instance)))
58-
(jupyter::enqueue *trait-notifications*
59-
(list instance :any :value nil (widget-value instance) nil))))
60-
61-
62-
(defmethod on-trait-change :after ((instance file-upload) type (name (eql :data)) old-value new-value source)
63-
(declare (ignore type name old-value new-value source))
64-
(file-upload-value-notify instance))
65-
66-
67-
(defmethod on-trait-change :after ((instance file-upload) type (name (eql :metadata)) old-value new-value source)
68-
(declare (ignore type name old-value new-value source))
69-
(file-upload-value-notify instance))
5+
((accept :initarg :accept
6+
:initform ""
7+
:accessor widget-accept
8+
:documentation "If set, ensure value is in options. Implies continuous_update=False. File types to accept, empty string for all."
9+
:trait :string)
10+
(value :initarg :value
11+
:initform nil
12+
:accessor widget-value
13+
:documentation "The file upload value"
14+
:trait :buffer-list)
15+
(error :initarg :error
16+
:initform ""
17+
:accessor widget-error
18+
:documentation "Error message"
19+
:trait :string)
20+
(multiple :initarg :multiple
21+
:initform nil
22+
:accessor widget-multiple
23+
:documentation "If True, allow for multiple files upload"
24+
:trait :bool))
25+
(:default-initargs :%model-name "FileUploadModel"
26+
:%view-name "FileUploadView"))
7027

src/widgets/label.lisp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
(defwidget label (description-widget placeholder-slot string-value-slot)
99
()
10-
(:default-initargs
11-
:%model-name "LabelModel"
12-
:%view-name "LabelView")
10+
(:default-initargs :%model-name "LabelModel"
11+
:%view-name "LabelView"
12+
:style (make-instance 'label-style))
1313
(:documentation "Label widget.
1414
1515
It also renders math inside the string `value` as Latex (requires $ $ or
@@ -18,17 +18,17 @@ $$ $$ and similar latex tags)."))
1818

1919
(defwidget html (label)
2020
()
21-
(:default-initargs
22-
:%model-name "HTMLModel"
23-
:%view-name "HTMLView")
21+
(:default-initargs :%model-name "HTMLModel"
22+
:%view-name "HTMLView"
23+
:style (make-instance 'html-style))
2424
(:documentation "Renders the string `value` as HTML."))
2525

2626

2727
(defwidget html-math (label)
2828
()
29-
(:default-initargs
30-
:%model-name "HTMLMathModel"
31-
:%view-name "HTMLMathView")
29+
(:default-initargs :%model-name "HTMLMathModel"
30+
:%view-name "HTMLMathView"
31+
:style (make-instance 'html-math-style))
3232
(:documentation "Renders the string `value` as HTML, and render mathematics."))
3333

3434

0 commit comments

Comments
 (0)