Extract PlotView control from MainWindow

Move ~460 lines of imperative Canvas plot rendering (draw helpers, value/time axes, zoom state, context flyout, wheel handler, color theming, and the PlotBounds/PlotAxisLayout/PlotSeriesSample records) out of MainWindow into a new Controls/PlotView : Grid that owns its own Canvas. PlotWindow now hosts a PlotView instead of a raw Canvas; the shared rendering path collapses to PlotView.Redraw().

MainWindow shrinks from 2014 to 1445 lines; the inline plot pane and the windowed plot now share a single code path. Public API on PlotView: Redraw(), Clear(), ResetZoom(), ApplyTheme(AppThemeMode).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-06-02 11:51:46 -05:00
co-authored by Copilot
parent ad16c9f3a4
commit 888c2cd852
3 changed files with 682 additions and 610 deletions
@@ -3,13 +3,12 @@
// Copyright (C) LibreHardwareMonitor and Contributors.
using System;
using LibreHardwareMonitor.Windows.WinUI.Controls;
using LibreHardwareMonitor.Windows.WinUI.Services;
using LibreHardwareMonitor.Windows.WinUI.ViewModels;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Windows.Graphics;
using WinRT.Interop;
@@ -19,10 +18,10 @@ public sealed class PlotWindow : Window
{
private readonly AppSettings _settings;
private readonly AppWindow _appWindow;
private readonly Grid _root;
private readonly PlotView _plotView;
private bool _closingFromOwner;
public PlotWindow(AppSettings settings)
internal PlotWindow(AppSettings settings, MainWindowViewModel viewModel)
{
_settings = settings;
@@ -30,36 +29,23 @@ public sealed class PlotWindow : Window
_appWindow = AppWindow.GetFromWindowId(Win32Interop.GetWindowIdFromWindow(hwnd));
_appWindow.Title = "Sensor Plot";
_root = new Grid();
PlotCanvas = new Canvas
{
MinWidth = 320,
MinHeight = 220,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch
};
PlotCanvas.SizeChanged += (_, _) => PlotSizeChanged?.Invoke(this, EventArgs.Empty);
_root.Children.Add(PlotCanvas);
Content = _root;
_plotView = new PlotView(viewModel);
Content = _plotView;
RestoreBounds();
Closed += PlotWindow_Closed;
}
public event EventHandler? PlotSizeChanged;
public event EventHandler? UserClosed;
public Canvas PlotCanvas { get; }
public void ApplyTheme(AppThemeMode themeMode)
{
_root.RequestedTheme = themeMode switch
{
AppThemeMode.Light => ElementTheme.Light,
AppThemeMode.Dark or AppThemeMode.Black => ElementTheme.Dark,
_ => ElementTheme.Default
};
_plotView.ApplyTheme(themeMode);
}
public void RedrawPlot()
{
_plotView.Redraw();
}
public void CloseFromOwner()