• Custom scaling factor for Tk 9 widgets

    From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Mon Mar 24 12:07:46 2025
    From Newsgroup: comp.lang.tcl

    Dear Tk team, dear Csaba,

    thanks for making Tk scalable.

    Please allow me to ask a dump question.

    My applications do use a custom scaling factor based on character size.

    For the AWThemes, there was the possibility of a scaling factor and I
    set it before activating the theme. This scales all elements like
    checkboxes etc.

    Here is a snippet with a font size in points in Config(FontSize):
    example: 32

    package require awthemes
    # >> Do AWDark scaling
    # >> Get element scaling factor from current font size
    set dFontSpec [font actual TkDefaultFont]
    dict set dFontSpec -size $Config(FontSize)
    set ScaleCur [expr {
    double([font metrics $dFontSpec -ascent])
    / [font metrics TkDefaultFont -ascent]}]
    ::themeutils::setThemeColors AWDark scale.factor $ScaleCur
    package require AWDark
    ttk::style theme use AWDark

    Is it possible to do something like this with plain Tk 9.0 ?

    Is it even possible to change the scaling factor on runtime ?
    (this is not possible with the AWThemes) ?

    Thanks for any answer,
    Harald

    P.S.: and it is so sad, that Brad Lanam is gone. With Tk 9, the AWThemes
    would be even greater...
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From nemethi@csaba.nemethi@t-online.de to comp.lang.tcl on Mon Mar 24 13:06:11 2025
    From Newsgroup: comp.lang.tcl

    Am 24.03.25 um 12:07 schrieb Harald Oehlmann:
    Dear Tk team, dear Csaba,

    thanks for making Tk scalable.

    Please allow me to ask a dump question.

    My applications do use a custom scaling factor based on character size.

    For the AWThemes, there was the possibility of a scaling factor and I
    set it before activating the theme. This scales all elements like
    checkboxes etc.

    Here is a snippet with a font size in points in Config(FontSize):
    example: 32

    package require awthemes
    # >> Do AWDark scaling
    # >> Get element scaling factor from current font size
    set dFontSpec [font actual TkDefaultFont]
    dict set dFontSpec -size $Config(FontSize)
    set ScaleCur [expr {
        double([font metrics $dFontSpec -ascent])
        / [font metrics TkDefaultFont -ascent]}] ::themeutils::setThemeColors AWDark scale.factor $ScaleCur
    package require AWDark
    ttk::style theme use AWDark

    Is it possible to do something like this with plain Tk 9.0 ?

    Is it even possible to change the scaling factor on runtime ?
    (this is not possible with the AWThemes) ?

    Thanks for any answer,
    Harald

    P.S.: and it is so sad, that Brad Lanam is gone. With Tk 9, the AWThemes would be even greater...

    Tk sets the variables tk::scalingPct and tk::svgFmt at initialization
    time. The reference manual states, among others, the following:

    tk::scalingPct
    Note that any access to this variable is supposed to be
    strictly read-only! Note also that whenever the scaling
    factor used to convert between physical units and pixels
    is changed via tk scaling, the value of the variable
    tk::scalingPct is automatically updated.

    tk::svgFmt
    Note that any access to this variable is supposed to be
    strictly read-only! Note also that whenever the scaling
    factor used to convert between physical units and pixels
    is changed via tk scaling, the value of the variable
    tk::svgFmt is automatically updated.

    That is, on runtime you can invoke "tk scaling", which will not only
    change tk's scaling factor used to convert between physical units and
    pixels, but will also automatically update the variables tk::scalingPct
    and tk::svgFmt.

    For example, if initially "tk scaling" returns 1.33 (as is the case on
    an unscaled screen) and you invoke

    tk scaling 2.66

    then the value of tk::scalingPct will become 200 and that of tk::svgFmt
    will become "svg -scale 2.0". And the checkbuttons of all builtin
    themes will become twice as large as without the above command invocation.
    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba.nemethi@t-online.de
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Mon Mar 24 14:23:22 2025
    From Newsgroup: comp.lang.tcl

    Am 24.03.2025 um 13:06 schrieb nemethi:
    Am 24.03.25 um 12:07 schrieb Harald Oehlmann:
    Dear Tk team, dear Csaba,

    thanks for making Tk scalable.

    Please allow me to ask a dump question.

    My applications do use a custom scaling factor based on character size.

    For the AWThemes, there was the possibility of a scaling factor and I
    set it before activating the theme. This scales all elements like
    checkboxes etc.

    Here is a snippet with a font size in points in Config(FontSize):
    example: 32

    package require awthemes
    # >> Do AWDark scaling
    # >> Get element scaling factor from current font size
    set dFontSpec [font actual TkDefaultFont]
    dict set dFontSpec -size $Config(FontSize)
    set ScaleCur [expr {
         double([font metrics $dFontSpec -ascent])
         / [font metrics TkDefaultFont -ascent]}]
    ::themeutils::setThemeColors AWDark scale.factor $ScaleCur
    package require AWDark
    ttk::style theme use AWDark

    Is it possible to do something like this with plain Tk 9.0 ?

    Is it even possible to change the scaling factor on runtime ?
    (this is not possible with the AWThemes) ?

    Thanks for any answer,
    Harald

    P.S.: and it is so sad, that Brad Lanam is gone. With Tk 9, the
    AWThemes would be even greater...

    Tk sets the variables tk::scalingPct and tk::svgFmt at initialization time.  The reference manual states, among others, the following:

    tk::scalingPct
        Note that any access to this variable is supposed  to  be
        strictly  read-only!  Note also that whenever the scaling
        factor used to convert between physical units and  pixels
        is  changed  via  tk  scaling,  the value of the variable
        tk::scalingPct is automatically updated.

    tk::svgFmt
        Note  that  any access to this variable is supposed to be
        strictly read-only!  Note also that whenever the  scaling
        factor  used to convert between physical units and pixels
        is changed via tk scaling,  the  value  of  the  variable
        tk::svgFmt is automatically updated.

    That is, on runtime you can invoke "tk scaling", which will not only
    change tk's scaling factor used to convert between physical units and pixels, but will also automatically update the variables tk::scalingPct
    and tk::svgFmt.

    For example, if initially "tk scaling" returns 1.33 (as is the case on
    an unscaled screen) and you invoke

        tk scaling 2.66

    then the value of tk::scalingPct will become 200 and that of tk::svgFmt
    will become "svg -scale 2.0".  And the checkbuttons of all builtin
    themes will become twice as large as without the above command invocation.


    Ok, great. So, you may change at any time and any new widget will honor
    the new value.
    I have to test, what happens, if changed on the fly.

    Thanks for all,
    Harald

    --- Synchronet 3.20c-Linux NewsLink 1.2