allow line number width to increase automatically

original commit: c3111c425b2a85a90a5312e343d5a9144665d252
This commit is contained in:
Jon Rafkind 2010-11-03 17:58:18 -06:00
parent fcec57d8fb
commit 67d668337c

View File

@ -3713,6 +3713,7 @@ designates the character that triggers autocompletion
(super-new) (super-new)
(inherit get-visible-line-range (inherit get-visible-line-range
get-visible-position-range get-visible-position-range
last-line
find-position find-position
line-location line-location
line-paragraph line-paragraph
@ -3722,10 +3723,10 @@ designates the character that triggers autocompletion
(init-field [line-numbers-color "black"]) (init-field [line-numbers-color "black"])
(init-field [show-line-numbers? #t]) (init-field [show-line-numbers? #t])
;; maybe make this a configurable field? (define (number-space)
(define number-space "10000") (number->string (max (* 10 (last-line)) 10)))
;; add an extra 0 so it looks nice ;; add an extra 0 so it looks nice
(define number-space+1 (string-append number-space "0")) (define (number-space+1) (string-append (number-space) "0"))
(define cached-snips (list)) (define cached-snips (list))
(define need-to-recalculate-snips #f) (define need-to-recalculate-snips #f)
@ -3778,7 +3779,7 @@ designates the character that triggers autocompletion
;; draw it! ;; draw it!
(draw-numbers dc top bottom dy (unbox start-line) (add1 (unbox end-line))) (draw-numbers dc top bottom dy (unbox start-line) (add1 (unbox end-line)))
(draw-separator dc top bottom dy (text-width dc "10000"))) (draw-separator dc top bottom dy (text-width dc (number-space))))
(define (text-width dc stuff) (define (text-width dc stuff)
(define-values (font-width font-height baseline space) (define-values (font-width font-height baseline space)
@ -3808,7 +3809,7 @@ designates the character that triggers autocompletion
(set! old-clipping (send dc get-clipping-region)) (set! old-clipping (send dc get-clipping-region))
(setup-dc dc) (setup-dc dc)
(define-values (font-width font-height baseline space) (define-values (font-width font-height baseline space)
(send dc get-text-extent number-space)) (send dc get-text-extent (number-space)))
(define clipped (make-object region% dc)) (define clipped (make-object region% dc))
(define all (make-object region% dc)) (define all (make-object region% dc))
(define copy (make-object region% dc)) (define copy (make-object region% dc))
@ -3820,7 +3821,7 @@ designates the character that triggers autocompletion
(send copy union all)) (send copy union all))
(send clipped set-rectangle (send clipped set-rectangle
0 (+ dy top) 0 (+ dy top)
(text-width dc number-space+1) (text-width dc (number-space+1))
(- bottom top)) (- bottom top))
#; #;
(define (print-region name region) (define (print-region name region)
@ -3828,7 +3829,7 @@ designates the character that triggers autocompletion
(printf "~a: ~a, ~a, ~a, ~a\n" name a b c d)) (printf "~a: ~a, ~a, ~a, ~a\n" name a b c d))
(send copy subtract clipped) (send copy subtract clipped)
(send dc set-clipping-region copy) (send dc set-clipping-region copy)
(send dc set-origin (+ x (text-width dc number-space+1)) y) (send dc set-origin (+ x (text-width dc (number-space+1))) y)
) )
(begin (begin
;; rest the origin and draw the line numbers ;; rest the origin and draw the line numbers