Lisp HUG Maillist Archive

Custom scrolling (non-initarg scroll-bar)

OK so I have another question. I need to implement scrolling of a pane with a
separate scroll-bar, i.e. one added as part of a layout rather than through the
pane's initargs. Looking at 'scrolling-without-bar.lisp' in the examples I came
up with this - 

(define-interface my-scroll-test ()
  ()
  (:panes
    (pane output-pane
      :accessor pane
      :horizontal-scroll :without-bar
      :display-callback 
        #'(lambda (pane x y width height)
	    (declare (ignore x y width height))
            (gp:draw-circle pane 100 100 50)))
    (x-scroll scroll-bar
      :callback 'scroll-pane))
  (:layouts	  
    (main-layout column-layout
      '(pane	   
	x-scroll)))
  (:default-initargs
   :layout 'main-layout
   :best-height 400
   :best-width 400))

(defun scroll-pane (interface self how where)
  (declare (ignore self how))
  (with-slots (pane) interface
    (set-horizontal-scroll-parameters pane :slug-position where)))

But unfortunately it doesn't work. I've also tried this -

(define-interface my-scroll-test ()
  ()
  (:panes
    (pane output-pane
      :accessor pane
      :horizontal-scroll :without-bar
      :display-callback 
        #'(lambda (pane x y width height)
	    (declare (ignore x y width height))
            (gp:draw-circle pane 100 100 50))
      :scroll-callback 'scroll-pane)
    (x-scroll scroll-bar
      :accessor x-scroll))
  (:layouts	  
    (main-layout column-layout
      '(pane	   
	x-scroll)))
  (:default-initargs
   :layout 'main-layout
   :best-height 400
   :best-width 400))

(defun scroll-pane (pane direction kind where &key &allow-other-keys)
  (declare (ignore direction kind where))
  (with-slots (x-scroll) (top-level-interface pane)
    (set-horizontal-scroll-parameters pane 
      :slug-position (range-slug-start x-scroll))))

But that doesn't work either. I'm most likely making a simple error, but I can't
see it! If so I'll probably see it as soon as I've posted... if not, any help is
very much appreciated.

Thanks,
Chris



Re: Custom scrolling (non-initarg scroll-bar)

Chris wrote:
OK so I have another question. I need to implement scrolling of a pane with a
separate scroll-bar, i.e. one added as part of a layout rather than through the
pane's initargs. Looking at 'scrolling-without-bar.lisp' in the examples I came
up with this - 

(define-interface my-scroll-test ()
  ()
  (:panes
    (pane output-pane
      :accessor pane
      :horizontal-scroll :without-bar
      :display-callback 
        #'(lambda (pane x y width height)
	    (declare (ignore x y width height))
            (gp:draw-circle pane 100 100 50)))
    (x-scroll scroll-bar
      :callback 'scroll-pane))
  (:layouts	  
    (main-layout column-layout
      '(pane	   
	x-scroll)))
  (:default-initargs
   :layout 'main-layout
   :best-height 400
   :best-width 400))

(defun scroll-pane (interface self how where)
  (declare (ignore self how))
  (with-slots (pane) interface
    (set-horizontal-scroll-parameters pane :slug-position where)))

But unfortunately it doesn't work. I've also tried this -

(define-interface my-scroll-test ()
  ()
  (:panes
    (pane output-pane
      :accessor pane
      :horizontal-scroll :without-bar
      :display-callback 
        #'(lambda (pane x y width height)
	    (declare (ignore x y width height))
            (gp:draw-circle pane 100 100 50))
      :scroll-callback 'scroll-pane)
    (x-scroll scroll-bar
      :accessor x-scroll))
  (:layouts	  
    (main-layout column-layout
      '(pane	   
	x-scroll)))
  (:default-initargs
   :layout 'main-layout
   :best-height 400
   :best-width 400))

(defun scroll-pane (pane direction kind where &key &allow-other-keys)
  (declare (ignore direction kind where))
  (with-slots (x-scroll) (top-level-interface pane)
    (set-horizontal-scroll-parameters pane 
      :slug-position (range-slug-start x-scroll))))

But that doesn't work either. I'm most likely making a simple error, but I can't
see it! If so I'll probably see it as soon as I've posted... if not, any help is
very much appreciated.

Thanks,
Chris
  

I think that set-horizontal-scroll-parameters will only set the slug position in the scroll bar for you. It won't affect your output pane. To see how to do that the simple-pane (superclass of output-pane) description in CAPI reference and the example in output-pane/scrolling-without-bar.lisp may be helpful.

Mitch

RE: Custom scrolling (non-initarg scroll-bar)



> There is no association between the scroll-bar pane and the output-pane
> you created.
>
> You'll need to explicitly set slug-end and end (perhaps using the
> accessors range-slug-end and range-end) so that the slug size
> corresponds correctly to the pane with which you are associating it.
>
> Mitch

After a bit of experimentation I came up with the following, which 'seems' to work -

(define-interface my-scroll-test ()
  ()
  (:panes
    (pane output-pane
      :accessor pane
      :scroll-width 500
      :horizontal-scroll :without-bar
      :display-callback
        #'(lambda (pane x y width height)
            (declare (ignore x y width height))
            (gp:draw-circle pane 100 100 50))
      :focus-callback 'set-scroll-range
      :resize-callback 'set-slug-size)
    (x-scroll scroll-bar
      :callback 'scroll-pane
      :line-size 7))
  (:layouts     
    (main-layout column-layout
      '(pane      
        x-scroll)))
  (:default-initargs
   :layout 'main-layout
   :best-height 400
   :best-width 400))

(defun scroll-pane (interface self how where)
  (declare (ignore how where))
  (with-slots (pane) interface
    (set-horizontal-scroll-parameters pane
      :slug-position (range-slug-start self))))

(defun set-slug-size (self x y width height)
  (declare (ignore x y width height))
  (with-slots (x-scroll) (top-level-interface self)
    (with-geometry self
      (setf (range-slug-end x-scroll)
        (+ (range-slug-start x-scroll)
        %scroll-horizontal-slug-size%)))))
  
(defun set-scroll-range (self bool)
  (declare (ignore bool))
  (with-slots (x-scroll) (top-level-interface self)
    (setf (range-end x-scroll)
      (get-horizontal-scroll-parameters self
        :max-range))))

The only remaining problem is that when I scroll and then resize past the scroll-width on resizing to within the scroll-width again the slug is in the same scrolled position - the default behaviour is for the slug to be set back to its starting position. Also, it doesn't seem quite right to be using a focus-callback to set the scroll-bar's maximum range.. I tried passing set-scroll-range as a create-callback but then get-horizontal-scroll-parameters just returned NIL.

Cheers,
Chris




Share your photos with Windows Live Photos - Free Try it Now!
Updated at: 2020-12-10 08:41 UTC