in reply to Tk::LCD Investigations

G'day James,

++ It worked as described for me.

There's an unlimited amount of times that "next" can be used. You may want to add a limit. At the moment, for the first several uses, the proportions are retained; something like this:

+-----+
|     |
|     |
|  O  |
|     |
|  O  |
|     |
|     |
+-----+

After half a dozen uses, the layout degrades; very roughly like this:

+-----+  +-----+  +-----+  +-----+
|     |  |     |  |     |  |     |
|     |  |     |  |     |  |     |
|  O  |  |  O  |  |  O  |  |  O  |
|     |  |     |  |     |  |     |
|  O  |  |  O  |  |  O  |  +-----+
|     |  |     |  +-----+
|     |  +-----+
+-----+

As a general rule-of-thumb in Tk applications, unless I want to pass an absolute value to a callback which doesn't change that value, I use references. In many cases, even if the value isn't being changed in the callback, it may be changed prior to the callback being invoked; references are typically a good option in these cases also.

You also may want add a "prev" button to test down-scaling.

Not intended as a huge criticism, but I do see the following code repeated:

$canvas->createPolygon(@scaledBox, -fill => 'darkgreen'); $canvas->createOval(@scaledTopColon, -fill => 'yellow'); $canvas->createOval(@scaledBotColon, -fill => 'yellow');

Consider abstracting that into a single routine. If you subsequently want to change something, you'll only need to do it in one place (see "DRY principle").

— Ken

Replies are listed 'Best First'.
Re^2: Tk::LCD Investigations
by jmlynesjr (Deacon) on Mar 16, 2023 at 14:54 UTC

    Ken, thanks for your comments.

    I had noticed the offset, but hadn't had a chance to look into it yet. The down-scaling I believe will work as all scaling is calculated from the base rather than from the previous. Errors shouldn't accumulate. The duplicate code in redraw() came from another post and at that moment I was happy to get it working! It had been a lot of trial and error at that point. It won't be necessary when I update the main package. It was an artifact from wanting a way to demo a changing scale without repeatedly editing the source.

    I next have to work in move-> to draw multiple colons at different sizes on the same canvas. That's how Tk::LCD draws multiple digits. Move->Polygon, Move->Polygon, etc.

    Several years back I ported a wxWidgets clock demo to wxPerl. While more flexible, it was a lot more code.

    My learning from this test was using the $_[0] notation for returning data back from a callback.

    James

    There's never enough time to do it right, but always enough time to do it over...