Files
LanMountainDesktop/LanMontainDesktop/Views/Components/ExtendedWeatherWidget.axaml.cs
lincube 478ed115a1 0.2.5
课表组件、天气组件全面升级。
2026-03-03 15:09:49 +08:00

49 lines
1.6 KiB
C#

using System;
using Avalonia.Controls;
using LanMontainDesktop.Services;
namespace LanMontainDesktop.Views.Components;
public partial class ExtendedWeatherWidget : UserControl, IDesktopComponentWidget, ITimeZoneAwareComponentWidget, IWeatherInfoAwareComponentWidget
{
private TimeZoneService? _timeZoneService;
private IWeatherInfoService? _weatherInfoService;
private double _currentCellSize = 48;
public ExtendedWeatherWidget()
{
InitializeComponent();
ApplyCellSize(_currentCellSize);
}
public void ApplyCellSize(double cellSize)
{
_currentCellSize = Math.Max(1, cellSize);
var metrics = HyperOS3WeatherTheme.ResolveMetrics(HyperOS3WeatherWidgetKind.Extended4x4);
ContainerGrid.RowSpacing = Math.Clamp(_currentCellSize * metrics.SectionGap * 0.22, 6, 18);
HourlyHost.ApplyCellSize(_currentCellSize);
MultiDayHost.ApplyCellSize(_currentCellSize);
}
public void SetTimeZoneService(TimeZoneService timeZoneService)
{
_timeZoneService = timeZoneService;
HourlyHost.SetTimeZoneService(timeZoneService);
MultiDayHost.SetTimeZoneService(timeZoneService);
}
public void ClearTimeZoneService()
{
HourlyHost.ClearTimeZoneService();
MultiDayHost.ClearTimeZoneService();
_timeZoneService = null;
}
public void SetWeatherInfoService(IWeatherInfoService weatherInfoService)
{
_weatherInfoService = weatherInfoService;
HourlyHost.SetWeatherInfoService(weatherInfoService);
MultiDayHost.SetWeatherInfoService(weatherInfoService);
}
}