Skip to content

Commit 965d9e0

Browse files
Add scaling functionality for accessibility (ChrisTitusTech#3505)
1 parent 2b9e277 commit 965d9e0

3 files changed

Lines changed: 172 additions & 6 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
function Invoke-WinUtilFontScaling {
2+
<#
3+
4+
.SYNOPSIS
5+
Applies UI and font scaling for accessibility
6+
7+
.PARAMETER ScaleFactor
8+
Sets the scaling from 0.75 and 2.0.
9+
Default is 1.0 (100% - no scaling)
10+
11+
.EXAMPLE
12+
Invoke-WinUtilFontScaling -ScaleFactor 1.25
13+
# Applies 125% scaling
14+
#>
15+
16+
param (
17+
[double]$ScaleFactor = 1.0
18+
)
19+
20+
# Validate if scale factor is within the range
21+
if ($ScaleFactor -lt 0.75 -or $ScaleFactor -gt 2.0) {
22+
Write-Warning "Scale factor must be between 0.75 and 2.0. Using 1.0 instead."
23+
$ScaleFactor = 1.0
24+
}
25+
26+
# Define an array for resources to be scaled
27+
$fontResources = @(
28+
"FontSize",
29+
"ButtonFontSize",
30+
"HeaderFontSize",
31+
"TabButtonFontSize",
32+
"IconFontSize",
33+
"SettingsIconFontSize",
34+
"CloseIconFontSize",
35+
"AppEntryFontSize",
36+
"SearchBarTextBoxFontSize",
37+
"SearchBarClearButtonFontSize",
38+
"CustomDialogFontSize",
39+
"CustomDialogFontSizeHeader",
40+
"ConfigUpdateButtonFontSize",
41+
"CheckBoxBulletDecoratorSize"
42+
)
43+
44+
# Apply scaling to each resource
45+
foreach ($resourceName in $fontResources) {
46+
try {
47+
# Get the default font size from the theme configuration
48+
$originalValue = $sync.configs.themes.shared.$resourceName
49+
if ($originalValue) {
50+
# Convert string to double since values are stored as strings
51+
$originalValue = [double]$originalValue
52+
# Calculates and applies the new font size
53+
$newValue = [math]::Round($originalValue * $ScaleFactor, 1)
54+
$sync.Form.Resources[$resourceName] = $newValue
55+
Write-Debug "Scaled $resourceName from original $originalValue to $newValue (factor: $ScaleFactor)"
56+
}
57+
}
58+
catch {
59+
Write-Warning "Failed to scale resource $resourceName : $_"
60+
}
61+
}
62+
63+
# Update the font scaling percentage displayed on the UI
64+
if ($sync.FontScalingValue) {
65+
$percentage = [math]::Round($ScaleFactor * 100)
66+
$sync.FontScalingValue.Text = "$percentage%"
67+
}
68+
69+
Write-Debug "Font scaling applied with factor: $ScaleFactor"
70+
}
71+
72+

scripts/main.ps1

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ $commonKeyEvents = {
261261
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
262262

263263
$sync["Form"].Add_MouseLeftButtonDown({
264-
Invoke-WPFPopup -Action "Hide" -Popups @("Settings", "Theme")
264+
Invoke-WPFPopup -Action "Hide" -Popups @("Settings", "Theme", "FontScaling")
265265
$sync["Form"].DragMove()
266266
})
267267

@@ -279,7 +279,7 @@ $sync["Form"].Add_MouseDoubleClick({
279279

280280
$sync["Form"].Add_Deactivated({
281281
Write-Debug "WinUtil lost focus"
282-
Invoke-WPFPopup -Action "Hide" -Popups @("Settings", "Theme")
282+
Invoke-WPFPopup -Action "Hide" -Popups @("Settings", "Theme", "FontScaling")
283283
})
284284

285285
$sync["Form"].Add_ContentRendered({
@@ -441,7 +441,7 @@ $sync["Form"].Add_Activated({
441441

442442
$sync["ThemeButton"].Add_Click({
443443
Write-Debug "ThemeButton clicked"
444-
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Hide"; "Theme" = "Toggle" }
444+
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Hide"; "Theme" = "Toggle"; "FontScaling" = "Hide" }
445445
})
446446
$sync["AutoThemeMenuItem"].Add_Click({
447447
Write-Debug "About clicked"
@@ -461,7 +461,7 @@ $sync["LightThemeMenuItem"].Add_Click({
461461

462462
$sync["SettingsButton"].Add_Click({
463463
Write-Debug "SettingsButton clicked"
464-
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Toggle"; "Theme" = "Hide" }
464+
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Toggle"; "Theme" = "Hide"; "FontScaling" = "Hide" }
465465
})
466466
$sync["ImportMenuItem"].Add_Click({
467467
Write-Debug "Import clicked"
@@ -506,5 +506,30 @@ $sync["SponsorMenuItem"].Add_Click({
506506
Show-CustomDialog -Title "Sponsors" -Message $authorInfo -EnableScroll $true
507507
})
508508

509+
# Font Scaling Event Handlers
510+
$sync["FontScalingButton"].Add_Click({
511+
Write-Debug "FontScalingButton clicked"
512+
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Hide"; "Theme" = "Hide"; "FontScaling" = "Toggle" }
513+
})
514+
515+
$sync["FontScalingSlider"].Add_ValueChanged({
516+
param($slider)
517+
$percentage = [math]::Round($slider.Value * 100)
518+
$sync.FontScalingValue.Text = "$percentage%"
519+
})
520+
521+
$sync["FontScalingResetButton"].Add_Click({
522+
Write-Debug "FontScalingResetButton clicked"
523+
$sync.FontScalingSlider.Value = 1.0
524+
$sync.FontScalingValue.Text = "100%"
525+
})
526+
527+
$sync["FontScalingApplyButton"].Add_Click({
528+
Write-Debug "FontScalingApplyButton clicked"
529+
$scaleFactor = $sync.FontScalingSlider.Value
530+
Invoke-WinUtilFontScaling -ScaleFactor $scaleFactor
531+
Invoke-WPFPopup -Action "Hide" -Popups @("FontScaling")
532+
})
533+
509534
$sync["Form"].ShowDialog() | out-null
510535
Stop-Transcript

xaml/inputXML.xaml

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@
948948
<ColumnDefinition Width="Auto"/><!-- Space for close button -->
949949
<ColumnDefinition Width="Auto"/>
950950
<ColumnDefinition Width="Auto"/>
951+
<ColumnDefinition Width="Auto"/><!-- Space for Font Scaling button-->
951952
</Grid.ColumnDefinitions>
952953

953954
<!--
@@ -1032,14 +1033,82 @@
10321033
</Border>
10331034
</Popup>
10341035

1035-
<Button Name="SettingsButton"
1036+
<Button Name="FontScalingButton"
10361037
Style="{StaticResource HoverButtonStyle}"
10371038
Grid.Column="3" BorderBrush="Transparent"
10381039
Background="{DynamicResource MainBackgroundColor}"
10391040
Foreground="{DynamicResource MainForegroundColor}"
10401041
FontSize="{DynamicResource SettingsIconFontSize}"
10411042
Width="{DynamicResource IconButtonSize}" Height="{DynamicResource IconButtonSize}"
10421043
HorizontalAlignment="Right" VerticalAlignment="Top"
1044+
Margin="0,5,5,0"
1045+
FontFamily="Segoe MDL2 Assets"
1046+
Content="&#xE8D3;"
1047+
ToolTip="Adjust Font Scaling for Accessibility"
1048+
/>
1049+
<Popup Grid.Column="3" Name="FontScalingPopup"
1050+
IsOpen="False"
1051+
PlacementTarget="{Binding ElementName=FontScalingButton}" Placement="Bottom"
1052+
HorizontalAlignment="Right" VerticalAlignment="Top">
1053+
<Border Background="{DynamicResource MainBackgroundColor}" BorderBrush="{DynamicResource MainForegroundColor}" BorderThickness="1" CornerRadius="0" Margin="0">
1054+
<StackPanel Background="{DynamicResource MainBackgroundColor}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="200">
1055+
<TextBlock Text="Font Scaling"
1056+
FontSize="{DynamicResource ButtonFontSize}"
1057+
Foreground="{DynamicResource MainForegroundColor}"
1058+
HorizontalAlignment="Center"
1059+
Margin="10,5,10,5"
1060+
FontWeight="Bold"/>
1061+
<Separator Margin="5,0,5,5"/>
1062+
<StackPanel Orientation="Horizontal" Margin="10,5,10,10">
1063+
<TextBlock Text="Small"
1064+
FontSize="{DynamicResource ButtonFontSize}"
1065+
Foreground="{DynamicResource MainForegroundColor}"
1066+
VerticalAlignment="Center"
1067+
Margin="0,0,10,0"/>
1068+
<Slider Name="FontScalingSlider"
1069+
Minimum="0.75" Maximum="2.0"
1070+
Value="1.0"
1071+
TickFrequency="0.25"
1072+
TickPlacement="BottomRight"
1073+
IsSnapToTickEnabled="True"
1074+
Width="120"
1075+
VerticalAlignment="Center"/>
1076+
<TextBlock Text="Large"
1077+
FontSize="{DynamicResource ButtonFontSize}"
1078+
Foreground="{DynamicResource MainForegroundColor}"
1079+
VerticalAlignment="Center"
1080+
Margin="10,0,0,0"/>
1081+
</StackPanel>
1082+
<TextBlock Name="FontScalingValue"
1083+
Text="100%"
1084+
FontSize="{DynamicResource ButtonFontSize}"
1085+
Foreground="{DynamicResource MainForegroundColor}"
1086+
HorizontalAlignment="Center"
1087+
Margin="10,0,10,5"/>
1088+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="10,0,10,10">
1089+
<Button Name="FontScalingResetButton"
1090+
Content="Reset"
1091+
Style="{StaticResource HoverButtonStyle}"
1092+
Width="60" Height="25"
1093+
Margin="5,0,5,0"/>
1094+
<Button Name="FontScalingApplyButton"
1095+
Content="Apply"
1096+
Style="{StaticResource HoverButtonStyle}"
1097+
Width="60" Height="25"
1098+
Margin="5,0,5,0"/>
1099+
</StackPanel>
1100+
</StackPanel>
1101+
</Border>
1102+
</Popup>
1103+
1104+
<Button Name="SettingsButton"
1105+
Style="{StaticResource HoverButtonStyle}"
1106+
Grid.Column="4" BorderBrush="Transparent"
1107+
Background="{DynamicResource MainBackgroundColor}"
1108+
Foreground="{DynamicResource MainForegroundColor}"
1109+
FontSize="{DynamicResource SettingsIconFontSize}"
1110+
Width="{DynamicResource IconButtonSize}" Height="{DynamicResource IconButtonSize}"
1111+
HorizontalAlignment="Right" VerticalAlignment="Top"
10431112
Margin="5,5,5,0"
10441113
FontFamily="Segoe MDL2 Assets"
10451114
Content="&#xE713;"/>
@@ -1067,7 +1136,7 @@
10671136
</Popup>
10681137

10691138
<Button
1070-
Grid.Column="4"
1139+
Grid.Column="5"
10711140
Content="&#xD7;" BorderThickness="0"
10721141
BorderBrush="Transparent"
10731142
Background="{DynamicResource MainBackgroundColor}"

0 commit comments

Comments
 (0)