Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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