Skip to content

Commit 5ad15ab

Browse files
Reapply DPI sizing fixes after formatting
1 parent b00460a commit 5ad15ab

7 files changed

Lines changed: 74 additions & 39 deletions

File tree

src/UniGetUI/Controls/CustomNavViewItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace UniGetUI.Controls;
99

1010
internal sealed partial class CustomNavViewItem : NavigationViewItem
1111
{
12-
int _iconSize = 28;
12+
int _iconSize = 24;
1313
public IconType LocalIcon
1414
{
1515
set => base.Icon = new LocalIcon(value);
@@ -62,15 +62,15 @@ public string Text
6262

6363
public CustomNavViewItem()
6464
{
65-
Height = 60;
65+
Height = 54;
6666
Resources["NavigationViewItemOnLeftIconBoxHeight"] = _iconSize;
6767
Resources["NavigationViewItemContentPresenterMargin"] = new Thickness(0);
6868

69-
var grid = new Grid { Height = 50 };
69+
var grid = new Grid { Height = 44 };
7070

7171
_progressRing = new ProgressRing
7272
{
73-
Margin = new Thickness(-46, 0, 0, 0),
73+
Margin = new Thickness(-42, 0, 0, 0),
7474
HorizontalAlignment = HorizontalAlignment.Left,
7575
VerticalAlignment = VerticalAlignment.Center,
7676
IsIndeterminate = true,

src/UniGetUI/MainWindow.xaml.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,27 @@ public IntPtr GetWindowHandle()
748748
return WinRT.Interop.WindowNative.GetWindowHandle(this);
749749
}
750750

751+
private double GetWindowRasterizationScale()
752+
{
753+
uint dpi = NativeHelpers.GetDpiForWindow(GetWindowHandle());
754+
if (dpi > 0)
755+
{
756+
return dpi / 96.0;
757+
}
758+
759+
return MainContentGrid.XamlRoot?.RasterizationScale ?? 1.0;
760+
}
761+
762+
private int ConvertPhysicalPixelsToDips(int physicalPixels)
763+
{
764+
return (int)Math.Round(physicalPixels / Math.Max(GetWindowRasterizationScale(), 0.01));
765+
}
766+
767+
private int ConvertDipsToPhysicalPixels(int dips)
768+
{
769+
return Math.Max(1, (int)Math.Round(dips * GetWindowRasterizationScale()));
770+
}
771+
751772
public async Task HandleMissingDependencies(IReadOnlyList<ManagerDependency> dependencies)
752773
{
753774
int current = 1;
@@ -803,7 +824,7 @@ private async Task SaveGeometry(bool Force = false)
803824
}
804825

805826
string geometry =
806-
$"{AppWindow.Position.X},{AppWindow.Position.Y},{AppWindow.Size.Width},{AppWindow.Size.Height},{windowState}";
827+
$"v2,{AppWindow.Position.X},{AppWindow.Position.Y},{ConvertPhysicalPixelsToDips(AppWindow.Size.Width)},{ConvertPhysicalPixelsToDips(AppWindow.Size.Height)},{windowState}";
807828

808829
Logger.Debug($"Saving window geometry {geometry}");
809830
Settings.SetValue(Settings.K.WindowGeometry, geometry);
@@ -818,10 +839,10 @@ private void RestoreGeometry()
818839
{
819840
string geometry = Settings.GetValue(Settings.K.WindowGeometry);
820841
string[] items = geometry.Split(",");
821-
if (items.Length != 5)
842+
if (items.Length is not (5 or 6))
822843
{
823844
Logger.Warn(
824-
$"The restored geometry did not have exactly 5 items (found length was {items.Length})"
845+
$"The restored geometry did not have a supported item count (found length was {items.Length})"
825846
);
826847
return;
827848
}
@@ -833,11 +854,22 @@ private void RestoreGeometry()
833854
State;
834855
try
835856
{
836-
X = int.Parse(items[0]);
837-
Y = int.Parse(items[1]);
838-
Width = int.Parse(items[2]);
839-
Height = int.Parse(items[3]);
840-
State = int.Parse(items[4]);
857+
if (items.Length == 6 && items[0] == "v2")
858+
{
859+
X = int.Parse(items[1]);
860+
Y = int.Parse(items[2]);
861+
Width = ConvertDipsToPhysicalPixels(int.Parse(items[3]));
862+
Height = ConvertDipsToPhysicalPixels(int.Parse(items[4]));
863+
State = int.Parse(items[5]);
864+
}
865+
else
866+
{
867+
X = int.Parse(items[0]);
868+
Y = int.Parse(items[1]);
869+
Width = int.Parse(items[2]);
870+
Height = int.Parse(items[3]);
871+
State = int.Parse(items[4]);
872+
}
841873
}
842874
catch (Exception ex)
843875
{
@@ -936,7 +968,7 @@ private void TitleBar_PaneToggleRequested(TitleBar sender, object args)
936968
if (NavigationPage is null)
937969
return;
938970

939-
if (this.AppWindow.Size.Width >= 1600)
971+
if (MainContentGrid.ActualWidth >= 1600)
940972
{
941973
Settings.Set(
942974
Settings.K.CollapseNavMenuOnWideScreen,
@@ -1005,6 +1037,9 @@ public static class NativeHelpers
10051037
[return: MarshalAs(UnmanagedType.Bool)]
10061038
public static extern bool SetForegroundWindow(IntPtr hWnd);
10071039

1040+
[DllImport("user32.dll")]
1041+
public static extern uint GetDpiForWindow(IntPtr hWnd);
1042+
10081043
public const int MONITORINFOF_PRIMARY = 0x00000001;
10091044

10101045
[StructLayout(LayoutKind.Sequential)]

src/UniGetUI/Pages/DialogPages/PackageDetailsPage.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
</Grid.ColumnDefinitions>
4040
<Border
4141
Grid.Column="0"
42-
Width="128"
43-
Height="128"
42+
Width="112"
43+
Height="112"
4444
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
45-
BorderThickness="10"
46-
CornerRadius="24"
45+
BorderThickness="8"
46+
CornerRadius="20"
4747
>
48-
<Image Name="PackageIcon" Width="80" Height="80" Margin="8" />
48+
<Image Name="PackageIcon" Width="72" Height="72" Margin="8" />
4949
</Border>
5050

5151
<TextBlock
@@ -54,7 +54,7 @@
5454
HorizontalAlignment="Left"
5555
VerticalAlignment="Center"
5656
FontFamily="Segoe UI Variable Display"
57-
FontSize="50"
57+
FontSize="40"
5858
FontWeight="Bold"
5959
TextWrapping="Wrap"
6060
/>

src/UniGetUI/Pages/DialogPages/PackageDetailsPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public void PackageDetailsPage_SizeChanged(
581581
SizeChangedEventArgs? e = null
582582
)
583583
{
584-
if (MainApp.Instance.MainWindow.AppWindow.Size.Width < 950)
584+
if (ActualWidth < 950)
585585
{
586586
if (__layout_mode != LayoutMode.Normal)
587587
{

src/UniGetUI/Pages/SettingsPages/SettingsBasePage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
</Grid.ColumnDefinitions>
4545
<Button
4646
Name="BackButton"
47-
Width="40"
48-
Height="40"
47+
Width="36"
48+
Height="36"
4949
Padding="6"
5050
VerticalAlignment="Center"
5151
Background="Transparent"
@@ -65,7 +65,7 @@
6565
Grid.Column="1"
6666
HorizontalAlignment="Stretch"
6767
VerticalAlignment="Center"
68-
FontSize="30"
68+
FontSize="24"
6969
FontWeight="Bold"
7070
Text=""
7171
TextWrapping="Wrap"

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -509,21 +509,21 @@
509509
x:Name="HeaderIcon"
510510
Grid.Row="0"
511511
Grid.Column="0"
512-
Width="60"
513-
MinHeight="60"
514-
Margin="0,0,-8,0"
515-
FontSize="50"
512+
Width="52"
513+
MinHeight="52"
514+
Margin="0,0,-6,0"
515+
FontSize="40"
516516
FontWeight="Normal"
517517
/>
518518

519519
<StackPanel Grid.Column="1" VerticalAlignment="Center" Orientation="Vertical" Spacing="0">
520520
<TextBlock
521521
x:Name="MainTitle"
522-
MaxHeight="70"
522+
MaxHeight="60"
523523
HorizontalAlignment="Left"
524524
x:FieldModifier="protected"
525525
FontFamily="Segoe UI Variable Display"
526-
FontSize="30"
526+
FontSize="24"
527527
FontWeight="Bold"
528528
TextWrapping="Wrap"
529529
/>
@@ -532,7 +532,7 @@
532532
MaxHeight="40"
533533
HorizontalAlignment="Left"
534534
x:FieldModifier="protected"
535-
FontSize="11"
535+
FontSize="12"
536536
FontWeight="Normal"
537537
Foreground="{ThemeResource AppBarItemDisabledForegroundThemeBrush}"
538538
TextWrapping="Wrap"
@@ -1228,31 +1228,31 @@
12281228
>
12291229
<Grid.RowDefinitions>
12301230
<RowDefinition Height="*" />
1231-
<RowDefinition Height="80" />
1231+
<RowDefinition Height="64" />
12321232
<RowDefinition Height="*" />
12331233
</Grid.RowDefinitions>
12341234
<Grid.ColumnDefinitions>
12351235
<ColumnDefinition Width="*" />
1236-
<ColumnDefinition Width="8*" MaxWidth="800" />
1237-
<ColumnDefinition Width="80" />
1236+
<ColumnDefinition Width="8*" MaxWidth="720" />
1237+
<ColumnDefinition Width="64" />
12381238
<ColumnDefinition Width="*" />
12391239
</Grid.ColumnDefinitions>
12401240
<TextBox
12411241
x:Name="MegaQueryBlock"
12421242
Grid.Row="1"
12431243
Grid.Column="1"
1244-
Padding="20,11,10,11"
1244+
Padding="16,8,10,8"
12451245
x:FieldModifier="protected"
12461246
CornerRadius="8,0,0,8"
1247-
FontSize="40"
1247+
FontSize="28"
12481248
FontWeight="SemiBold"
12491249
/>
12501250
<Button
12511251
x:Name="MegaFindButton"
12521252
Grid.Row="1"
12531253
Grid.Column="2"
1254-
Width="80"
1255-
Height="80"
1254+
Width="64"
1255+
Height="64"
12561256
Padding="12"
12571257
x:FieldModifier="protected"
12581258
AutomationProperties.HelpText="Search"

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,14 +1680,14 @@ private void ABSTRACT_PAGE_SizeChanged(object sender, SizeChangedEventArgs e)
16801680
if (_pageIsWide != false)
16811681
{
16821682
_pageIsWide = false;
1683-
MainTitle.FontSize = 20;
1683+
MainTitle.FontSize = 18;
16841684
}
16851685
}
16861686
else
16871687
{
16881688
if (_pageIsWide != true)
16891689
{
1690-
MainTitle.FontSize = 30;
1690+
MainTitle.FontSize = 24;
16911691
_pageIsWide = true;
16921692
}
16931693
}

0 commit comments

Comments
 (0)