Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

[DO NOT MERGE] Include Adorners in matrix calculations in VisualExtensions

Open BAndysc opened this issue 10 months ago • 6 comments

What does the pull request do?

This PR changes VisualExtensions::TransformToVisual to support adorners.

What is the current behavior?

Currently VisualExtensions::TransformToVisual doesn't work correctly when one of the controls is inside an Adorner Layer. Adorned element is not on a path to root from adorner element. So it is not included in calculations. Adorners are rendered correctly, because the renderer has special handling for adorners. Hence TransformToVisual needs some special handling too.

What is the updated/expected behavior with this PR?

VisualExtensions::TransformToVisual should correctly take into account adorners.

How was the solution implemented (if it's not obvious)?

Unfortunately, adorners are defined in Avalonia.Controls while VisualExtensions is in Avalonia.Base, so VisualExtensions doesn't know what adorners are. Therefore, this PR adds AdornerLayerBase with AdornedElementProperty and an empty IAdornerLayer to Avalonia.Base so that this information is available. This is far from perfect, but I don't know how to do it in a cleaner way.

Besides, the obvious downside of the solution is additional computation complexity in VisualExtensions::TransformToVisual. Each time this method is called, an adorned element needs to be found via calling GetValue(AdornedElementProperty) on each element on path to root.

Checklist

  • [x] Added unit tests (if possible)?
  • [ ] Added XML documentation to any related classes?
  • [ ] Consider submitting a PR to https://github.com/AvaloniaUI/avalonia-docs with user documentation

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #15480

BAndysc avatar Apr 23 '24 18:04 BAndysc

You can test this PR using the following package version. 11.2.999-cibuild0047604-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

avaloniaui-bot avatar Apr 23 '24 18:04 avaloniaui-bot

As per @kekekeks, whole situation with "adorner transformation processed on composition thread" should be changed to be done on UI thread. So, I am not sure how we should process with this PR (and previous already merged).

maxkatz6 avatar Apr 25 '24 01:04 maxkatz6

I understand. However, until it is properly fixed, I would appreciate if this PR could remain open, as I use adorners a lot in my app (and it worked fine in Avalonia 0.10), thus for now I can use nightly builds produced by this PR.

BAndysc avatar Apr 25 '24 08:04 BAndysc

You can test this PR using the following package version. 11.2.999-cibuild0047725-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

avaloniaui-bot avatar Apr 25 '24 08:04 avaloniaui-bot

@BAndysc we can leave it open, but I'd like to mark it as draft and won't merged for now, just in case

timunie avatar Apr 25 '24 11:04 timunie

You can test this PR using the following package version. 11.2.999-cibuild0048166-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

avaloniaui-bot avatar May 07 '24 10:05 avaloniaui-bot

You can test this PR using the following package version. 11.1.3-cibuild0051668-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

avaloniaui-bot avatar Sep 05 '24 00:09 avaloniaui-bot

  • [x] All contributors have signed the CLA.

cla-avalonia avatar Sep 05 '24 00:09 cla-avalonia

Oh my, sorry for all the pings, I just needed to rebase this PR on top of 11.3, but it wouldn't build until I merged it with master, hence the mess, sorry again.

BAndysc avatar Sep 05 '24 00:09 BAndysc

@cla-avalonia agree

derekantrican avatar Sep 05 '24 02:09 derekantrican

@cla-avalonia agree

ArtjomP avatar Sep 05 '24 07:09 ArtjomP

@cla-avalonia agree

SKProCH avatar Sep 05 '24 07:09 SKProCH

Please rebuild your commit tree to only have your commits.

emmauss avatar Sep 05 '24 08:09 emmauss

@emmauss Latest master has some problems which prevent me from using it (https://github.com/AvaloniaUI/Avalonia/issues/16754) that's why I rebased it on top of 11.1, but CI wouldn't build until all conflicts with master were solved (the PR destination branch is master and I can't change it). Sorry for the mess again. Maybe you could remove the bot comment so that people will not reply agree here?

BAndysc avatar Sep 05 '24 10:09 BAndysc

@emmauss Latest master has some problems which prevent me from using it (#16754) that's why I rebased it on top of 11.1, but CI wouldn't build until all conflicts with master were solved (the PR destination branch is master and I can't change it). Sorry for the mess again. Maybe you could remove the bot comment so that people will not reply agree here?

Don't worry. It auto updates when a new commit is pushed. It has fixed itself.

emmauss avatar Sep 05 '24 11:09 emmauss

You can test this PR using the following package version. 11.2.999-cibuild0051678-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

avaloniaui-bot avatar Sep 05 '24 11:09 avaloniaui-bot