Browse Source

Fix bottom-of-Options content unreachable at max scroll

The trailing HeaderedContentControl in the Display panel (Other -> Sort
results by fitness) sat 15 px below the ScrollViewer.Extent's reported
height: the outer StackPanel's measure under-counted that last child's
inner content, so MaxYOffset never grew enough to scroll the checkbox
into view. The Reset-to-defaults border below the ScrollViewer covered
the gap visually, making the checkbox look obscured.

ScrollViewer.Padding alone can't compensate because Avalonia 12's
Simple-theme ScrollContentPresenter collapses Padding on the axis the
scrollbar lives on -- the horizontal 6 px stuck, the vertical 6 px was
dropped. Wrapping the content in a Border with explicit Padding makes
the padding part of the StackPanel's measured extent, and the last
child becomes reachable. Applied to both panels that use a top-level
StackPanel under a ScrollViewer; Misc is unaffected (no ScrollViewer,
two checkboxes never overflow).

The new OptionsPageScrollReachTests.Last_Item_In_Display_Panel_Is_-
Reachable_At_Max_Scroll opens the Options tab, scrolls the Display
panel to ScrollViewer.Extent.Height, and asserts the "Sort results by
fitness" CheckBox's rendered bottom sits at or above the Reset border's
top in window-coordinate space.

Assisted-by: Claude:claude-opus-4-7:Claude Code
pull/3755/head
Siegfried Pammer 1 month ago
parent
commit
2e9f0504af
  1. 108
      ILSpy.Tests/Options/OptionsPageScrollReachTests.cs
  2. 43
      ILSpy/Options/DecompilerSettingsPanel.axaml
  3. 13
      ILSpy/Options/DisplaySettingsPanel.axaml

108
ILSpy.Tests/Options/OptionsPageScrollReachTests.cs

@ -0,0 +1,108 @@ @@ -0,0 +1,108 @@
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Headless.NUnit;
using Avalonia.Threading;
using Avalonia.VisualTree;
using AwesomeAssertions;
using ICSharpCode.ILSpy.Properties;
using ILSpy.AppEnv;
using ILSpy.Commands;
using ILSpy.Docking;
using ILSpy.Options;
using ILSpy.ViewModels;
using ILSpy.Views;
using NUnit.Framework;
namespace ICSharpCode.ILSpy.Tests;
[TestFixture]
public class OptionsPageScrollReachTests
{
[AvaloniaTest]
public void Last_Item_In_Display_Panel_Is_Reachable_At_Max_Scroll()
{
// Regression for the "Reset-to-defaults border obscures last setting" bug:
// before the fix, the outer StackPanel's measured DesiredHeight didn't include
// the trailing HeaderedContentControl's inner content (the "Sort results by
// fitness" checkbox), so ScrollViewer.Extent was short by ~30 pixels and the
// checkbox couldn't be scrolled into view. Padding on the inner Border (rather
// than the ScrollViewer, where vertical padding is collapsed) forces the
// measure pass to include all children plus breathing room.
var window = AppComposition.Current.GetExport<MainWindow>();
window.Width = 900;
window.Height = 600;
window.Show();
Dispatcher.UIThread.RunJobs();
var registry = AppComposition.Current.GetExport<MainMenuCommandRegistry>();
var command = registry.Commands
.Single(c => c.Metadata.Header == nameof(Resources._Options))
.CreateExport().Value;
command.Execute(null);
Dispatcher.UIThread.RunJobs();
var view = window.GetVisualDescendants().OfType<OptionsPageView>().Single();
var model = (OptionsPageModel)((ContentTabPage)((MainWindowViewModel)window.DataContext!)
.DockWorkspace.Documents!.VisibleDockables!
.OfType<ContentTabPage>().Single(t => t.Content is OptionsPageModel)).Content!;
model.SelectedPage = model.Pages.OfType<DisplaySettingsViewModel>().Single();
Dispatcher.UIThread.RunJobs();
// Each panel now declares its own ScrollViewer (so per-tab scroll offset is
// independent), so the visual tree may contain multiple ScrollViewer instances
// — one per panel that's been materialized at least once. Pick the visible one.
var scrollViewer = view.GetVisualDescendants().OfType<ScrollViewer>()
.First(sv => sv.IsEffectivelyVisible && sv.Bounds.Height > 0);
scrollViewer.Offset = new Vector(0, scrollViewer.Extent.Height);
Dispatcher.UIThread.RunJobs();
// The "Sort results by fitness" checkbox sits inside the last HeaderedContentControl
// of the Display panel. After scrolling to max, its rendered bottom edge in
// window-coordinate space must sit at or above the Reset-to-defaults border's top.
// Scope the search inside the visible ScrollViewer in case other panels materialized
// a stale copy of the same checkbox label.
var sortCheckbox = scrollViewer.GetVisualDescendants().OfType<CheckBox>()
.FirstOrDefault(cb => cb.Content?.ToString() == Resources.SortResultsFitness);
sortCheckbox.Should().NotBeNull(
"the Display panel must expose a 'Sort results by fitness' checkbox; if this fails the "
+ "panel structure changed and the test needs updating, not just the assertion below");
var resetBorder = view.GetVisualDescendants().OfType<Border>()
.Single(b => b.GetVisualDescendants().OfType<Button>()
.Any(btn => btn.Content?.ToString() == Resources.ResetToDefaults));
var checkboxBottom = sortCheckbox!.TranslatePoint(
new Point(0, sortCheckbox.Bounds.Height), window)!.Value.Y;
var resetTop = resetBorder.TranslatePoint(new Point(0, 0), window)!.Value.Y;
checkboxBottom.Should().BeLessThanOrEqualTo(resetTop,
$"the last checkbox's bottom ({checkboxBottom}) must not extend below the Reset "
+ $"border's top ({resetTop}) when scrolled to max; otherwise the Reset row visually "
+ "obscures it. Indicates either ScrollViewer.Extent under-measures the StackPanel "
+ "content or the ContentPresenter under-allocates the TabControl's vertical room.");
}
}

43
ILSpy/Options/DecompilerSettingsPanel.axaml

@ -6,23 +6,30 @@ @@ -6,23 +6,30 @@
mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="500"
x:Class="ILSpy.Options.Panels.DecompilerSettingsPanel"
x:DataType="vm:DecompilerSettingsViewModel">
<ScrollViewer Padding="6">
<ItemsControl ItemsSource="{Binding Settings}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:DecompilerSettingsGroupViewModel">
<Expander Header="{Binding Category}" IsExpanded="True" Margin="0,2">
<ItemsControl ItemsSource="{Binding Settings}" Margin="12,4,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:DecompilerSettingsItemViewModel">
<CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}"
Content="{Binding Description}"
Margin="0,1" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- ScrollViewer Padding is collapsed on the vertical axis by the Simple-theme
ScrollContentPresenter when a vertical scrollbar is present, and the outer
StackPanel's measure also under-counts a trailing HeaderedContentControl's
content. Wrapping in a Border with explicit Padding makes the padding part
of the measured content so the last child stays reachable at max scroll. -->
<ScrollViewer>
<Border Padding="6,6,6,12">
<ItemsControl ItemsSource="{Binding Settings}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:DecompilerSettingsGroupViewModel">
<Expander Header="{Binding Category}" IsExpanded="True" Margin="0,2">
<ItemsControl ItemsSource="{Binding Settings}" Margin="12,4,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:DecompilerSettingsItemViewModel">
<CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}"
Content="{Binding Description}"
Margin="0,1" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
</ScrollViewer>
</UserControl>

13
ILSpy/Options/DisplaySettingsPanel.axaml

@ -7,8 +7,14 @@ @@ -7,8 +7,14 @@
mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="500"
x:Class="ILSpy.Options.Panels.DisplaySettingsPanel"
x:DataType="vm:DisplaySettingsViewModel">
<ScrollViewer Padding="6">
<StackPanel Spacing="10">
<!-- ScrollViewer Padding is collapsed on the vertical axis by the Simple-theme
ScrollContentPresenter when a vertical scrollbar is present, and the outer
StackPanel's measure also under-counts a trailing HeaderedContentControl's
content. Wrapping in a Border with explicit Padding makes the padding part
of the measured content so the last child stays reachable at max scroll. -->
<ScrollViewer>
<Border Padding="6,6,6,12">
<StackPanel Spacing="10">
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="Auto,Auto" ColumnSpacing="8" RowSpacing="4">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
Text="{x:Static res:Resources.Font}" />
@ -94,6 +100,7 @@ @@ -94,6 +100,7 @@
Content="{x:Static res:Resources.SortResultsFitness}" />
</StackPanel>
</HeaderedContentControl>
</StackPanel>
</StackPanel>
</Border>
</ScrollViewer>
</UserControl>

Loading…
Cancel
Save