Menu

#305 improved range for Scale widget

open
15. [scale] (2)
5
2010-05-19
2010-05-19
No

The current Scale widget isn't able to display a range starting with 1 and having a resolution of 2. Instead the "-from" value is rounded to be a multiple of the "-resolution".

Example:
pack [scale .s -orient hor -from 1 -to 9 -resolution 2 -tickinterval 1] -fill x

The attached diffs contain all changes necessary to fix this odd behaviour. It's a diff for Tk 8.5.8, tkScale.c and tkScale.h.
The "TkRoundToResolution" function has to be updated and "TkRoundTickToResolution" is introduced. The first one now refers to the "-from" value, too, and the latter is needed to round the "-tickinterval" without any reference to this value.

Discussion

  • Tobias Tischler

    Tobias Tischler - 2010-05-19

    Diff for tkScale.c 1.28

     
  • Tobias Tischler

    Tobias Tischler - 2010-05-19

    Because I couldn't find a way to upload a second file, here's the diff-content for the header file.

    --- tkScale.h 2005-11-26 20:36:14.000000000 +0100
    +++ tkScale.h 2010-05-18 15:40:33.281250000 +0200
    @@ -233,6 +233,7 @@

    MODULE_SCOPE void TkEventuallyRedrawScale(TkScale *scalePtr, int what);
    MODULE_SCOPE double TkRoundToResolution(TkScale *scalePtr, double value);
    +MODULE_SCOPE double TkRoundTickToResolution(TkScale *scalePtr, double value);
    MODULE_SCOPE TkScale * TkpCreateScale(Tk_Window tkwin);
    MODULE_SCOPE void TkpDestroyScale(TkScale *scalePtr);
    MODULE_SCOPE void TkpDisplayScale(ClientData clientData);