Windows issues parsing these characters. Bug fix for entering edit mode without setti...
[cowl.git] / src / cowl-numeric-input.lisp
blob140376cb551832d23d42127f7970c9eceea22060
1 (in-package #:cowl)
3 (defclass numeric-input (input)
4 ((number-type :initarg :number-type :initform 'single-float :accessor number-type :type (or symbol cons)
5 :documentation "A typespec of the type to coerce the number into on write."))
6 (:documentation "Widget for editable numbers.
7 The writer initarg function will be automatically wrapped in
8 the initialize-instance so that it is given a number as the first argument."))
10 (defmethod initialize-instance :after ((numeric-input numeric-input) &key writer)
11 (when writer
12 (setf (slot-value numeric-input 'writer)
13 (lambda (val)
14 (let ((rval (read-from-string val)))
15 (when (numberp rval)
16 (funcall writer (coerce rval (number-type numeric-input)))))))))
18 (defmethod accept-char-p ((numeric-input numeric-input) character)
19 (or (eql #\. character)
20 (eql #\- character)
21 (digit-char-p character)))