-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathslider.lisp
182 lines (138 loc) · 5.49 KB
/
slider.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
(in-package #:jupyter/widgets)
(defwidget base-slider (description-widget disabled-slot orientation-slot
continuous-update-slot)
((readout
:initarg :readout
:initform t
:accessor widget-readout
:documentation "Display the current value of the slider next to it."
:trait :bool)
(readout-format
:initarg :readout-format
:accessor widget-readout-format
:documentation "Format for the readout"
:trait :string))
(:default-initargs
:style (make-instance 'slider-style)))
(defwidget number-slider (base-slider)
((readout-format
:initarg :readout-format
:accessor widget-readout-format
:documentation "Format for the readout"
:trait :string)))
(defwidget float-log-slider (number-slider float-min-max-slots float-step-slot
float-value-slot)
((base
:initarg :base
:initform 10.0d0
:accessor widget-base
:documentation "Base for the logarithm"
:trait :float))
(:default-initargs
:%model-name "FloatLogSliderModel"
:%view-name "FloatLogSliderView"
:readout-format ".3g"
:max 4.0d0)
(:documentation
"Slider/trackbar of logarithmic floating values with the specified range."))
(defwidget float-range-slider (number-slider float-min-max-slots float-step-slot)
((value
:initarg :value
:initform (list 0.0d0 1.0d0)
:accessor widget-value
:documentation "Float range"
:trait :float-list))
(:default-initargs
:%model-name "FloatRangeSliderModel"
:%view-name "FloatRangeSliderView"
:readout-format ".2f")
(:documentation
"Slider/trackbar that represents a pair of floats bounded by minimum and maximum
value."))
(defwidget float-slider (number-slider float-min-max-slots float-step-slot
float-value-slot)
()
(:default-initargs
:%model-name "FloatSliderModel"
:%view-name "FloatSliderView"
:readout-format ".2f")
(:documentation "Slider/trackbar of floating values with the specified range."))
(defwidget int-range-slider (number-slider int-min-max-slots int-step-slot)
((value
:initarg :value
:initform (list 0 1)
:accessor widget-value
:documentation "Int range value"
:trait :int-list))
(:default-initargs
:%model-name "IntRangeSliderModel"
:%view-name "IntRangeSliderView"
:readout-format "d")
(:documentation
"Slider/trackbar that represents a pair of ints bounded by minimum and maximum
value."))
(defwidget int-slider (number-slider int-min-max-slots int-step-slot
int-value-slot)
()
(:default-initargs
:%model-name "IntSliderModel"
:%view-name "IntSliderView"
:readout-format "d")
(:documentation
"Slider widget that represents an integer bounded from above and below."))
(defwidget label-slider (base-slider %options-labels-slot)
((options
:accessor widget-options
:initarg :options
:documentation "The option values that correspond to the labels")))
(defwidget selection-range-slider (label-slider)
((index
:initarg :index
:initform '(0 0)
:accessor widget-index
:documentation "Min and max selected indices"
:trait :int-list))
(:default-initargs
:%model-name "SelectionRangeSliderModel"
:%view-name "SelectionRangeSliderView")
(:documentation "Slider to select multiple contiguous items from a list."))
(defmethod widget-value ((instance selection-range-slider))
(select-values instance (widget-index instance)))
(defmethod (setf widget-value) (new-value (instance selection-range-slider))
(setf (widget-index instance)
(mapcar (lambda (value)
(position value
(if (slot-boundp instance 'options)
(widget-options instance)
(widget-%options-labels instance))
:test #'equal))
new-value)))
(defmethod on-trait-change :after ((instance selection-range-slider) type (name (eql :index)) old-value new-value source)
(jupyter::enqueue *trait-notifications*
(list instance :any :value (select-values instance old-value) (select-values instance new-value) source)))
(defmethod initialize-instance :after ((instance selection-range-slider) &rest initargs &key &allow-other-keys)
(let ((value (getf initargs :value)))
(when value
(setf (widget-value instance) value))))
(defwidget selection-slider (label-slider index-slot)
()
(:default-initargs
:%model-name "SelectionSliderModel"
:%view-name "SelectionSliderView")
(:documentation "Slider to select a single item from a list or dictionary."))
(defmethod widget-value ((instance selection-slider))
(select-value instance (widget-index instance)))
(defmethod (setf widget-value) (new-value (instance selection-slider))
(setf (widget-index instance)
(position new-value
(if (slot-boundp instance 'options)
(widget-options instance)
(widget-%options-labels instance))
:test #'equal)))
(defmethod on-trait-change :after ((instance selection-slider) type (name (eql :index)) old-value new-value source)
(jupyter::enqueue *trait-notifications*
(list instance :any :value (select-value instance old-value) (select-value instance new-value) source)))
(defmethod initialize-instance :after ((instance selection-slider) &rest initargs &key &allow-other-keys)
(let ((value (getf initargs :value)))
(when value
(setf (widget-value instance) value))))