Paste number 50762: yay! closures!

Paste number 50762: yay! closures!
Pasted by: baggles
8 months, 1 week ago
#lispcafe | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
(defmacro make-scroll-button ((&rest osd-button-keyargs)
                              format-text variable-place
                              &key (update-p t)
                              (wheel-delta-form 0.1)
                              minimum
                              maximum
)

  `(let ((numeric-writer #'(lambda (new-value)
                             (if ,update-p
                                 (setf ,variable-place
                                       ,(cond
                                         ((and minimum maximum)
                                          `(max ,minimum (min ,maximum new-value))
)

                                         (minimum `(max ,minimum new-value))
                                         (maximum `(min ,maximum new-value))
                                         (t 'new-value)
)
)

                                 ,variable-place
)
)
)
)

     (make-instance 'osd-numeric-input ,@osd-button-keyargs
                    :text (if ,update-p (format nil ,format-text ,variable-place) "-")
                    :writer numeric-writer
                    :text-updater #'(lambda () (if ,update-p (format nil ,format-text ,variable-place) "-"))
                    :middle-click
                    (lambda (self)
                      (unwind-protect
                           (setf (text-of self)
                                 (format nil ,format-text
                                         (funcall numeric-writer
                                                  (+ ,variable-place (* ,wheel-delta-form 0.1))
)
)
)

                        (signal 'mouse-handled)
)
)

                    :right-click
                    (lambda (self)
                      (unwind-protect
                           (setf (text-of self)
                                 (format nil ,format-text
                                         (funcall numeric-writer
                                                  (- ,variable-place (* ,wheel-delta-form 0.1))
)
)
)

                        (signal 'mouse-handled)
)
)

                    :wheel
                    (lambda (self zrel)
                      (unwind-protect
                           (setf (text-of self)
                                 (format nil ,format-text
                                         (funcall numeric-writer
                                                  (+ ,variable-place (* zrel ,wheel-delta-form))
)
)
)

                        (signal 'mouse-handled)
)
)

                    ,@(osd-style :button)
                    :name ',(gensym "OSD-CLAMPF-BUTTON-") ; have to give it a name so it sits in the hash table
                    
)
)
)

This paste has no annotations.

Colorize as:
Show Line Numbers

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.