{"size": 3363, "ext": "scrbl", "max_stars_repo_path": "pict-doc/pict/scribblings/conditional.scrbl", "max_stars_repo_name": "jackfirth/pict", "max_stars_repo_stars_event_min_datetime": "2015-02-13T20:25:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T02:32:33.000Z", "max_issues_repo_path": "pict-doc/pict/scribblings/conditional.scrbl", "max_issues_repo_name": "jackfirth/pict", "max_issues_repo_issues_event_min_datetime": "2015-06-21T23:40:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T09:56:04.000Z", "max_forks_repo_path": "pict-doc/pict/scribblings/conditional.scrbl", "max_forks_repo_name": "jackfirth/pict", "max_forks_repo_forks_event_min_datetime": "2015-06-21T23:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-01T03:03:24.000Z"}
{"max_stars_count": 13, "max_issues_count": 67, "max_forks_count": 20, "avg_line_length": 33.297029703, "max_line_length": 81, "alphanum_fraction": 0.6488254535}
#lang scribble/manual

@(require (for-label pict pict/conditional racket/base racket/contract)
          scribble/eval)

@(define the-eval (make-base-eval))
@(the-eval '(require pict pict/conditional))

@title{Conditional Combinations}

@defmodule[pict/conditional]

These pict control flow operators decide which pict of several to use.  All
branches are evaluated; the resulting pict is a combination of the pict chosen
by normal conditional flow with @racket[ghost] applied to all the other picts.
The result is a picture large enough to accommodate each alternative, but showing
only the chosen one.  This is useful for staged slides, as the pict chosen may
change with each slide but its size and position will not.

@defform/subs[(pict-if maybe-combine test-expr then-expr else-expr)
              ([maybe-combine code:blank (code:line #:combine combine-expr)])]{

Chooses either @racket[then-expr] or @racket[else-expr] based on
@racket[test-expr], similarly to @racket[if].  Combines the chosen, visible
image with the other, invisible image using @racket[combine-expr], defaulting to
@racket[lbl-superimpose].

@examples[#:eval the-eval
(let ([f (lambda (x)
           (pict-if x
                    (disk 20)
                    (disk 40)))])
  (hc-append 10
             (frame (f #t))
             (frame (f #f))))
]

@history[#:added "1.4"]{}
}

@defform/subs[(pict-cond maybe-combine [test-expr pict-expr] ...)
              ([maybe-combine code:blank (code:line #:combine combine-expr)])]{

Chooses a @racket[pict-expr] based on the first successful @racket[test-expr],
similarly to @racket[cond].  Combines the chosen, visible image with the other,
invisible images using @racket[combine-expr], defaulting to
@racket[lbl-superimpose].

@examples[#:eval the-eval
(let ([f (lambda (x)
           (pict-cond #:combine cc-superimpose
             [(eq? x 'circle) (circle 20)]
             [(eq? x 'disk) (disk 40)]
             [(eq? x 'text) (text "ok" null 20)]))])
  (hc-append 10
             (frame (f 'circle))
             (frame (f 'disk))
             (frame (f 'text))))
]

@history[#:added "1.4"]{}
}

@defform/subs[(pict-case test-expr maybe-combine [literals pict-expr] ...)
              ([maybe-combine code:blank (code:line #:combine combine-expr)])]{

Chooses a @racket[pict-expr] based on @racket[test-expr] and each list of
@racket[literals], similarly to @racket[case].  Combines the chosen, visible
image with the other, invisible images using @racket[combine-expr], defaulting
to @racket[lbl-superimpose].

@examples[#:eval the-eval
(let ([f (lambda (x)
           (pict-case x
             [(circle) (circle 20)]
             [(disk) (disk 40)]
             [(text) (text "ok" null 20)]))])
  (hc-append 10
             (frame (f 'circle))
             (frame (f 'disk))
             (frame (f 'text))))
]

@history[#:added "1.4"]{}
}

@deftogether[(
@defproc[(show [pict pict?] [show? any/c #t]) pict?]
@defproc[(hide [pict pict?] [hide? any/c #t]) pict?]
)]{

These functions conditionally show or hide an image, essentially choosing
between @racket[pict] and @racket[(ghost pict)].  The only difference between
the two is the default behavior and the opposite meaning of the @racket[show?]
and @racket[hide?] booleans.  Both functions are provided for mnemonic purposes.

@history[#:added "1.4"]{}
}

@(close-eval the-eval)
