[ltk-user] Adding support for various units of measure for canvas items.

Peter Herth herth at peter-herth.de
Wed Jul 8 16:13:35 UTC 2009


2009/7/7 Ilya Zvyagin <i.zvyagin at 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




More information about the ltk-user mailing list