Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the pixels-per-scroll-step init argument #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion pict-snip-doc/scribblings/pict-snip/pict-snip.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
pict
racket
racket/snip
racket/math
racket/contract))


Expand All @@ -18,9 +19,18 @@
}

@defclass[pict-snip% snip% ()]{
@defconstructor[([pict pict?])]{
@defconstructor[([pict pict?]
[pixels-per-scroll-step (or/c #f natural?) 2])]{
Creates a @racket[pict-snip%] object, using
@racket[pict] to draw.

If @racket[pixels-per-scroll-step] is @racket[#f], then the
snip will have only one scroll step (see
@method[snip% get-num-scroll-steps] for more information).
The default means that the scroll bars will stop every two
pixels.

@history[#:changed "1.1" @list{Added the @racket[pixels-per-scroll-snip] argument}]
}
@defmethod[(get-pict) pict?]{
Returns the pict passed to the constructor.
Expand Down
2 changes: 2 additions & 0 deletions pict-snip-lib/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@

(define license
'(Apache-2.0 OR MIT))

(define version "1.1")
29 changes: 28 additions & 1 deletion pict-snip-lib/pict/snip.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
racket/snip
racket/draw
racket/format
racket/math
(prefix-in racket: racket/base)
pict
pict/convert
Expand All @@ -19,7 +20,13 @@

(define pict-snip%
(class* snip% (convert<%>)
(init-field pict)
(init-field pict [pixels-per-scroll-step 2])
(unless (or (natural? pixels-per-scroll-step)
(not pixels-per-scroll-step))
(error 'pict-snip%
"pixels-per-scroll-step init arg wrong\n expected: ~s\n got: ~e"
'(or/c #f natural?)
pixels-per-scroll-step))
(define drawer (make-pict-drawer pict))
(define/override (get-extent dc x y wb hb db sb lb rb)
(set-box/f! wb (pict-width pict))
Expand Down Expand Up @@ -50,6 +57,26 @@
(define bts (get-output-bytes bp))
(send f put (bytes-length bts) bts))

(define/override (get-num-scroll-steps)
(cond
[pixels-per-scroll-step
(define height (pict-height pict))
(exact-ceiling (/ height pixels-per-scroll-step))]
[else (super get-num-scroll-steps)]))

(define/override (get-scroll-step-offset offset)
(cond
[pixels-per-scroll-step
(exact-floor (* offset pixels-per-scroll-step))]
[else
(super get-scroll-step-offset offset)]))

(define/override (find-scroll-step y)
(cond
[pixels-per-scroll-step
(exact-floor (/ y pixels-per-scroll-step))]
[else (super find-scroll-step y)]))

(define/public (get-pict) pict)

(inherit set-snipclass)
Expand Down