Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beb248c8bd |
No files matched your search
@@ -28,6 +28,15 @@ numeric core and does not move; the heading is the full version — corrected 20
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- **The documents in the app scroll further and smoothly** — the user guide, Help ▸ Limitations, About's documents, the
|
||||
Legal Gate and the update notes. A wheel notch moved them a fixed short step whatever the wheel or touchpad sent;
|
||||
it now moves the number of lines Windows is set to scroll (a screen if it is set to that), about twice as far by
|
||||
default, in proportion for a touchpad, and glides there unless Windows' animations are off. At the end of the update
|
||||
notes the wheel scrolls the window instead; Ctrl+wheel still zooms. A page is drawn once when it is opened, not two or
|
||||
three times, and going back to a page you have read in the same window is immediate.
|
||||
|
||||
### Security
|
||||
|
||||
- **Four itch.io downloads this project's documentation used as examples carry malware.** HELLO, HELLO WORLD!, A Doll's
|
||||
|
||||
+8
-1
@@ -66,7 +66,14 @@ WPF + **WPF UI (Wpf.Ui, Fluent)**. Shell = `ui:FluentWindow` with custom `ui:Tit
|
||||
> off** — a tag is shown as the text it is; **no image is fetched** — its description stands in; a node the renderer
|
||||
> does not know is shown as its own source text, and `MarkdownRendererTests` proves for every embedded document that
|
||||
> no word of its plain text is lost and no table is left as `|---|` source. The GPL's `LICENSE` is not Markdown: it is
|
||||
> shown as written, monospace. Colours and the font are theme resources (`16_WPFUI_SYNTAX` §FlowDocument). Links
|
||||
> shown as written, monospace. Colours and the font are theme resources (`16_WPFUI_SYNTAX` §FlowDocument).
|
||||
> **The wheel and the render, beta.21 (owner request 2026-10-13: "scrolling the documents is slow"):** a notch moves
|
||||
> Windows' *lines to scroll* at a browser's line (100/3 DIP; three lines = 100 DIP, scaled by the zoom; a delta in
|
||||
> proportion, so a touchpad's small deltas move a little; Windows' *one screen at a time* a screen) and eases there in
|
||||
> about 120 ms unless Windows' animations are off — WPF moved a fixed 48 DIP per message, whatever its delta. At its ends
|
||||
> the view leaves the wheel to what holds it (the update notes' dialog), and Ctrl+wheel stays the zoom. A page is
|
||||
> rendered once (`MarkdownView.Show`; three bindings changing ask for one render, ahead of layout), and a view keeps the
|
||||
> last 16 documents it rendered, so going back to a page costs its layout only (`MarkdownViewTests`). Links
|
||||
> follow `Markdown/MarkdownLinks`: http, https and mailto through `IUrlOpener`; `#section` scrolls to the heading
|
||||
> (GitHub's anchors); a relative path resolves against the document's place in the repository and opens in the App
|
||||
> when the window holds that page, on GitHub otherwise — **at this build's own source** (`Services/RepositoryLinks`:
|
||||
|
||||
@@ -250,6 +250,11 @@ On startup and on `ApplicationThemeManager.Changed`: for every live plot set fig
|
||||
A `ContentDialog` whose content should not scroll as a whole sets `ScrollViewer.VerticalScrollBarVisibility="Disabled"`
|
||||
on the dialog: its content row then has the window's height, and a `*` row inside it can hold a list that scrolls alone
|
||||
(`ImportReviewPrompt`).
|
||||
- [ ] **A `ScrollViewer` moves a FIXED 48 DIP per wheel message, whatever its delta** (`ScrollViewer._mouseWheelDelta`,
|
||||
read from .NET 10.0.12; measured on a `FlowDocumentScrollViewer`: deltas of −1, −15, −120 and −360 each moved 48). It
|
||||
ignores Windows' *lines to scroll*, and a precision touchpad's small deltas each jump the whole step — a long document
|
||||
read as slow and jerky while its layout cost about a millisecond a step. `Controls/MarkdownView` handles
|
||||
`PreviewMouseWheel` itself (beta.21): the delta in proportion at Windows' lines, eased, unhandled at its ends.
|
||||
- [ ] **ScottPlot 5 zooms on every wheel and never marks it handled.** Without `Charts/ChartWheel` a wheel over a chart
|
||||
zoomed it and scrolled the page at once; a plain wheel is the page's, Ctrl+wheel the chart's, for every plot that
|
||||
`ChartTheme.Attach` registers.
|
||||
|
||||
@@ -110,6 +110,8 @@ public partial class App : System.Windows.Application
|
||||
_host = BuildHost(_db, appearance, registered, closePolicy);
|
||||
await _host.StartAsync().ConfigureAwait(true);
|
||||
Log.Information("ui: started ({Version}), ledger {Ledger}", UiIdentity.Version, UiPaths.Database);
|
||||
// beta.21: tier 0 is software rendering (a VM without a GPU, Remote Desktop) - every scroll drawn on the CPU.
|
||||
Log.Information("ui: render tier {Tier} (2 = the GPU draws; 0 = software)", System.Windows.Media.RenderCapability.Tier >> 16);
|
||||
if (UiPaths.IsViewer)
|
||||
{
|
||||
Log.Warning("ui: a VIEWER over {Folder} (--data-dir, D52): no Agent is started or contacted, nothing on this PC is changed", UiPaths.DataDirectory);
|
||||
@@ -192,7 +194,8 @@ public partial class App : System.Windows.Application
|
||||
Log.Warning(ex, "diag: the hardware could not be read; its lines are n/a");
|
||||
}
|
||||
|
||||
string report = DiagReport.Build(UiIdentity.Version, UiPaths.DataDirectory, UiPaths.Logs, schema, values, new AgentLauncher().CanLaunch, now, hardware);
|
||||
string report = DiagReport.Build(UiIdentity.Version, UiPaths.DataDirectory, UiPaths.Logs, schema, values, new AgentLauncher().CanLaunch, now, hardware,
|
||||
System.Windows.Media.RenderCapability.Tier >> 16);
|
||||
string path = DiagReport.Write(UiPaths.Logs, report, now);
|
||||
await Console.Out.WriteLineAsync(string.Format(CultureInfo.CurrentCulture, Strings.Diag_Written_Format, path)).ConfigureAwait(true);
|
||||
Log.Information("ui: --diag written to {Path}", path);
|
||||
|
||||
@@ -97,9 +97,8 @@ public partial class DocumentBrowser : UserControl
|
||||
|
||||
private void ShowPage(DocumentPage? page)
|
||||
{
|
||||
View.DocumentPath = page?.Path;
|
||||
View.IsPlainText = page?.IsPlainText ?? false;
|
||||
View.MarkdownText = page?.Text ?? string.Empty;
|
||||
// One render, now (beta.21): the three properties one by one rendered the old text under the new path first.
|
||||
View.Show(page?.Text ?? string.Empty, page?.IsPlainText ?? false, page?.Path);
|
||||
AutomationProperties.SetName(View, page?.Title ?? string.Empty);
|
||||
PageChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Threading;
|
||||
using FrameLedger.App.Markdown;
|
||||
using FrameLedger.App.Services;
|
||||
|
||||
@@ -18,8 +21,32 @@ namespace FrameLedger.App.Controls;
|
||||
/// (<see cref="RepositoryLinkRequested"/>), which shows it when the App embeds it, and otherwise opens on GitHub at this
|
||||
/// build's source (<see cref="RepositoryLinks"/>); anything else is not followed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>The wheel (beta.21, owner request 2026-10-13: "scrolling the documents is slow").</b> WPF's scroll viewer moves a
|
||||
/// fixed 48 DIP per wheel message, whatever its delta — about two and a half lines of body text, Windows' "lines to
|
||||
/// scroll" ignored, and a precision touchpad's small deltas each jumping the whole step (measured: −1, −15, −120 and −360
|
||||
/// all moved 48). Layout costs about a millisecond a step, so the step was the problem, not drawing. The view now moves
|
||||
/// <see cref="WheelStep"/>: the delta in proportion, Windows' lines per notch at a browser's line (100/3 DIP), scaled by
|
||||
/// the zoom — and eases there over about 120 ms unless Windows' animations are off. At either end it leaves the wheel
|
||||
/// unhandled, so whatever holds the view (the update notes' dialog) scrolls instead. Ctrl+wheel stays the zoom.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>One render per page.</b> Each of the three properties rendered the whole document on its own, so a page change
|
||||
/// rendered the old text under the new path first, and the Legal Gate's three bindings rendered three times. Property
|
||||
/// changes now ask for one render, posted to the dispatcher ahead of layout; <see cref="Show"/> sets all three and renders
|
||||
/// at once; and a document this view has rendered is kept (<see cref="CacheCapacity"/>), so going back to a page costs
|
||||
/// its layout and nothing else.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class MarkdownView : FlowDocumentScrollViewer
|
||||
{
|
||||
/// <summary>A line of the wheel's step: Chromium scrolls 100 DIP for Windows' default three lines at 100%.</summary>
|
||||
internal const double WheelLineDip = 100.0 / 3.0;
|
||||
|
||||
/// <summary>How many rendered documents one view keeps (the user guide has twelve pages and Limitations).</summary>
|
||||
internal const int CacheCapacity = 16;
|
||||
|
||||
public static readonly DependencyProperty MarkdownTextProperty =
|
||||
DependencyProperty.Register(nameof(MarkdownText), typeof(string), typeof(MarkdownView), new PropertyMetadata(null, OnSourceChanged));
|
||||
|
||||
@@ -29,7 +56,18 @@ public sealed class MarkdownView : FlowDocumentScrollViewer
|
||||
public static readonly DependencyProperty DocumentPathProperty =
|
||||
DependencyProperty.Register(nameof(DocumentPath), typeof(string), typeof(MarkdownView), new PropertyMetadata(null, OnSourceChanged));
|
||||
|
||||
private readonly Dictionary<RenderKey, RenderedMarkdown> _cache = [];
|
||||
private readonly LinkedList<RenderKey> _recent = new();
|
||||
private IReadOnlyDictionary<string, Block> _anchors = new Dictionary<string, Block>(StringComparer.Ordinal);
|
||||
private RenderKey? _shown;
|
||||
private bool _batching;
|
||||
private DispatcherOperation? _pending;
|
||||
|
||||
private ScrollViewer? _scroller;
|
||||
private double _wheelTarget = double.NaN;
|
||||
private double _lastSetOffset = double.NaN;
|
||||
private TimeSpan _lastFrame;
|
||||
private bool _easing;
|
||||
|
||||
public MarkdownView()
|
||||
{
|
||||
@@ -38,7 +76,8 @@ public sealed class MarkdownView : FlowDocumentScrollViewer
|
||||
VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
Focusable = true;
|
||||
AddHandler(Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler(OnRequestNavigate));
|
||||
Rebuild();
|
||||
Unloaded += (_, _) => StopEasing();
|
||||
RenderNow();
|
||||
}
|
||||
|
||||
/// <summary>A link to another file of the repository; the host shows it and sets Handled, or it opens on GitHub.</summary>
|
||||
@@ -69,31 +108,226 @@ public sealed class MarkdownView : FlowDocumentScrollViewer
|
||||
public IUrlOpener UrlOpener { get; set; } = new ShellUrlOpener();
|
||||
|
||||
/// <summary>The headings this document can scroll to, by anchor.</summary>
|
||||
public IReadOnlyCollection<string> Anchors => [.. _anchors.Keys];
|
||||
public IReadOnlyCollection<string> Anchors
|
||||
{
|
||||
get
|
||||
{
|
||||
RenderIfPending();
|
||||
return [.. _anchors.Keys];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>How many documents this view has rendered from text — a cache hit is not one (for tests).</summary>
|
||||
internal int Renders { get; private set; }
|
||||
|
||||
/// <summary>Where the wheel is taking the view, or NaN when it is not easing it there (for tests).</summary>
|
||||
internal double ScrollTarget => _wheelTarget;
|
||||
|
||||
/// <summary>The template's scroll viewer, once the template is applied (for tests).</summary>
|
||||
internal ScrollViewer? Scroller => _scroller;
|
||||
|
||||
/// <summary>The modifier keys held, read when the wheel turns; a test gives its own rather than the real keyboard's.</summary>
|
||||
internal Func<ModifierKeys> CurrentModifiers { get; set; } = static () => Keyboard.Modifiers;
|
||||
|
||||
/// <summary>Windows' "lines to scroll" per notch (−1: a screen); a test gives its own.</summary>
|
||||
internal Func<int> WheelScrollLines { get; set; } = static () => SystemParameters.WheelScrollLines;
|
||||
|
||||
/// <summary>Whether the wheel eases to its target; off where Windows' animations are, and in tests.</summary>
|
||||
internal bool EaseWheel { get; set; } = SystemParameters.ClientAreaAnimation;
|
||||
|
||||
/// <summary>Shows a document: the three properties at once, rendered once, now.</summary>
|
||||
public void Show(string? text, bool isPlainText, string? path)
|
||||
{
|
||||
_batching = true;
|
||||
try
|
||||
{
|
||||
DocumentPath = path;
|
||||
IsPlainText = isPlainText;
|
||||
MarkdownText = text;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_batching = false;
|
||||
}
|
||||
|
||||
RenderNow();
|
||||
}
|
||||
|
||||
/// <summary>Brings the heading with <paramref name="anchor"/> into view; whether the document has it.</summary>
|
||||
public bool ScrollTo(string anchor)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(anchor);
|
||||
RenderIfPending();
|
||||
if (!_anchors.TryGetValue(anchor, out Block? block))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
StopEasing();
|
||||
block.BringIntoView();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((MarkdownView)d).Rebuild();
|
||||
|
||||
private void Rebuild()
|
||||
/// <summary>
|
||||
/// The distance one wheel message moves the view, in DIP (positive: down). <paramref name="delta"/> in proportion (120 is a
|
||||
/// notch); <paramref name="wheelScrollLines"/> lines per notch at <see cref="WheelLineDip"/>, or a screen
|
||||
/// (<paramref name="viewportHeight"/>) when Windows says −1; scaled by <paramref name="zoomPercent"/>.
|
||||
/// </summary>
|
||||
internal static double WheelStep(int delta, int wheelScrollLines, double viewportHeight, double zoomPercent)
|
||||
{
|
||||
string text = MarkdownText ?? string.Empty;
|
||||
RenderedMarkdown rendered = IsPlainText ? MarkdownRenderer.RenderPlainText(text) : MarkdownRenderer.Render(text, DocumentPath);
|
||||
double notches = delta / 120.0;
|
||||
double perNotch = wheelScrollLines < 0 ? viewportHeight : wheelScrollLines * WheelLineDip * zoomPercent / 100.0;
|
||||
return -notches * perNotch;
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
StopEasing();
|
||||
_scroller = GetTemplateChild("PART_ContentHost") as ScrollViewer;
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(e);
|
||||
base.OnPreviewMouseWheel(e);
|
||||
if (e.Handled || _scroller is not { } scroller || (CurrentModifiers() & ModifierKeys.Control) != ModifierKeys.None)
|
||||
{
|
||||
return; // Ctrl+wheel is the zoom
|
||||
}
|
||||
|
||||
double step = WheelStep(e.Delta, WheelScrollLines(), scroller.ViewportHeight, Zoom);
|
||||
if (step == 0 || double.IsNaN(step))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double from = double.IsNaN(_wheelTarget) ? scroller.VerticalOffset : _wheelTarget;
|
||||
double to = Math.Clamp(from + step, 0, scroller.ScrollableHeight);
|
||||
if (Math.Abs(to - scroller.VerticalOffset) < 0.5 && double.IsNaN(_wheelTarget))
|
||||
{
|
||||
return; // at the end it would move toward: the wheel is the host's
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
if (!EaseWheel)
|
||||
{
|
||||
scroller.ScrollToVerticalOffset(to);
|
||||
return;
|
||||
}
|
||||
|
||||
_wheelTarget = to;
|
||||
if (!_easing)
|
||||
{
|
||||
_easing = true;
|
||||
_lastFrame = TimeSpan.Zero;
|
||||
_lastSetOffset = scroller.VerticalOffset;
|
||||
CompositionTarget.Rendering += OnRendering;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((MarkdownView)d).RequestRender();
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD001:Avoid legacy thread switching APIs", Justification = "a WPF application has no JoinableTaskFactory; this posts to the view's own dispatcher from its own thread, at a priority ahead of layout, and never waits (ScrollBarHiding does the same)")]
|
||||
private void RequestRender()
|
||||
{
|
||||
if (_batching || _pending is not null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ahead of layout, after whatever is setting the other properties has set them.
|
||||
_pending = Dispatcher.InvokeAsync(RenderIfPending, DispatcherPriority.DataBind);
|
||||
}
|
||||
|
||||
private void RenderIfPending()
|
||||
{
|
||||
if (_pending is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RenderNow();
|
||||
}
|
||||
|
||||
private void RenderNow()
|
||||
{
|
||||
if (_pending is { } pending)
|
||||
{
|
||||
_ = pending.Abort();
|
||||
_pending = null;
|
||||
}
|
||||
|
||||
var key = new RenderKey(DocumentPath, IsPlainText, MarkdownText ?? string.Empty);
|
||||
if (_shown is { } shown && shown.Equals(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_cache.TryGetValue(key, out RenderedMarkdown? rendered))
|
||||
{
|
||||
rendered = key.IsPlainText ? MarkdownRenderer.RenderPlainText(key.Text) : MarkdownRenderer.Render(key.Text, key.Path);
|
||||
Renders++;
|
||||
_cache[key] = rendered;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = _recent.Remove(key);
|
||||
}
|
||||
|
||||
_ = _recent.AddFirst(key);
|
||||
while (_recent.Count > CacheCapacity && _recent.Last is { } oldest)
|
||||
{
|
||||
_ = _cache.Remove(oldest.Value);
|
||||
_recent.RemoveLast();
|
||||
}
|
||||
|
||||
StopEasing();
|
||||
_anchors = rendered.Anchors;
|
||||
_shown = key;
|
||||
Document = rendered.Document;
|
||||
}
|
||||
|
||||
private void OnRendering(object? sender, EventArgs e)
|
||||
{
|
||||
if (_scroller is not { } scroller || double.IsNaN(_wheelTarget))
|
||||
{
|
||||
StopEasing();
|
||||
return;
|
||||
}
|
||||
|
||||
// Something else moved the view since the last frame (the scroll bar, the keyboard, a link): it is theirs now.
|
||||
if (Math.Abs(scroller.VerticalOffset - _lastSetOffset) > 1)
|
||||
{
|
||||
StopEasing();
|
||||
return;
|
||||
}
|
||||
|
||||
TimeSpan now = (e as RenderingEventArgs)?.RenderingTime ?? TimeSpan.Zero;
|
||||
double elapsedMs = _lastFrame == TimeSpan.Zero ? 16 : Math.Clamp((now - _lastFrame).TotalMilliseconds, 1, 100);
|
||||
_lastFrame = now;
|
||||
|
||||
// Exponential ease-out: about 95% of the way in 120 ms, however many notches have been added on the way.
|
||||
double remaining = _wheelTarget - scroller.VerticalOffset;
|
||||
double next = Math.Abs(remaining) < 0.5 ? _wheelTarget : scroller.VerticalOffset + (remaining * (1 - Math.Exp(-elapsedMs / 40.0)));
|
||||
scroller.ScrollToVerticalOffset(next);
|
||||
_lastSetOffset = next;
|
||||
if (next == _wheelTarget)
|
||||
{
|
||||
StopEasing();
|
||||
}
|
||||
}
|
||||
|
||||
private void StopEasing()
|
||||
{
|
||||
_wheelTarget = double.NaN;
|
||||
if (_easing)
|
||||
{
|
||||
_easing = false;
|
||||
CompositionTarget.Rendering -= OnRendering;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
@@ -116,4 +350,7 @@ public sealed class MarkdownView : FlowDocumentScrollViewer
|
||||
_ = ScrollTo(anchor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>What a rendered document depends on: theme and language are not in it — its colours are resource references.</summary>
|
||||
private readonly record struct RenderKey(string? Path, bool IsPlainText, string Text);
|
||||
}
|
||||
@@ -233,7 +233,7 @@ public static class MarkdownRenderer
|
||||
int columns = Math.Max(table.ColumnDefinitions.Count, rows.Select(static r => r.Count).DefaultIfEmpty(0).Max());
|
||||
for (int i = 0; i < columns; i++)
|
||||
{
|
||||
wpf.Columns.Add(new TableColumn { Width = GridLength.Auto });
|
||||
wpf.Columns.Add(new TableColumn()); // WPF's default width is already Auto (read by reflection, beta.21)
|
||||
}
|
||||
|
||||
var group = new TableRowGroup();
|
||||
|
||||
@@ -26,7 +26,8 @@ public static class DiagReport
|
||||
}
|
||||
|
||||
/// <summary>The report text. <paramref name="settings"/> is every registry key's effective value; <paramref name="schemaVersion"/> null when the ledger could not be opened.</summary>
|
||||
public static string Build(string appVersion, string dataDirectory, string logsDirectory, long? schemaVersion, IReadOnlyDictionary<string, string> settings, bool agentBesideApp, DateTimeOffset now, HardwareSnapshot? hardware = null)
|
||||
public static string Build(string appVersion, string dataDirectory, string logsDirectory, long? schemaVersion, IReadOnlyDictionary<string, string> settings, bool agentBesideApp, DateTimeOffset now, HardwareSnapshot? hardware = null,
|
||||
int? renderTier = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
var sb = new StringBuilder();
|
||||
@@ -48,6 +49,8 @@ public static class DiagReport
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $"gpu_driver: {hardware?.GpuDriver ?? "n/a"}");
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $"ram_gb: {(hardware?.RamGb is double gb ? gb.ToString("0.#", CultureInfo.InvariantCulture) : "n/a")}");
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $"display: {hardware?.DisplayRes ?? "n/a"}{(hardware?.DisplayHz is double hz ? " @ " + hz.ToString("0.#", CultureInfo.InvariantCulture) + " Hz" : string.Empty)}");
|
||||
// beta.21: WPF's rendering tier — 0 is software rendering, where every scroll of a document is drawn on the CPU.
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $"render_tier: {(renderTier is int tier ? tier.ToString(CultureInfo.InvariantCulture) : "n/a")}");
|
||||
sb.AppendLine("settings:");
|
||||
foreach (SettingDefinition definition in SettingsRegistry.All)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,9 @@ public sealed class DiagReportTests
|
||||
}
|
||||
|
||||
report.Should().Contain(" capture.min_session_s = 30", "a key with no row reports its default");
|
||||
report.Should().Contain("render_tier: n/a", "no tier given");
|
||||
DiagReport.Build("1.2.3", @"C:\data", @"C:\data\logs", 2, values, agentBesideApp: true, now, renderTier: 0)
|
||||
.Should().Contain("render_tier: 0", "beta.21: software rendering, where every scroll is drawn on the CPU, is named");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using FluentAssertions;
|
||||
using FrameLedger.App.Controls;
|
||||
using Xunit;
|
||||
|
||||
namespace FrameLedger.App.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// beta.21 (owner request 2026-10-13: "scrolling the documents in the app is slow"): the wheel moves a document by Windows'
|
||||
/// lines at a browser's line instead of WPF's fixed 48 DIP, in proportion to the delta, and leaves its ends to the host; a
|
||||
/// page is rendered once, and a page shown before is not rendered again.
|
||||
/// </summary>
|
||||
public sealed class MarkdownViewTests
|
||||
{
|
||||
private static readonly string _longText = string.Join("\n\n", Enumerable.Range(1, 400).Select(static i => "Paragraph " + i + ": a few words that wrap."));
|
||||
|
||||
[Fact]
|
||||
public void TheWheelStepFollowsTheDeltaWindowsLinesAndTheZoom()
|
||||
{
|
||||
MarkdownView.WheelStep(-120, 3, 600, 100).Should().BeApproximately(100, 1e-9, "three lines at a browser's line, downwards");
|
||||
MarkdownView.WheelStep(120, 3, 600, 100).Should().BeApproximately(-100, 1e-9);
|
||||
MarkdownView.WheelStep(-15, 3, 600, 100).Should().BeApproximately(12.5, 1e-9, "a touchpad's small delta moves in proportion");
|
||||
MarkdownView.WheelStep(-120, 3, 600, 200).Should().BeApproximately(200, 1e-9, "zoomed in, a line is taller");
|
||||
MarkdownView.WheelStep(-120, -1, 600, 100).Should().BeApproximately(600, 1e-9, "Windows' \"one screen at a time\"");
|
||||
MarkdownView.WheelStep(-120, 0, 600, 100).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TheWheelMovesTheDocumentByItsStepAndLeavesItsEndsToTheHost()
|
||||
{
|
||||
(double notch, double touch, bool atEnd, bool withCtrl) = await PagesLoadTests.OnStaAsync(static () =>
|
||||
{
|
||||
var view = new MarkdownView { EaseWheel = false, WheelScrollLines = static () => 3, CurrentModifiers = static () => ModifierKeys.None };
|
||||
view.Show(_longText, isPlainText: false, path: "LIMITATIONS.md");
|
||||
Layout(view);
|
||||
ScrollViewer scroller = view.Scroller ?? throw new InvalidOperationException("the template has no PART_ContentHost");
|
||||
scroller.ScrollableHeight.Should().BeGreaterThan(1000, "the document is longer than its view");
|
||||
|
||||
Wheel(view, -120).Should().BeTrue();
|
||||
Layout(view);
|
||||
double afterNotch = scroller.VerticalOffset;
|
||||
|
||||
Wheel(view, -15).Should().BeTrue();
|
||||
Layout(view);
|
||||
double afterTouch = scroller.VerticalOffset;
|
||||
|
||||
scroller.ScrollToVerticalOffset(scroller.ScrollableHeight);
|
||||
Layout(view);
|
||||
bool handledAtEnd = Wheel(view, -120);
|
||||
|
||||
scroller.ScrollToVerticalOffset(0);
|
||||
Layout(view);
|
||||
view.CurrentModifiers = static () => ModifierKeys.Control;
|
||||
bool handledWithCtrl = Wheel(view, -120);
|
||||
return (afterNotch, afterTouch, handledAtEnd, handledWithCtrl);
|
||||
});
|
||||
|
||||
notch.Should().BeApproximately(100, 0.5, "one notch is three lines of 100/3 DIP, not WPF's fixed 48");
|
||||
touch.Should().BeApproximately(112.5, 0.5, "a delta of 15 is an eighth of a notch");
|
||||
atEnd.Should().BeFalse("at the end the wheel is the host's — the update notes' dialog scrolls instead");
|
||||
withCtrl.Should().BeFalse("Ctrl+wheel is the zoom's, never the scroll's");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EasingAddsEveryNotchToTheTargetAndANewPageStopsIt()
|
||||
{
|
||||
(double first, double second, double afterShow) = await PagesLoadTests.OnStaAsync(static () =>
|
||||
{
|
||||
var view = new MarkdownView { EaseWheel = true, WheelScrollLines = static () => 3, CurrentModifiers = static () => ModifierKeys.None };
|
||||
view.Show(_longText, isPlainText: false, path: "LIMITATIONS.md");
|
||||
Layout(view);
|
||||
Wheel(view, -120).Should().BeTrue();
|
||||
double target1 = view.ScrollTarget;
|
||||
Wheel(view, -120).Should().BeTrue();
|
||||
double target2 = view.ScrollTarget;
|
||||
view.Show("# Another page", isPlainText: false, path: "guide/README.md");
|
||||
return (target1, target2, view.ScrollTarget);
|
||||
});
|
||||
|
||||
first.Should().BeApproximately(100, 0.5);
|
||||
second.Should().BeApproximately(200, 0.5, "a notch turned while easing adds to where the view is going, not to where it is");
|
||||
double.IsNaN(afterShow).Should().BeTrue("a new page ends the easing");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task APageIsRenderedOnceAndAPageShownBeforeIsNotRenderedAgain()
|
||||
{
|
||||
(int one, int two, int back, int evicted) = await PagesLoadTests.OnStaAsync(static () =>
|
||||
{
|
||||
var view = new MarkdownView();
|
||||
int start = view.Renders; // the constructor's empty document
|
||||
view.Show("# One\n\ntext", isPlainText: false, path: "guide/a.md");
|
||||
int afterOne = view.Renders - start;
|
||||
view.Show("# Two\n\ntext", isPlainText: false, path: "guide/b.md");
|
||||
int afterTwo = view.Renders - start;
|
||||
view.Show("# One\n\ntext", isPlainText: false, path: "guide/a.md");
|
||||
int afterBack = view.Renders - start;
|
||||
|
||||
for (int i = 0; i < MarkdownView.CacheCapacity; i++)
|
||||
{
|
||||
view.Show("# Page " + i, isPlainText: false, path: "guide/p" + i + ".md");
|
||||
}
|
||||
|
||||
int beforeEvicted = view.Renders;
|
||||
view.Show("# Two\n\ntext", isPlainText: false, path: "guide/b.md");
|
||||
return (afterOne, afterTwo, afterBack, view.Renders - beforeEvicted);
|
||||
});
|
||||
|
||||
one.Should().Be(1, "Show sets the three properties and renders once");
|
||||
two.Should().Be(2);
|
||||
back.Should().Be(2, "a page this view has rendered is kept");
|
||||
evicted.Should().Be(1, "past the cache's capacity the oldest page is rendered again");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PropertiesSetOneByOneAreRenderedOnceAheadOfLayout()
|
||||
{
|
||||
(int beforePump, int afterPump, bool hasAnchor) = await PagesLoadTests.OnStaAsync(static () =>
|
||||
{
|
||||
var view = new MarkdownView();
|
||||
int start = view.Renders;
|
||||
view.DocumentPath = "guide/a.md";
|
||||
view.IsPlainText = false;
|
||||
view.MarkdownText = "# Heading\n\ntext";
|
||||
int before = view.Renders - start;
|
||||
Visuals.Pump();
|
||||
int after = view.Renders - start;
|
||||
return (before, after, view.Anchors.Count > 0);
|
||||
});
|
||||
|
||||
beforePump.Should().Be(0, "a binding's change asks for a render; it does not render the half-set page");
|
||||
afterPump.Should().Be(1, "three changes, one render");
|
||||
hasAnchor.Should().BeTrue();
|
||||
}
|
||||
|
||||
private static void Layout(FrameworkElement element)
|
||||
{
|
||||
element.Measure(new Size(700, 600));
|
||||
element.Arrange(new Rect(0, 0, 700, 600));
|
||||
element.UpdateLayout();
|
||||
}
|
||||
|
||||
private static bool Wheel(UIElement over, int delta)
|
||||
{
|
||||
var wheel = new MouseWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, delta) { RoutedEvent = UIElement.PreviewMouseWheelEvent };
|
||||
over.RaiseEvent(wheel);
|
||||
return wheel.Handled;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user