Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Simplify implementation for ImageTagSet equality #1116

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
27 changes: 17 additions & 10 deletions Xwt/Xwt.Drawing/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Image: XwtObject, IDisposable
internal StyleSet styles;

internal static int[] SupportedScales = { 2 };
internal static string[] SupportedScalesTags = SupportedScales.Select(scale => "@" + scale + "x").ToArray();

internal Image ()
{
Expand Down Expand Up @@ -1183,16 +1184,22 @@ public override object LoadImage (string fileName)

public override IEnumerable<string> GetAlternativeFiles (string fileName, string baseName, string ext)
{
if (!Context.RegisteredStyles.Any ()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check breaks my brain. I don't really understand why it is !Context.RegisteredStyles.Any()

foreach (var s in Image.SupportedScales) {
var fn = baseName + "@" + s + "x" + ext;
if (File.Exists (fn))
yield return fn;
}
} else {
var files = Directory.EnumerateFiles (Path.GetDirectoryName (fileName), Path.GetFileName (baseName) + "*" + ext);
foreach (var f in files)
yield return f;
if (!Context.RegisteredStyles.Any())
{
return EnumerateFilesForRegisteredStyles(baseName, ext);
}
else
{
return Directory.EnumerateFiles(Path.GetDirectoryName(fileName), Path.GetFileName(baseName) + "*" + ext);
}
}

IEnumerable<string> EnumerateFilesForRegisteredStyles (string baseName, string ext)
{
foreach (var scaleTag in Image.SupportedScalesTags) {
var fn = baseName + scaleTag + ext;
if (File.Exists (fn))
yield return fn;
}
}

Expand Down