Skip to content

Commit

Permalink
Add ScaleChanged event, some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Perksey committed Dec 8, 2024
1 parent 237675b commit c46fd50
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions documentation/proposals/Proposal - Windowing 3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -1121,15 +1121,20 @@ public interface ISurfaceWindow
/// </summary>
bool IsCloseRequested { get; set; }

/// <summary>
/// Raised when <see cref="IsCloseRequested" /> is set to <c>true</c>.
/// </summary>
event Action<WindowToggleEvent> CloseRequested { add; remove; }

/// <summary>
/// Gets or sets a value indicating whether the window is visible.
/// </summary>
bool IsVisible { get; set; }

/// <summary>
/// Raised when <see cref="IsCloseRequested" /> is set to <c>true</c>.
/// Raised when <see cref="IsVisible" /> changes.
/// </summary>
event Action<WindowToggleEvent> CloseRequested { add; remove; }
event Action<WindowToggleEvent> VisibilityChanged { add; remove; }

/// <summary>
/// Gets or sets a value indicating whether the window currently has input focus. If setting to <c>true</c>, the
Expand Down Expand Up @@ -1529,15 +1534,35 @@ their rendering code. It provides no configuration but provides extra informatio
```cs
namespace Silk.NET.Windowing;

/// <summary>
/// Contains properties pertaining to a change in a surface's scale.
/// </summary>
/// <param name="Surface">The surface to which the change in scale occurred.</param>
/// <param name="OldContent">The previous value for <see cref="ISurfaceScale.Content"/>.</param>
/// <param name="NewContent">The new value for <see cref="ISurfaceScale.Content"/>.</param>
/// <param name="OldDraw">The previous value for <see cref="ISurfaceScale.Draw"/>.</param>
/// <param name="NewDraw">The new value for <see cref="ISurfaceScale.Draw"/>.</param>
/// <param name="OldPixelDensity">The previous value for <see cref="ISurfaceScale.PixelDensity"/>.</param>
/// <param name="NewPixelDensity">The new value for <see cref="ISurfaceScale.PixelDensity"/>.</param>
public readonly record struct ScaleChangedEvent(
Surface Surface,
float OldContent,
float NewContent,
float OldDraw,
float NewDraw,
float OldPixelDensity,
float NewPixelDensity
);

/// <summary>
/// Provides information pertaining to the surface's graphical scaling.
/// </summary>
/// <remarks>
/// <see cref="ContentScale" /> is typically used to scale UI elements to the correct size for the end user.
/// <see cref="Content" /> is typically used to scale UI elements to the correct size for the end user.
/// <see cref="PixelDensity" /> on the other hand is used to scale the entire application to cover the entire client
/// area in cases where the window client size is smaller than the actual drawable size (i.e. it is high density).
/// If scaling content for legibility and scaling the application's rendering as a whole are not needed to be separated,
/// it is recommended to use <see cref="DrawScale" />. Implementations shall always request a high density surface if
/// it is recommended to use <see cref="Draw" />. Implementations shall always request a high density surface if
/// given the choice, to account for the platforms where applications may not be able to opt-out of high density.
/// </remarks>
public interface ISurfaceScale
Expand All @@ -1546,35 +1571,40 @@ public interface ISurfaceScale
/// Gets the factor with which the application should scale its content to make the content more legible for the
/// user. This has no influence on <see cref="Surface.DrawableSize" />.
/// </summary>
/// <seealso cref="DrawScale" />
float ContentScale { get; }
/// <seealso cref="Draw" />
float Content { get; }

/// <summary>
/// Gets the suggested amplification factor when drawing in terms of <see cref="Surface.DrawableSize" />. This
/// represents the scale from the pixel resolution to the desired content size, and is typically the multiplication
/// of <see cref="PixelDensity" /> and <see cref="ContentScale" />.
/// of <see cref="PixelDensity" /> and <see cref="Content" />.
/// </summary>
/// <remarks>
/// For example, if <see cref="PixelDensity" /> is <c>2.0</c> (i.e. there are 2 pixels per screen coordinate)
/// <i>and</i> the window manager requests that applications scale their content up by <c>2.0</c> to meet the user's
/// settings as per <see cref="ContentScale" />, this would be <c>4.0</c>. This is because we're scaling once to
/// settings as per <see cref="Content" />, this would be <c>4.0</c>. This is because we're scaling once to
/// account for the fact that the application has twice the amount of pixels available to it for the given window
/// size, and then scaling again so that what we are drawing appears zoomed in as per the user's request. Note that
/// it is rarely the case that an operating system employs both dense pixels <i>and</i> content scale. macOS for
/// instance, instead of setting <see cref="ContentScale" />, opts to scale the resolution in the cases where the
/// instance, instead of setting <see cref="Content" />, opts to scale the resolution in the cases where the
/// user wants magnified visuals instead of having the applications scale their content; whereas Windows sets
/// <see cref="ContentScale" /> and instead always keeps <see cref="PixelDensity" /> as <c>1.0</c>. This is down
/// <see cref="Content" /> and instead always keeps <see cref="PixelDensity" /> as <c>1.0</c>. This is down
/// to philosophical differences between the window coordinate systems on platforms as to whether they prefer to
/// deal in physical device pixels or physical content sizes.
/// </remarks>
float DrawScale { get; }
float Draw { get; }

/// <summary>
/// Gets the ratio of pixels rendered to window size. This shall be equivalent to
/// <see cref="Surface.DrawableSize" /> divided by <see cref="ISurfaceWindow.ClientSize" />.
/// </summary>
/// <seealso cref="DrawScale" />
/// <seealso cref="Draw" />
float PixelDensity { get; }

/// <summary>
/// An event raised when any scale factor changes.
/// </summary>
event Action<ScaleChangedEvent> Changed { add; remove; }
}

public abstract partial class Surface
Expand Down

0 comments on commit c46fd50

Please sign in to comment.