Chapter 11½: inside card/src
lib.rs is a tiny graphics library and three pictures:
- The palette: paper, ink, pink and grey, the page's own colours.
Canvas:fill,frame,dither(the page's dot fields, with a 4 by 4 ordered dither), andtextin the 8 by 8 face, scaled.- Text layout:
cut(shorten with "..."),wrap(break at spaces into lines),fit(the largest scale that fits). draw: the frame common to every card (dither, pink band, window), then the inside forHome,QuestionorCode;slideranddetaildraw an answer's numbers.png: packs four pixels a byte and writes an indexed PNG.
tests.rs checks the PNG is the size the page declares, that the answer
and its numbers change the picture, that nothing runs off the card, and that
letters outside ASCII fall back to ?.
Try it.
cargo test -p card.
| File | What |
|---|---|
| lib.rs | The canvas, the face, the cards, and png. |
| tests.rs | Sizes, pictures that change with the answer, and edges. |
← Previous: Chapter 11, card/ · Up: card · Next: Chapter 11¾, card/examples/ →