Skip to content

Commit

Permalink
Refactor, misc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Oct 11, 2024
1 parent f5d095a commit cad3508
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/PicView.Avalonia/ImageHandling/ImageModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using PicView.Avalonia.Navigation;
using PicView.Core.ImageDecoding;
using PicView.Core.ImageDecoding;

namespace PicView.Avalonia.ImageHandling;

public class ImageModel
public record ImageModel
{
public object? Image { get; set; }
public FileInfo? FileInfo { get; set; }
Expand Down
27 changes: 17 additions & 10 deletions src/PicView.Avalonia/UI/ScreenHelper.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
using Avalonia.Controls;

namespace PicView.Avalonia.UI;
public readonly struct ScreenSize(double workingAreaWidth, double workingAreaHeight, double scaling)

public readonly record struct ScreenSize
{
public double WorkingAreaWidth { get; init; } = workingAreaWidth;
public double WorkingAreaHeight { get; init; } = workingAreaHeight;
public double Scaling { get; init; } = scaling;
public double WorkingAreaWidth { get; init; }
public double WorkingAreaHeight { get; init; }
public double Scaling { get; init; }
}

public static class ScreenHelper
{
private static readonly Lock _lock = new();
private static readonly Lock Lock = new();
public static ScreenSize ScreenSize { get; private set; }

public static void UpdateScreenSize(Window window)
{
// TODO: Add support for dragging between multiple monitors
// Dragging to monitor with different scaling (DPI) causes weird incorrect size behavior,
// but starting the application works fine for either monitor, until you drag it to the other.
// It works most of the time in debug mode, but not so much for AOT release

// Need to lock it to prevent multiple calls
lock (_lock)
lock (Lock)
{
var screen = window.Screens.ScreenFromVisual(window);

var monitorWidth = screen.Bounds.Width / screen.Scaling;
var monitorHeight = screen.Bounds.Height / screen.Scaling;
var monitorWidth = screen.WorkingArea.Width / screen.Scaling;
var monitorHeight = screen.WorkingArea.Height / screen.Scaling;

ScreenSize = new ScreenSize(monitorWidth, monitorHeight, screen.Scaling)
ScreenSize = new ScreenSize
{
WorkingAreaWidth = monitorWidth,
WorkingAreaHeight = monitorHeight,
Scaling = screen.Scaling,
};
}
}
}
}
18 changes: 9 additions & 9 deletions src/PicView.Core/Config/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PicView.Core.Config;

public class AppSettings
public record AppSettings
{
public double Version { get; set; } = 1.1;
public WindowProperties? WindowProperties { get; set; }
Expand All @@ -13,7 +13,7 @@ public class AppSettings
public StartUp? StartUp { get; set; }
}

public class WindowProperties
public record WindowProperties
{
public double Top { get; set; } = 0;
public double Left { get; set; } = 0;
Expand All @@ -26,7 +26,7 @@ public class WindowProperties
public bool KeepCentered { get; set; } = false;
}

public class UIProperties
public record UIProperties
{
public string UserLanguage { get; set; } = "en";
public bool ShowInterface { get; set; } = true;
Expand All @@ -41,7 +41,7 @@ public class UIProperties
public bool OpenInSameWindow { get; set; } = false;
}

public class Theme
public record Theme
{
public bool Dark { get; set; } = true;
public int ColorTheme { get; set; } = 3;
Expand All @@ -50,7 +50,7 @@ public class Theme
public bool GlassTheme { get; set; } = false;
}

public class Gallery
public record Gallery
{
public bool IsBottomGalleryShown { get; set; } = false;
public bool ShowBottomGalleryInHiddenUI { get; set; } = false;
Expand All @@ -60,15 +60,15 @@ public class Gallery
public string BottomGalleryStretchMode { get; set; } = "Uniform";
}

public class ImageScaling
public record ImageScaling
{
public bool StretchImage { get; set; } = false;
public bool IsScalingSetToNearestNeighbor { get; set; } = false;

public bool ShowImageSideBySide { get; set; } = false;
}

public class Zoom
public record Zoom
{
public double ZoomSpeed { get; set; } = 0.3;
public bool AvoidZoomingOut { get; set; } = false;
Expand All @@ -77,7 +77,7 @@ public class Zoom
public bool ScrollEnabled { get; set; } = false;
}

public class Sorting
public record Sorting
{
public bool Name { get; set; } = true;
public bool Size { get; set; } = false;
Expand All @@ -91,7 +91,7 @@ public class Sorting
public bool IncludeSubDirectories { get; set; } = false;
}

public class StartUp
public record StartUp
{
public bool OpenLastFile { get; set; } = false;
public bool OpenSpecificFile { get; set; } = false;
Expand Down
2 changes: 1 addition & 1 deletion src/PicView.Core/Localization/LanguageModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PicView.Core.Localization;

public class LanguageModel
public record LanguageModel
{
public string? Loading { get; set; }
public string? NoImage { get; set; }
Expand Down

0 comments on commit cad3508

Please sign in to comment.