mirror of
https://github.com/waynebian01/Shigure.git
synced 2026-09-03 07:15:24 +08:00
- Updated color definitions in UiTheme.cs for improved UI aesthetics. - Introduced ButtonKind enum for better button styling options. - Added CreateButton method to streamline button creation with different styles. - Improved item height calculations in various controls for better layout. - Implemented ListColumn and ListColumnLayoutState for dynamic ListView column management. - Added FitListViewColumns method to ensure ListView columns adjust properly to available space. - Created UiCardPanel class for rounded card-like UI elements with custom painting.
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System.Text.Json;
|
|
|
|
namespace Shigure;
|
|
|
|
internal static class UiCacheStore
|
|
{
|
|
private const string CacheFolderName = "cache";
|
|
private const string CacheFileName = "window-state.json";
|
|
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
|
|
|
|
private static string CacheDirectory => Path.Combine(AppPaths.BaseDirectory, CacheFolderName);
|
|
private static string CacheFilePath => Path.Combine(CacheDirectory, CacheFileName);
|
|
|
|
public static UiCacheState Load()
|
|
{
|
|
try
|
|
{
|
|
if (!File.Exists(CacheFilePath))
|
|
{
|
|
return new UiCacheState();
|
|
}
|
|
|
|
var json = File.ReadAllText(CacheFilePath);
|
|
return JsonSerializer.Deserialize<UiCacheState>(json) ?? new UiCacheState();
|
|
}
|
|
catch
|
|
{
|
|
return new UiCacheState();
|
|
}
|
|
}
|
|
|
|
public static void Save(UiCacheState state)
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(CacheDirectory);
|
|
var json = JsonSerializer.Serialize(state, JsonOptions);
|
|
File.WriteAllText(CacheFilePath, json);
|
|
}
|
|
catch
|
|
{
|
|
// 忽略缓存写入异常,避免影响主流程。
|
|
}
|
|
}
|
|
|
|
public static bool IsBoundsVisible(Rectangle bounds)
|
|
{
|
|
if (bounds.Width <= 0 || bounds.Height <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(bounds));
|
|
}
|
|
}
|
|
|
|
internal sealed class UiCacheState
|
|
{
|
|
public WindowLocation? MainWindowLocation { get; set; }
|
|
public WindowBounds? MainWindowBounds { get; set; }
|
|
public WindowBounds? SettingsWindowBounds { get; set; }
|
|
public string? SelectedSettingsPage { get; set; }
|
|
public string? ToggleKey { get; set; }
|
|
public string? SelectedModuleId { get; set; }
|
|
public Dictionary<string, int>? ModuleRulesGridColumns { get; set; }
|
|
}
|
|
|
|
internal sealed class WindowLocation
|
|
{
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
}
|
|
|
|
internal sealed class WindowBounds
|
|
{
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
public int Width { get; set; }
|
|
public int Height { get; set; }
|
|
}
|