Files
Chronos/src/Titano.Ui/Visuals/HoverReadout.cs
T
Claude 3f8464aabc fix(ui): toasts render; RTL-aware icons, charts and media; keyboard and screen-reader support in the kit
- ToastHost gets its template (nothing drew before); toasts are announced, pause while hovered or focused,
  Esc dismisses the focused one, the action closes it, FocusNewest brings the keyboard to them.
- Windows take the UI language's direction when created and follow every switch.
- Icons mirror only when the glyph is directional (IconData.IsDirectional, Bidi.IsDirectional override);
  the brand mark never mirrors; icons centre in stretched slots (ComboBox chevron).
- Card photos, scrub position, preview surface and shot data, mono templates, paths are left-to-right islands;
  the preview tool row follows the layout direction.
- Chart words (categories, legends, summaries) read in the UI direction and legends start on its side.
- Automation peers: charts as named images, filmstrip as a slider, curve editor value, preview image,
  split button, AutoSlider group; localized names for caption, reset, remove, dismiss and drop-down buttons.
- Focus visible on list and table rows and the preview; curve editor fully operable by keyboard.
- Rail item collapsed layout fixed; job bar trims its text only once the bar is at its minimum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 17:22:42 +00:00

67 lines
2.6 KiB
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Titano.Ui.Controls;
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. The text reads in
/// the UI language's direction unless the caller pins a numeric readout left to right.
/// </summary>
public sealed class HoverReadout(FrameworkElement owner)
{
private ToolTip? _tip;
private TextBlock? _text;
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. <paramref name="direction"/> defaults to the UI language's.
/// </summary>
public void Show(string? text, Point position, FlowDirection? direction = null)
{
if (string.IsNullOrEmpty(text))
{
Hide();
return;
}
if (_tip is null)
{
// The tip keeps the owner's direction so its placement offsets stay the owner's; only the text inside reads
// right to left. The content is explicit, so the tooltip style's text settings are repeated here.
_text = new TextBlock { TextWrapping = TextWrapping.Wrap, LineHeight = 16 };
_tip = new ToolTip
{
Placement = PlacementMode.Relative,
PlacementTarget = owner,
IsHitTestVisible = false,
Focusable = false,
FlowDirection = owner.FlowDirection,
Content = _text,
};
}
_text!.FlowDirection = direction ?? Bidi.UiDirection;
if (_text.Text != text) _text.Text = 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;
}
}