From 228930e2ebc3ddc1c9a5a8aa300a5e7e6c94998d Mon Sep 17 00:00:00 2001
From: filipeotero <89042471+filipeotero@users.noreply.github.com>
Date: Wed, 30 Nov 2022 23:56:13 -0300
Subject: [PATCH] DYN-5426 Setting different font size when the height of the
library is smaller (#13578)
* Setting different font size when the height is smaller
* calculate the font size based on the screen height
---
.../LibraryViewController.cs | 30 +++++++++++++++++++
.../web/library/library.html | 8 ++---
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/LibraryViewExtensionWebView2/LibraryViewController.cs b/src/LibraryViewExtensionWebView2/LibraryViewController.cs
index ecd496a69fe..d1e48ed60e3 100644
--- a/src/LibraryViewExtensionWebView2/LibraryViewController.cs
+++ b/src/LibraryViewExtensionWebView2/LibraryViewController.cs
@@ -49,6 +49,12 @@ public class LibraryViewController : IDisposable
private LibraryViewCustomization customization;
internal string WebBrowserUserDataFolder { get; set; }
+ //Assuming that the fon size is 14px and the screen height is 1080 initially
+ private const int standardFontSize = 14;
+ private const int standardScreenHeight = 1080;
+ private double libraryFontSize;
+
+
///
/// Creates a LibraryViewController.
///
@@ -313,6 +319,8 @@ private void Browser_CoreWebView2InitializationCompleted(object sender, CoreWebV
{
string msg = ex.Message;
}
+
+ SetLibraryFontSize();
}
private void Browser_Loaded(object sender, RoutedEventArgs e)
@@ -328,6 +336,25 @@ private void Browser_SizeChanged(object sender, SizeChangedEventArgs e)
{
browser.InvalidateVisual();
UpdatePopupLocation();
+ SetLibraryFontSize();
+ }
+ }
+
+ //Changes the size of the font's library depending of the screen height
+ private async void SetLibraryFontSize()
+ {
+ //Gets the height of the primary monitor
+ var height = SystemParameters.PrimaryScreenHeight;
+
+ //Calculates the proportion of the font size depending on the screen height
+ //Changing the scale also changes the screen height (F.E: height of 1080px with 150% will be actually 720px)
+ var fontSize = (standardFontSize * height) / standardScreenHeight;
+
+ if(fontSize != libraryFontSize)
+ {
+ var result = await ExecuteScriptFunctionAsync(browser, "setLibraryFontSize", fontSize);
+ if(result != null)
+ libraryFontSize = fontSize;
}
}
@@ -553,6 +580,9 @@ protected void Dispose(bool disposing)
public static async Task ExecuteScriptFunctionAsync(WebView2 webView2, string functionName, params object[] parameters)
{
+ if (webView2.CoreWebView2 == null)
+ return null;
+
string script = functionName + "(";
for (int i = 0; i < parameters.Length; i++)
{
diff --git a/src/LibraryViewExtensionWebView2/web/library/library.html b/src/LibraryViewExtensionWebView2/web/library/library.html
index 3a5523b5704..64978b3bdd1 100644
--- a/src/LibraryViewExtensionWebView2/web/library/library.html
+++ b/src/LibraryViewExtensionWebView2/web/library/library.html
@@ -9,10 +9,6 @@