diff --git a/slideshow-doc/scribblings/slideshow/slides.scrbl b/slideshow-doc/scribblings/slideshow/slides.scrbl index 2c7ec62..feae32c 100644 --- a/slideshow-doc/scribblings/slideshow/slides.scrbl +++ b/slideshow-doc/scribblings/slideshow/slides.scrbl @@ -173,6 +173,24 @@ paragraph. @history[#:changed "1.5" @elem{Added the @racket[#:aspect] argument.}]} +@defproc[(nitem [#:aspect aspect aspect? #f] + [#:width width real? ((get-current-para-width #:aspect aspect))] + [#:gap-size sep-gap-size real? (current-gap-size)] + [#:separator string? "."] + [#:number integer? (nitem-counter)] + [#:align (or/c 'left 'center 'right) 'left] + [#:fill? fill? any/c #t] + [#:decode? decode? any/c #t] + [element (flat-rec-contract elem/c + or/c string? pict? (listof elem/c))] ...) + pict?]{ + +Like @racket[item], but with a number instead of a bullet point. The +number can be specified using @racket[#:number] or automatically +incremented. Furthermore, the character following the number defaults +to "." and can be specified using @racket[separator].} + + @defproc[(subitem [#:aspect aspect aspect? #f] [#:width width real? ((get-current-para-width #:aspect aspect))] [#:gap-size sep-gap-size real? (current-gap-size)] diff --git a/slideshow-exe/slideshow/tutorial-show.rkt b/slideshow-exe/slideshow/tutorial-show.rkt index 91ec510..7cef7a4 100644 --- a/slideshow-exe/slideshow/tutorial-show.rkt +++ b/slideshow-exe/slideshow/tutorial-show.rkt @@ -296,6 +296,20 @@ (para #:width w l))))) (para "where" (code bullet) "is a constant pict:" bullet)) +(slide + #:title "Numbering" + (nitem "Numbered items can also occur in slides") + (nitem "You can make a number list using" (code nitem)) + (nitem "The numbers are automatically calculated for you!") + (nitem #:separator ")" + "The separator can be modified using" (code #:separator))) + +(slide + #:title "More Numbering" + (nitem "The numbers automatically restart with every slide") + (nitem #:number 15 + "But the number can also be provided using" (code #:number))) + (slide #:title "Grouping and Space" (para "Sometimes you want to group items on a slide") diff --git a/slideshow-lib/slideshow/base.rkt b/slideshow-lib/slideshow/base.rkt index 762aa21..5626421 100644 --- a/slideshow-lib/slideshow/base.rkt +++ b/slideshow-lib/slideshow/base.rkt @@ -31,6 +31,7 @@ most-recent-slide retract-most-recent-slide re-slide slide->pict start-at-recent-slide make-outline (rename-out [item/kw item] + [nitem/kw nitem] [subitem/kw subitem] [para/kw para]) gap-size current-gap-size current-font-size current-line-sep diff --git a/slideshow-lib/slideshow/core.rkt b/slideshow-lib/slideshow/core.rkt index 7b55586..ba21bd5 100644 --- a/slideshow-lib/slideshow/core.rkt +++ b/slideshow-lib/slideshow/core.rkt @@ -145,6 +145,13 @@ (define o-bullet (baseless (cc-superimpose (circle (/ gap-size 2)) (blank 0 gap-size)))) + (define nitem-start-num 0) ;; start at 0 so that the first number is 1 + (define (make-nitem-counter) + (let ([n nitem-start-num]) + (lambda () + (set! n (add1 n)) + n))) + (define nitem-counter (make-nitem-counter)) (define margin 20) @@ -435,6 +442,7 @@ #:gap-size [a-gap-size (current-gap-size)] . body) (check-aspect 'slide aspect) + (set! nitem-counter (make-nitem-counter)) ;; reset the number counter (let ([t (if s (if (equal? name s) (if (string? s) @@ -946,6 +954,29 @@ #:decode? decode? s)))]) item)) + (define nitem/kw + (let ([nitem (lambda (#:gap-size [a-gap-size (current-gap-size)] + #:number [number (nitem-counter)] + #:separator [separator "."] + #:aspect [aspect #f] + #:width [width ((hash-ref current-para-widths aspect))] + #:align [align 'left] + #:fill? [fill? #t] + #:decode? [decode? #t] + . s) + (check-aspect 'item aspect) + (htl-append (/ a-gap-size 2) + (para/kw #:aspect aspect + #:width (- width + (pict-width bullet) + (/ a-gap-size 2)) + #:align align + #:fill? fill? + #:decode? decode? + (number->string number) + separator + s)))]) + nitem)) (define (item*/bullet bullet w . s) (htl-append (/ gap-size 2) diff --git a/slideshow-lib/slideshow/sig.rkt b/slideshow-lib/slideshow/sig.rkt index 6758611..1e7aec8 100644 --- a/slideshow-lib/slideshow/sig.rkt +++ b/slideshow-lib/slideshow/sig.rkt @@ -65,6 +65,7 @@ scroll-transition pause-transition comment make-outline item/kw item item* page-item page-item* + nitem/kw item/bullet item*/bullet page-item/bullet page-item*/bullet subitem/kw subitem subitem* page-subitem page-subitem* itemize itemize* page-itemize page-itemize* diff --git a/slideshow-lib/slideshow/slide.rkt b/slideshow-lib/slideshow/slide.rkt index 32dd93e..4da5372 100644 --- a/slideshow-lib/slideshow/slide.rkt +++ b/slideshow-lib/slideshow/slide.rkt @@ -58,6 +58,16 @@ #:decode? any/c) #:rest elem/c . ->* . pict?)) + (define nitem-contract (() (#:number integer? + #:separator string? + #:width real? + #:gap-size real? + #:align (or/c 'left 'center 'right) + #:fill? any/c + #:decode? any/c) + #:rest elem/c + . ->* . pict?)) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Exports ;; @@ -98,6 +108,7 @@ #:rest elem/c . ->* . pict?)] [item/kw item-contract] + [nitem/kw nitem-contract] [subitem/kw item-contract] [t (string? . -> . pict?)] [bt (string? . -> . pict?)]