Skip to content

Commit

Permalink
Win32: Use listview's builtin "scroll into view" implementation.
Browse files Browse the repository at this point in the history
The default implementation doesn't work well in details view
because we scroll by items and it expects pixels. List view,
where we scroll by columns, is likely similar.
  • Loading branch information
madewokherd committed Oct 7, 2024
1 parent e0a6fbb commit 1a5108e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions xalia/Interop/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ public struct COMBOBOXINFO
public const int LVM_FIRST = 0x1000;
public const int LVM_GETITEMCOUNT = LVM_FIRST + 4;
public const int LVM_GETITEMRECT = LVM_FIRST + 14;
public const int LVM_ENSUREVISIBLE = LVM_FIRST + 19;
public const int LVM_SCROLL = LVM_FIRST + 20;
public const int LVM_GETCOLUMNWIDTH = LVM_FIRST + 29;
public const int LVM_GETHEADER = LVM_FIRST + 31;
Expand Down
16 changes: 13 additions & 3 deletions xalia/Ui/UiMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ internal void TargetMove(Direction direction)

TargetedElement = best_element;

ScrollIntoView(TargetedElement);
Utils.RunTask(ScrollIntoView(TargetedElement));
}

private bool AdjustValue(UiDomElement targetedElement, Direction direction)
Expand Down Expand Up @@ -1051,8 +1051,18 @@ internal void TargetMoveRoutineStopped()
target_box.Hide();
}

private void ScrollIntoView(UiDomElement targetedElement)
private async Task ScrollIntoView(UiDomElement targetedElement)
{
var scroll_to = targetedElement.ProviderByType<IUiDomScrollToProvider>();

if (!(scroll_to is null))
{
if (await scroll_to.ScrollToAsync())
{
return;
}
}

if (!TryGetElementTargetBounds(targetedElement, out var bounds))
return;

Expand Down Expand Up @@ -1105,7 +1115,7 @@ private void ScrollIntoView(UiDomElement targetedElement)
queue.Enqueue(st);
queue.Enqueue(new InputState(InputStateKind.Disconnected));

Utils.RunTask(routine.ProcessInputQueue(queue));
await routine.ProcessInputQueue(queue);
}

break;
Expand Down
9 changes: 9 additions & 0 deletions xalia/UiDom/IUiDomScrollToProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace Xalia.UiDom
{
internal interface IUiDomScrollToProvider : IUiDomProvider
{
Task<bool> ScrollToAsync();
}
}
8 changes: 7 additions & 1 deletion xalia/Win32/HwndListViewItemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Xalia.Win32
{
internal class HwndListViewItemProvider : UiDomProviderBase, IWin32LocationChange
internal class HwndListViewItemProvider : UiDomProviderBase, IWin32LocationChange, IUiDomScrollToProvider
{
public HwndListViewItemProvider(HwndListViewProvider parent, UiDomElement element)
{
Expand Down Expand Up @@ -388,5 +388,11 @@ await SendMessageAsync(Parent.Hwnd, LVM_SETITEMSTATE,
(IntPtr)(ChildId - 1), (IntPtr)(long)memory.Address);
}
}

public async Task<bool> ScrollToAsync()
{
await SendMessageAsync(Parent.Hwnd, LVM_ENSUREVISIBLE, (IntPtr)(ChildId - 1), (IntPtr)(1));
return true;
}
}
}
1 change: 1 addition & 0 deletions xalia/xalia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="Sdl\SplitOverlayBox.cs" />
<Compile Include="Sdl\Win32LayeredBox.cs" />
<Compile Include="UiDom\IUiDomProvider.cs" />
<Compile Include="UiDom\IUiDomScrollToProvider.cs" />
<Compile Include="UiDom\IUiDomValueProvider.cs" />
<Compile Include="UiDom\UiDomAdjustScrollbars.cs" />
<Compile Include="Gudl\ApplyExpression.cs" />
Expand Down

0 comments on commit 1a5108e

Please sign in to comment.