Lisp HUG Maillist Archive

Range input of non-integers

[sorry if this is a duplicate, I tried posting from gmane but it
didn't show up]

Is there a way to use text-input-range (or something else) to accept 
non-integers?  Something with a spin wheel that takes both a range and an 
increment/decrement (say 0.5 to 9.7 by 0.1).  Same goes for the slider: is 
there a way to have the range there be non-integer and have it display the 
value at the same time?  

thanks,

BM


Re: Range input of non-integers

Bulent Murtezaoglu wrote:

> Is there a way to use text-input-range (or something else) to
> accept non-integers?  Something with a spin wheel that takes
> both a range and an increment/decrement (say 0.5 to 9.7 by 0.1).

That's funny: I had the same problem a few days ago. I got the
impression that it's impossible (and used an ugly work-around),
but I'd love to be contradicted.

Arthur Lemmens


Re: Range input of non-integers

----- Original Message ----- 
From: "Bulent Murtezaoglu" <bm@acm.org>
To: <lisp-hug@xanalys.com>
Sent: Tuesday, March 16, 2004 4:22 PM
Subject: Range input of non-integers


>
> [sorry if this is a duplicate, I tried posting from gmane but it
> didn't show up]
>
> Is there a way to use text-input-range (or something else) to accept
> non-integers?  Something with a spin wheel that takes both a range and an
> increment/decrement (say 0.5 to 9.7 by 0.1).  Same goes for the slider: is
> there a way to have the range there be non-integer and have it display the
> value at the same time?
>
> thanks,
>
> BM
>
I have such a thing. It is an interface built on text-input-range and a
display-pane. It seems
to work fine. You're welcome to use and modify it at will.

Jim Bushnell

;; note that the callback must be called on interface two levels up
;; because the first interface is just the spinner itself

(capi:define-interface spinner ()
  ((start :initarg :start :initform 0)
   (end :initarg :end :initform 10)
   (value :reader spinner-value ; not sure if a problem with the setf method
below
          :initarg :value :initform 0)
   (step :initarg :step :initform 1 :reader spinner-step)
   (callback :initarg :callback :initform nil))
  (:panes
   (value-pane
    capi:display-pane
    :text (format nil "~D" value))
   (tir
    capi:text-input-range
    :accessor tir
    :end (round end step)
    :start (round start step)
    :value (round value step)
    :callback (lambda (item data)
                (let ((val (* data step)))
                  (setf (capi:display-pane-text value-pane) (format nil "~D"
val)
                        value val)
                  (when callback (funcall callback (capi:element-interface
                                                    (capi:element-interface
item))))))
    :visible-max-width 15
    :visible-min-width 15))
  (:layouts
   (sp-layout
    capi:row-layout
    '(value-pane tir)))
  (:default-initargs
   :best-height 20
   :best-width 104
   :layout 'sp-layout
   :title "Spinner"))


(defmethod initialize-instance :after ((self spinner) &rest initargs)
  (with-slots (value value-pane) self
    (setf (capi:display-pane-text value-pane)
          (format nil "~D" value))))

(defmethod (setf spinner-start) (start-value (self spinner))
  (with-slots (start step tir) self
    (setf start start-value
          (capi:text-input-range-start tir) (round start step))))

(defmethod (setf spinner-end) (end-value (self spinner))
  (with-slots (end step tir) self
    (setf end end-value
          (capi:text-input-range-end tir) (round end step))))

(defmethod (setf spinner-step) (new-step (self spinner))
  (with-slots (end start step tir) self
    (setf step new-step
          (capi:text-input-range-end tir) (round end step)
          (capi:text-input-range-start tir) (round start step))))

(defmethod (setf spinner-value) (this-value (self spinner))
  (with-slots (value step tir value-pane) self
    (setf value this-value
          (capi:display-pane-text value-pane) (format nil "~D" this-value)
          (capi:text-input-range-value tir) (round value step))))


Re: Range input of non-integers

Unable to parse email body. Email id is 2049

Updated at: 2020-12-10 08:57 UTC