Skip to content

Commit

Permalink
perf(WindowManager): Add ArrangeElement binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Dec 23, 2022
1 parent 0944535 commit 927ab11
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,21 @@ internal static void ArrangeElement(IntPtr htmlId, Rect rect, Rect? clipRect)
}
else
{
#if NET7_0_OR_GREATER
var clipRectValue = clipRect ?? default;

NativeMethods.ArrangeElement(
htmlId,
rect.Top,
rect.Left,
rect.Width,
rect.Height,
clipRect.HasValue,
clipRectValue.Top,
clipRectValue.Left,
clipRectValue.Bottom,
clipRectValue.Right);
#else
var parms = new WindowManagerArrangeElementParams()
{
HtmlId = htmlId,
Expand All @@ -1320,6 +1335,7 @@ internal static void ArrangeElement(IntPtr htmlId, Rect rect, Rect? clipRect)
}

TSInteropMarshaller.InvokeJS("Uno:arrangeElementNative", parms);
#endif
}
}

Expand Down Expand Up @@ -1522,6 +1538,19 @@ internal enum HtmlPointerButtonUpdate
#if NET7_0_OR_GREATER
internal static partial class NativeMethods
{
[JSImport("globalThis.Uno.UI.WindowManager.current.arrangeElementNativeFast")]
internal static partial void ArrangeElement(
IntPtr htmlId,
double top,
double left,
double width,
double height,
bool clip,
double clipTop,
double clipLeft,
double clipBottom,
double clipRight);

[JSImport("globalThis.Uno.UI.WindowManager.current.measureViewNativeFast")]
internal static partial void MeasureView(IntPtr htmlId, double availableWidth, double availableHeight, bool measureContent, IntPtr pReturn);

Expand Down
44 changes: 35 additions & 9 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,25 +712,51 @@ namespace Uno.UI {
public arrangeElementNative(pParams: number): boolean {

const params = WindowManagerArrangeElementParams.unmarshal(pParams);
const element = this.getView(params.HtmlId);

this.arrangeElementNativeFast(
params.HtmlId,
params.Top,
params.Left,
params.Width,
params.Height,
params.Clip,
params.ClipTop,
params.ClipLeft,
params.ClipBottom,
params.ClipRight);

return true;
}

public arrangeElementNativeFast(
htmlId: number,
top: number,
left: number,
width: number,
height: number,
clip: boolean,
clipTop: number,
clipLeft: number,
clipBottom: number,
clipRight: number) {

const element = this.getView(htmlId);

const style = element.style;

style.position = "absolute";
style.top = params.Top + "px";
style.left = params.Left + "px";
style.width = params.Width === NaN ? "auto" : params.Width + "px";
style.height = params.Height === NaN ? "auto" : params.Height + "px";
style.top = top + "px";
style.left = left + "px";
style.width = width === NaN ? "auto" : width + "px";
style.height = height === NaN ? "auto" : height + "px";

if (params.Clip) {
style.clip = `rect(${params.ClipTop}px, ${params.ClipRight}px, ${params.ClipBottom}px, ${params.ClipLeft}px)`;
if (clip) {
style.clip = `rect(${clipTop}px, ${clipRight}px, ${clipBottom}px, ${clipLeft}px)`;
} else {
style.clip = "";
}

this.setAsArranged(element);

return true;
}

private setAsArranged(element: HTMLElement | SVGElement) {
Expand Down

0 comments on commit 927ab11

Please sign in to comment.