taublast / DrawnUi.Maui

UI Rendering Engine for .NET MAUI powered by SkiaSharp
MIT License
206 stars 15 forks source link

Bug? in SkiaControl.Shared.AdaptCachedLayout is doubling Left/Top offsets. TBD under what circumstances. #94

Open ToolmakerSteve opened 3 days ago

ToolmakerSteve commented 3 days ago

I believe I have surfaced a latent problem in AdaptCachedLayout.
I need to determine exactly what in my layout of SkiaControls causes this.

This is when scrolling SkiaScroll. It has become a problem because on one path through DrawnUI code, the doubling occurs, BUT on a different path, the doubling does not occur. As a result, my content draws in one of two different positions (offsets), depending on ...[I'll add a comment when I know more]...

What I see so far:


Example:

+   destination {{Left=-52,Top=-1,Width=∞,Height=∞}}    SkiaSharp.SKRect
+   ArrangedDestination {{Left=-52,Top=-1,Width=∞,Height=∞}}    SkiaSharp.SKRect
=> `Destination` setter called with:
+   value   {{Left=-104,Top=-2,Width=∞,Height=∞}}   SkiaSharp.SKRect

Workaround:

I override AdaptCachedLayout to remove newDestination.Offset(...); line.


UPDATE

Given workaround, no longer have "doubled" values.
BUT my control is still drawn in two different positions, when it has been scrolled.

Now instead of "correct offset" and "doubled offset", the two positions are:
"zero offset", as if Scroll = (0,0), and "correct offset".
Investigating.

ToolmakerSteve commented 20 hours ago

This code path gives correct offsets, for controls inside SkiaScroll:

correct offset

This code path gives doubled offsets: doubled offset

taublast commented 1 hour ago

Thanks, Steve! Sorry for slow reaction, sick these days, will get in ranks soon.

taublast commented 1 hour ago

I believe I have surfaced a latent problem in AdaptCachedLayout. I need to determine exactly what in my layout of SkiaControls causes this.

This is when scrolling SkiaScroll. It has become a problem because on one path through DrawnUI code, the doubling occurs, BUT on a different path, the doubling does not occur. As a result, my content draws in one of two different positions (offsets), depending on ...[I'll add a comment when I know more]...

What I see so far:

  • AdaptCachedLayout is called for my custom SkiaLayout, which is Content of a SkiaScroll.
  • AdaptCachedLayout is called with destination that has Left, Top offsets.
  • ArrangedDestination ALSO has those offsets!
  • These lines result in the DOUBLED offsets:
var newDestination = ArrangedDestination;//.Clone();
newDestination.Offset(destination.Left, destination.Top);

Example:

+ destination {{Left=-52,Top=-1,Width=∞,Height=∞}}    SkiaSharp.SKRect
+ ArrangedDestination {{Left=-52,Top=-1,Width=∞,Height=∞}}    SkiaSharp.SKRect
=> `Destination` setter called with:
+ value   {{Left=-104,Top=-2,Width=∞,Height=∞}}   SkiaSharp.SKRect

Workaround:

I override AdaptCachedLayout to remove newDestination.Offset(...); line.

UPDATE

Given workaround, no longer have "doubled" values. BUT my control is still drawn in two different positions, when it has been scrolled.

Now instead of "correct offset" and "doubled offset", the two positions are: "zero offset", as if Scroll = (0,0), and "correct offset". Investigating.

I think I know where this might come from. Is it possible you changed the measuring process for your custom scroll or for the content wrapper (hopefully a skialayout)? What type is your content actually?

taublast commented 1 hour ago

One thing to know is that we land inside Arrange either when the parent measures us, either for "self-measure" that happens for top views on the canvas AND occasionally for any view when it's marked as dirty but for reason it's redrawing BEFORE the parent had the luck to measure it as due.