Scrolling in racket/gui

299 views
Skip to first unread message

Philip McGrath

unread,
Mar 1, 2017, 3:16:47 PM3/1/17
to Racket Users
This seems like it should be a simple question, but I can't figure out how to get a scroll bar in a gui application like this one:

#lang racket/gui
(define frame
  (new frame% [label "Example"]))
(for ([letter '("A" "B" "C" "D")])
  (define grp
    (new group-box-panel%
         [parent frame]
         [label letter]))
  (for ([i (in-range 0 10)])
    (new button%
         [parent grp]
         [label (number->string i)])))
(send frame show #t)

I can see something like what I have in mind in Dr. Racket's "Colors">"Color Schemes" preferences tab (at least on Mac OS), but I can't figure out how to do it.

Thanks,
Philip

Alex Harsanyi

unread,
Mar 1, 2017, 6:39:30 PM3/1/17
to Racket Users
Does this do what you want?

#lang racket/gui

(define frame
(new frame% [label "Example"] [height 300]))
(for ([letter '("A" "B" "C" "D")])
(define grp
(new group-box-panel%
[parent frame]
[min-height 100]
[label letter]))
(define panel
(new vertical-panel%
[parent grp]
[style '(vscroll)]
[alignment '(left top)]))
(for ([i (in-range 0 10)])
(new button%
[parent panel]
[label (number->string i)])))
(send frame show #t)

Best Regards,
Alex.

Philip McGrath

unread,
Mar 1, 2017, 9:56:30 PM3/1/17
to Alex Harsanyi, Racket Users
Almost — thanks! (I'm sure I read over that page of the docs, but I somehow missed 'vscroll.)

The one thing that isn't working is scrolling with the mouse/trackpad. It seems like I might need to override on-subwindow-char to listen for 'wheel-up and 'wheel-down, which I can do, but I'm not finding how to change the scrolling position of the panel if I do catch one of those events. (Or maybe there's a way to do it without implementing it myself?)

-Philip


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Harsanyi

unread,
Mar 1, 2017, 11:54:41 PM3/1/17
to Racket Users, alexha...@gmail.com
On Thursday, March 2, 2017 at 10:56:30 AM UTC+8, Philip McGrath wrote:
> Almost — thanks! (I'm sure I read over that page of the docs, but I somehow missed 'vscroll.)
>
>
> The one thing that isn't working is scrolling with the mouse/trackpad. It seems like I might need to override on-subwindow-char to listen for 'wheel-up and 'wheel-down, which I can do, but I'm not finding how to change the scrolling position of the panel if I do catch one of those events. (Or maybe there's a way to do it without implementing it myself?)
>

I don't think you will be able to update the scroll-bar positions. The scroll functionality that is implemented for panel objects is limited to automatic scrolling and the racket GUI code would have to be updated to allow changing it programmatically.

BTW, I am looking forward to being proven wrong on this, as I could use the functionality myself :-)

Alex.

Philip McGrath

unread,
Mar 2, 2017, 12:39:21 AM3/2/17
to Alex Harsanyi, Racket Users
I fear you may be right: I see that the Dr. Racket's "Colors">"Color Schemes" preferences tab also does not scroll in response to the mouse/trackpad.

-Philip


Alex.

Reply all
Reply to author
Forward
0 new messages