Skip to content

Commit 16bdb2c

Browse files
author
csaba
committed
Make sure that [tk scaling] will be taken into account when creating the images.
1 parent e1b0158 commit 16bdb2c

File tree

5 files changed

+65
-16
lines changed

5 files changed

+65
-16
lines changed

doc/ttk_spinbox.n

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ Besides the standard \fBTSpinbox\fP layout with small arrow buttons, in
135135
which the up arrow is placed above the down arrow, \fBttk::spinbox\fP
136136
widgets support the \fBWide.TSpinbox\fP style, whose up and down arrows
137137
are of a more user-friendly size and in which the up arrow is placed to
138-
the right of the down arrow.
138+
the right of the down arrow. The size of these arrows depends on the
139+
display's scaling level and Tk's scaling factor given by \fB[tk scaling]\fP
140+
at the time the first themed spinbox widget is created.
139141
.SH "SEE ALSO"
140142
ttk::widget(n), ttk::entry(n), spinbox(n)
141143
.SH KEYWORDS

doc/ttk_toggleswitch.n

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ ttk::toggleswitch \- Create and manipulate a toggleswitch widget
1717
A \fBttk::toggleswitch\fR widget is used to show or change a binary setting.
1818
It consists of a horizontal \fItrough\fR (a fully rounded filled rectangle)
1919
and a \fIslider\fR (a filled circle contained in the trough). Their
20-
dimensions depend on the display's scaling level, the current theme, and the
21-
value of the \fB-size\fR configuration option.
20+
dimensions depend on the value of the \fB-size\fR configuration option, the
21+
current theme, the display's scaling level, and Tk's scaling factor given by
22+
\fB[tk scaling]\fR at the time the first toggleswitch widget is created.
2223
.PP
2324
Just like a light switch, a toggleswitch widget can have one of two possible
2425
\fIswitch state\fRs: on or off. In the on state the slider is placed at the

generic/ttk/ttkEntry.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,17 @@ static void
20252025
SpinboxInitialize(Tcl_Interp *interp, void *recordPtr)
20262026
{
20272027
Spinbox *sb = (Spinbox *)recordPtr;
2028+
2029+
/*
2030+
* Create the WideSpinbox.uparrow and WideSpinbox.downarrow
2031+
* elements for the Wide.TSpinbox style if necessary
2032+
*/
2033+
int code = Tcl_EvalEx(interp, "ttk::wideSpinbox::CondMakeElements",
2034+
TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
2035+
if (code != TCL_OK) {
2036+
Tcl_BackgroundException(interp, code);
2037+
}
2038+
20282039
TtkTrackElementState(&sb->core);
20292040
EntryInitialize(interp, recordPtr);
20302041
}

library/ttk/elements.tcl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ proc ttk::toggleswitch::IsColorLight color {
104104
return [expr {5 * ($g >> 8) + 2 * ($r >> 8) + ($b >> 8) > 8 * 192}]
105105
}
106106

107-
interp alias {} ttk::toggleswitch::CreateImg \
108-
{} image create photo -format $::tk::svgFmt
109107
interp alias {} ttk::toggleswitch::CreateElem {} ttk::style element create
110108

111109
namespace eval ttk::toggleswitch {
@@ -951,9 +949,6 @@ proc ttk::toggleswitch::UpdateElements_aqua {} {
951949
}
952950
}
953951

954-
# Public procedures
955-
# =================
956-
957952
#------------------------------------------------------------------------------
958953
# ttk::toggleswitch::CreateElements
959954
#
@@ -1040,6 +1035,9 @@ proc ttk::toggleswitch::CreateElements {} {
10401035
}
10411036
}
10421037

1038+
# Public procedures
1039+
# =================
1040+
10431041
#------------------------------------------------------------------------------
10441042
# ttk::toggleswitch::CondMakeElements
10451043
#
@@ -1050,6 +1048,12 @@ proc ttk::toggleswitch::CreateElements {} {
10501048
proc ttk::toggleswitch::CondMakeElements {} {
10511049
variable madeElements
10521050
if {!$madeElements} {
1051+
# If Tk's scaling factor was changed via "tk scaling"
1052+
# then $::tk::svgFmt now has the updated value.
1053+
1054+
interp alias {} ::ttk::toggleswitch::CreateImg \
1055+
{} image create photo -format $::tk::svgFmt
1056+
10531057
CreateElements
10541058
set madeElements 1
10551059
}

library/ttk/wideSpinbox.tcl

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
#
1010
# Structure of the module:
1111
# - Private procedures and data
12-
# - Public procedure
12+
# - Public procedures
1313
#==============================================================================
1414

1515
# Private procedures and data
1616
# ===========================
1717

18-
interp alias {} ttk::wideSpinbox::CreateImg \
19-
{} image create photo -format $::tk::svgFmt
2018
interp alias {} ttk::wideSpinbox::CreateElem {} ttk::style element create
2119

2220
namespace eval ttk::wideSpinbox {
@@ -28,10 +26,9 @@ namespace eval ttk::wideSpinbox {
2826
<svg width="20" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
2927
<circle cx="10" cy="8" r="8" fill="bg"/>
3028
<path d="m6 6 4 4 4-4" fill="none" stroke-linecap="round" stroke-linejoin="round" }
31-
variable gapImg [CreateImg -data {
32-
<svg width="4" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg"/>}]
3329

34-
variable onAndroid [expr {[info exists ::tk::android] && $::tk::android}]
30+
variable onAndroid [expr {[info exists ::tk::android] && $::tk::android}]
31+
variable madeElements 0
3532
}
3633

3734
#------------------------------------------------------------------------------
@@ -190,8 +187,37 @@ proc ttk::wideSpinbox::UpdateElements theme {
190187
$aImg configure -data $imgData
191188
}
192189

193-
# Public procedure
194-
# ================
190+
# Public procedures
191+
# =================
192+
193+
#------------------------------------------------------------------------------
194+
# ttk::wideSpinbox::CondMakeElements
195+
#
196+
# Creates the elements WideSpinbox.uparrow and WideSpinbox.downarrow of the
197+
# Wide.TSpinbox layout if necessary. Invoked from within the C code, by the
198+
# ttk::spinbox widget initialization hook.
199+
#------------------------------------------------------------------------------
200+
proc ttk::wideSpinbox::CondMakeElements {} {
201+
variable madeElements
202+
if {!$madeElements} {
203+
# If Tk's scaling factor was changed via "tk scaling"
204+
# then $::tk::svgFmt now has the updated value.
205+
206+
interp alias {} ::ttk::wideSpinbox::CreateImg \
207+
{} image create photo -format $::tk::svgFmt
208+
variable gapImg [CreateImg -data {
209+
<svg width="4" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg"/>}]
210+
211+
set theme [ttk::style theme use]
212+
CreateElements $theme
213+
UpdateElements $theme
214+
215+
variable elemInfoArr
216+
set elemInfoArr($theme) 1
217+
218+
set madeElements 1
219+
}
220+
}
195221

196222
#------------------------------------------------------------------------------
197223
# ttk::wideSpinbox::MakeOrUpdateElements
@@ -202,6 +228,11 @@ proc ttk::wideSpinbox::UpdateElements theme {
202228
# ttk::AppearanceChanged (see ttk.tcl).
203229
#------------------------------------------------------------------------------
204230
proc ttk::wideSpinbox::MakeOrUpdateElements {} {
231+
variable madeElements
232+
if {!$madeElements} {
233+
return ""
234+
}
235+
205236
variable elemInfoArr
206237
set theme [ttk::style theme use]
207238

0 commit comments

Comments
 (0)