feat(ui-visuals): add retained-mode drawing base and chart data types
DrawingElement resolves theme brushes by key (re-resolved on theme swap via a resource-reference probe), caches frozen pens per theme and DPI, lays out text in the UI font and offers an overlay layer redrawn without touching the static content. HoverReadout is a mouse-following tooltip for values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+409
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
namespace Titano.Ui.Visuals;
|
||||
|
||||
/// <summary>
|
||||
/// A tooltip (same style as every other) that opens at once and follows the mouse to read out the value under
|
||||
/// the cursor. While it shows, the owner's own tooltip (which describes the action) is suppressed.
|
||||
/// </summary>
|
||||
public sealed class HoverReadout(FrameworkElement owner)
|
||||
{
|
||||
private ToolTip? _tip;
|
||||
private object? _savedEnabled;
|
||||
|
||||
public bool IsOpen => _tip?.IsOpen == true;
|
||||
|
||||
/// <summary>Shows <paramref name="text"/> next to <paramref name="position"/> (owner coordinates); empty text hides the readout.</summary>
|
||||
public void Show(string? text, Point position)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
_tip ??= new ToolTip
|
||||
{
|
||||
Placement = PlacementMode.Relative,
|
||||
PlacementTarget = owner,
|
||||
IsHitTestVisible = false,
|
||||
Focusable = false,
|
||||
};
|
||||
if (!Equals(_tip.Content, text)) _tip.Content = text;
|
||||
// Below-right of the cursor so the popup never sits under the mouse (which would end the hover).
|
||||
_tip.HorizontalOffset = position.X + 12;
|
||||
_tip.VerticalOffset = position.Y + 18;
|
||||
if (_tip.IsOpen) return;
|
||||
_savedEnabled = owner.ReadLocalValue(ToolTipService.IsEnabledProperty);
|
||||
ToolTipService.SetIsEnabled(owner, false);
|
||||
_tip.IsOpen = true;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (_tip is not { IsOpen: true }) return;
|
||||
_tip.IsOpen = false;
|
||||
if (_savedEnabled is null || _savedEnabled == DependencyProperty.UnsetValue) owner.ClearValue(ToolTipService.IsEnabledProperty);
|
||||
else owner.SetValue(ToolTipService.IsEnabledProperty, _savedEnabled);
|
||||
_savedEnabled = null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user