Skip to content

Improve mouse interactions in Avalonia control#1040

Merged
swharden merged 9 commits intoScottPlot:masterfrom
bclehmann:avalonia-call-base-pointerMoved
May 20, 2021
Merged

Improve mouse interactions in Avalonia control#1040
swharden merged 9 commits intoScottPlot:masterfrom
bclehmann:avalonia-call-base-pointerMoved

Conversation

@bclehmann
Copy link
Member

New Contributors:
please review CONTRIBUTING.md

Purpose:
#999 (comment)

New Functionality:
Forwards mouse moved events to the parent object in Avalonia.

@bclehmann
Copy link
Member Author

As an aside, there is still quite a bit of functionality commented out in AvaPlot.axaml.cs. It fits mostly into these categories:

  • Dead or no longer necessary code, perhaps from a previous AvaPlot implementation or debugging code
  • Code for features Avalonia does not/did not support when it was written
    • Copying images to clipboard I believe is still quite difficult
    • I don't know if Avalonia supports changing the cursor yet
  • Code for features that I never added but probably should've
    • I still am unsure what we're doing about context menus on the new common backend
    • Detecting designer mode was removed in order to get the very first version working and then never revisited

Let me know your opinion.

@bclehmann
Copy link
Member Author

It looks like Avalonia does support changing the cursor on InputElements, which is one of the base types of UserControl.

@swharden
Copy link
Member

Thanks for this PR and the notes about the commented-out blocks! I was about to list-out the changes I made but it looks like you're already on it.

Regarding right-click, controls respond to right-clicks by invoking whatever is in RightClicked. This lets users do things other than deploy context menus. I added XML docs to make this a little easier to figure out.

Let me know if all these changes look good to you! If so I'll merge now. Thanks again for all your Avalonia input! 👍 🚀

@swharden swharden changed the title Call base.PointerMoved on mouse move in AvaPlot Improve mouse interactions in Avalonia control May 19, 2021
@bclehmann
Copy link
Member Author

bclehmann commented May 19, 2021

Let me know if all these changes look good to you! If so I'll merge now. Thanks again for all your Avalonia input! 👍 🚀

All looks good, thanks for taking this up!

EDIT: It might be worth looking into preventing rendering in the designer view, like is done in WPF and WinForms

@bclehmann
Copy link
Member Author

bclehmann commented May 20, 2021

I made it so it does not render in the designer view:

image

It looks like this no longer works in WPF or on WinForms, was this an intentional choice or a regression?

@swharden
Copy link
Member

swharden commented May 20, 2021

was this an intentional choice or a regression

I removed it in 99c786f because bool isDesignerMode = false; was hard-coded so I didn't think it worked

I didn't realize until now Avalonia even had a designer mode (it doesn't work out of the box on my system)

I'd like to move toward the design time display I'm using in WinForms (#1043), but I'm really scared about difficult to diagnose design-time crashes. Do you think this can be done safely in a way that falls back to something simple? I'll try to implement something similar for WPF shortly

@bclehmann
Copy link
Member Author

I didn't realize until now Avalonia even had a designer mode

I think it might have been this extension: https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio

Do you think this can be done safely in a way that falls back to something simple? I'll try to implement something similar for WPF shortly

By and large, if it can be done in WPF it can be done in Avalonia the same way (although sometimes with a bit of extra work). As for doing it in WPF, perhaps if it detects designer mode it enables a massive try-catch block that swallows everything (like how webservers stay alive and just send an HTTP 500 if there's an unhandled exception).

Now that I think about it, it may be easier to always have the massive try-catch block, but rethrow if not in the designer, and handle it in the designer. I don't think this is likely to be worth the extra effort in debugging. Perhaps when in designer mode it might be best to use an entirely different code path.

Or simply accept that designer crashes may happen, I think most of the time when these issues occur it is related to .csproj issues, so I don't know how much we're increasing the surface.

@swharden
Copy link
Member

I think it might have been this extension

Ah, that makes sense

massive try-catch block ... I don't think this is likely to be worth the extra effort in debugging ... or simply accept that designer crashes may happen

I'll research this topic more as it relates to the WPF control and note my findings in #1043, and I'm happy to leave things as they are now for the Avalonia control. I'll go ahead and merge this is, and if/when you're inspired to make a fancier designer view for the Avalonia control you can choose the implementation you feel best about.

Thanks again for this PR! This one-liner turned into a solid improvement 👍

@swharden swharden merged commit 1faa44a into ScottPlot:master May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants