FIX: SwitchButton auto scale font

Change-Id: If4004c0963cc8bb2f41e8e71c304d5239bf252ab
Jira: STUDIO-4969 STUDIO-4921
This commit is contained in:
chunmao.guo 2023-12-04 18:45:11 +08:00 committed by Lane.Wei
parent 2564c51b36
commit 818416d081
1 changed files with 7 additions and 0 deletions

View File

@ -82,6 +82,7 @@ void SwitchButton::Rescale()
textSize[0] = dc.GetTextExtent(labels[0]); textSize[0] = dc.GetTextExtent(labels[0]);
textSize[1] = dc.GetTextExtent(labels[1]); textSize[1] = dc.GetTextExtent(labels[1]);
} }
float fontScale = 0;
{ {
thumbSize = textSize[0]; thumbSize = textSize[0];
auto size = textSize[1]; auto size = textSize[1];
@ -96,6 +97,7 @@ void SwitchButton::Rescale()
maxWidth *= scale; maxWidth *= scale;
#endif #endif
if (trackSize.x > maxWidth) { if (trackSize.x > maxWidth) {
fontScale = float(maxWidth) / trackSize.x;
thumbSize.x -= (trackSize.x - maxWidth) / 2; thumbSize.x -= (trackSize.x - maxWidth) / 2;
trackSize.x = maxWidth; trackSize.x = maxWidth;
} }
@ -115,6 +117,11 @@ void SwitchButton::Rescale()
memdc.SelectObject(bmp); memdc.SelectObject(bmp);
#endif #endif
memdc.SetFont(dc.GetFont()); memdc.SetFont(dc.GetFont());
if (fontScale) {
memdc.SetFont(dc.GetFont().Scaled(fontScale));
textSize[0] = memdc.GetTextExtent(labels[0]);
textSize[1] = memdc.GetTextExtent(labels[1]);
}
auto state = i == 0 ? StateColor::Enabled : (StateColor::Checked | StateColor::Enabled); auto state = i == 0 ? StateColor::Enabled : (StateColor::Checked | StateColor::Enabled);
{ {
#ifdef __WXMSW__ #ifdef __WXMSW__