AtlatestRepositorysigil-ui

sigil-ui / tree / testtest-viewport.sgl

1(import (sigil test) (sigil ui raster) (sigil ui font)
2 (sigil ui display) (sigil ui theme) (sigil ui tree))
3
4(define small (make-bitmap-font "viewport" 8 2 (bytevector 255 0) '(65)))
5(define fonts (make-font-set (list (cons 1 small))))
6(define theme (make-theme '((background . 0) (text . 16777215))
7 (list (cons 'text fonts)) '()))
8
9(test-group "viewport text clipping"
10 (test "retained repaint clips a text run at a tiny viewport"
11 (for-each
12 (lambda (width)
13 (let ((ui (make-ui theme (make-canvas width 1) 1 'background)))
14 (ui-update! ui (label 0 0 "AAAA" 'text))
15 (assert-equal width (canvas-count-other (ui-canvas ui) 0 0 width 1 0))))
16 '(1 5 16)))
17 (test "a tiny canvas can be replaced by a normal canvas with the same view"
18 (let ((view (label 0 0 "AAAA" 'text)))
19 (for-each
20 (lambda (size)
21 (let ((ui (make-ui theme (make-canvas (car size) (cadr size)) 1 'background)))
22 (ui-update! ui view)
23 (assert-equal #xFFFFFF (canvas-pixel (ui-canvas ui) 0 0))))
24 '((1 1) (2 1) (64 32)))))
25 (test "an explicitly clipped repaint also handles negative text origins"
26 (let ((canvas (make-canvas 3 1)))
27 (repaint-rects! canvas (list (text-item -2 0 "AA" #xFFFFFF fonts)) 1 0 '((0 0 3 1)))
28 (assert-equal 3 (canvas-count-other canvas 0 0 3 1 0)))))