Updated zoom level

This commit is contained in:
Florian Rappl
2026-09-04 16:03:43 +02:00
parent 703cf8f880
commit 98c72af3d6
8 changed files with 109 additions and 6 deletions

View File

@@ -0,0 +1,18 @@
namespace ElectronNET.API.Entities
{
/// <summary>
/// The direction of a zoom change triggered by the user.
/// </summary>
public enum ZoomDirection
{
/// <summary>
/// The user zoomed in.
/// </summary>
In,
/// <summary>
/// The user zoomed out.
/// </summary>
Out
}
}

View File

@@ -113,6 +113,15 @@ public class WebContents : ApiBase
remove => RemoveEvent(value, Id);
}
/// <summary>
/// Emitted when the user is requesting to change the zoom level using the mouse wheel or the keyboard.
/// </summary>
public event Action<ZoomDirection> OnZoomChanged
{
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
internal WebContents(int id)
{
Id = id;
@@ -337,14 +346,14 @@ public class WebContents : ApiBase
/// Returns number - The current zoom level.
/// </summary>
/// <returns></returns>
public Task<int> GetZoomLevelAsync() => InvokeAsync<int>();
public Task<double> GetZoomLevelAsync() => InvokeAsync<double>();
/// <summary>
/// Changes the zoom level to the specified level.
/// The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively.
/// </summary>
/// <param name="level"></param>
public void SetZoomLevel(int level)
public void SetZoomLevel(double level)
{
BridgeConnector.Socket.Emit("webContents-setZoomLevel", Id, level);
}
@@ -354,7 +363,7 @@ public class WebContents : ApiBase
/// </summary>
/// <param name="minimumLevel"></param>
/// <param name="maximumLevel"></param>
public Task SetVisualZoomLevelLimitsAsync(int minimumLevel, int maximumLevel)
public Task SetVisualZoomLevelLimitsAsync(double minimumLevel, double maximumLevel)
{
var tcs = new TaskCompletionSource();