Hi, all.
First of all, thank you for a good library. So far I think LTK is the best CL library for TK. That is a good reason to make it even better !
I think why does not LTK have support for units of length for canvas items? At least, I have not found any neither from reading the docs no from reading the sources (which are compact, indeed).
That is why I tried my own hack for this. The idea is very simple: we declare a dynamic variable to hold name of units of measure, with reasonable value of "", which should not have any effect on the existing applications, and attach it to each length or size with is forwarded to WISH. Like this:
(defparameter *canvas-units* "")
(defun format-number (stream number) (when (and (atom number) (not (vectorp number))) (format *debug-io* "~%format-number: ~A ~A ~A" number (type-of number) *canvas-units*)) (cond ((complexp number) (format-number stream (realpart number)) (format-number stream (imagpart number))) ((integerp number) (format stream " ~d~a" number *canvas-units*)) ((typep number 'single-float) (format stream " ~a~a" number *canvas-units*)) ((numberp number) (format-number stream (coerce number 'single-float))) ((stringp number) (format stream " ~a" number)) ((null number) ) ((listp number) (format-number stream (car number)) (format-number stream (cdr number))) ((arrayp number) (dotimes (i (length number)) (format-number stream (aref number i)))) )) And I also added a branch for STRING parameters. The reason is I spent significant number of time trying to figure out why my code using STRING parameters to length options. LTK in this case silently ignores these parameters so I think either output branch or error condition should be added here.
To support the tradition, a WITH-like macro also can be added. Like :
(WITH-CANVAS-UNITS (m) ...)
I can provide the code in any form, if it is interesting.
2009/7/7 Ilya Zvyagin i.zvyagin@rlisystems.ru:
Hi, all.
First of all, thank you for a good library. So far I think LTK is the best CL library for TK. That is a good reason to make it even better !
Thank you, and there is no better way than submitting enhancements :)
I think why does not LTK have support for units of length for canvas items? At least, I have not found any neither from reading the docs no from reading the sources (which are compact, indeed).
Well, I had no use for them so far, but as with many Tk features, I might have overlooked a cool use case. So can you give an example where you use canvas units?
That is why I tried my own hack for this. The idea is very simple: we declare a dynamic variable to hold name of units of measure, with reasonable value of "", which should not have any effect on the existing applications, and attach it to each length or size with is forwarded to WISH. Like this:
(defparameter *canvas-units* "")
(defun format-number (stream number) (when (and (atom number) (not (vectorp number))) (format *debug-io* "~%format-number: ~A ~A ~A" number (type-of number) *canvas-units*)) (cond ((complexp number) (format-number stream (realpart number)) (format-number stream (imagpart number))) ((integerp number) (format stream " ~d~a" number *canvas-units*)) ((typep number 'single-float) (format stream " ~a~a" number *canvas-units*)) ((numberp number) (format-number stream (coerce number 'single-float))) ((stringp number) (format stream " ~a" number)) ((null number) ) ((listp number) (format-number stream (car number)) (format-number stream (cdr number))) ((arrayp number) (dotimes (i (length number)) (format-number stream (aref number i)))) )) And I also added a branch for STRING parameters. The reason is I spent significant number of time trying to figure out why my code using STRING parameters to length options. LTK in this case silently ignores these parameters so I think either output branch or error condition should be added here.
To support the tradition, a WITH-like macro also can be added. Like :
(WITH-CANVAS-UNITS (m) ...)
Yeah, looks like a good solution and I will merge it in.
Peter
Peter Herth ?????:
Well, I had no use for them so far, but as with many Tk features, I might have overlooked a cool use case. So can you give an example where you use canvas units?
I simply draw a plan of real objects and it is more convenient to do this in real coordinates, not in pixels, moreover, pixels are not always of same height and width, that is, not always circles. So measuring in pixels would lead to axis of X and Y being unisotropic. I may be wrong here but this was my first idea when I decided to use millimeters.
Yeah, looks like a good solution and I will merge it in.
I can provide the full source file if it is needed.