WIP: GUI
静态分析没有问题了。但是一尝试扫描文件夹就炸。怀疑是权限问题,但不确定。
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace GUI.Converters;
|
||||
|
||||
public class DurationFormatConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double duration) return "--:--";
|
||||
var ts = TimeSpan.FromSeconds(duration);
|
||||
if (ts.TotalHours >= 1)
|
||||
return ts.ToString(@"h\:mm\:ss\.ff");
|
||||
return ts.ToString(@"m\:ss\.ff");
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class SampleRateFormatConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double rate) return "--";
|
||||
return $"{rate / 1000.0:F1}k";
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class ChannelsFormatConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
int ch when ch == 1 => "Mono",
|
||||
int ch when ch == 2 => "Stereo",
|
||||
null => "--",
|
||||
int ch => $"{ch}ch",
|
||||
_ => "--"
|
||||
};
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class RatingStarsConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not uint rating || rating == 0) return "☆☆☆☆☆";
|
||||
return new string('★', (int)rating) + new string('☆', 5 - (int)rating);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class DurationToSliderMaxConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double duration) return 1.0;
|
||||
return Math.Ceiling(duration);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class PositionFormatConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double pos) return "0:00";
|
||||
var ts = TimeSpan.FromSeconds(pos);
|
||||
return ts.ToString(@"m\:ss");
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class InverseBoolConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool b) return !b;
|
||||
return true;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool b) return !b;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ValueConverters
|
||||
{
|
||||
public static readonly IValueConverter DurationFormat = new DurationFormatConverter();
|
||||
public static readonly IValueConverter SampleRateFormat = new SampleRateFormatConverter();
|
||||
public static readonly IValueConverter ChannelsFormat = new ChannelsFormatConverter();
|
||||
public static readonly IValueConverter RatingStars = new RatingStarsConverter();
|
||||
public static readonly IValueConverter DurationToSliderMax = new DurationToSliderMaxConverter();
|
||||
public static readonly IValueConverter PositionFormat = new PositionFormatConverter();
|
||||
public static readonly IValueConverter InverseBool = new InverseBoolConverter();
|
||||
}
|
||||
Reference in New Issue
Block a user