This commit is contained in:
2026-06-08 10:37:00 -05:00
parent 739b2be4c2
commit 193de6059e
19 changed files with 678 additions and 157 deletions
@@ -0,0 +1,18 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Copyright (C) LibreHardwareMonitor and Contributors.
using System;
namespace LibreHardwareMonitor.Windows.WinUI.ViewModels;
[Flags]
internal enum SensorDisplayColumn
{
None = 0,
Sensor = 1,
Value = 2,
Min = 4,
Max = 8,
All = Sensor | Value | Min | Max
}
@@ -41,6 +41,8 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
_settings = settings;
}
internal event EventHandler<SensorDisplayColumn>? DisplayColumnsChanged;
public ObservableCollection<SensorTreeItemViewModel> Children { get; } = [];
public bool CanHide => Sensor != null;
@@ -151,6 +153,9 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
}
set
{
if (Text == value)
return;
if (Sensor != null)
Sensor.Name = value;
else if (Hardware != null)
@@ -159,6 +164,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
_text = value;
OnPropertyChanged();
OnDisplayColumnsChanged(SensorDisplayColumn.Sensor);
}
}
@@ -267,11 +273,14 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
// actually changed. Unconditionally notifying all four for every item on every update tick made the native
// binding engine re-marshal unchanged values across the boundary continuously — most sensors don't change each
// tick, so this cuts the per-tick interop churn (and its retained wrappers) by a large factor.
SensorDisplayColumn changedColumns = SensorDisplayColumn.None;
string value = Value;
if (value != _lastValue)
{
_lastValue = value;
OnPropertyChanged(nameof(Value));
changedColumns |= SensorDisplayColumn.Value;
}
string min = Min;
@@ -279,6 +288,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
{
_lastMin = min;
OnPropertyChanged(nameof(Min));
changedColumns |= SensorDisplayColumn.Min;
}
string max = Max;
@@ -286,6 +296,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
{
_lastMax = max;
OnPropertyChanged(nameof(Max));
changedColumns |= SensorDisplayColumn.Max;
}
string toolTip = ToolTip;
@@ -295,6 +306,8 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
OnPropertyChanged(nameof(ToolTip));
}
OnDisplayColumnsChanged(changedColumns);
foreach (SensorTreeItemViewModel child in Children)
child.RefreshValues();
}
@@ -376,6 +389,12 @@ public sealed class SensorTreeItemViewModel : ViewModelBase
return changed;
}
private void OnDisplayColumnsChanged(SensorDisplayColumn columns)
{
if (columns != SensorDisplayColumn.None)
DisplayColumnsChanged?.Invoke(this, columns);
}
private void UpdateVisibilityState()
{
bool visible = Kind switch