Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with mouse cursor position when editing nodes #7014

Merged
merged 5 commits into from
Jun 19, 2023

Conversation

vitvakatu
Copy link
Contributor

@vitvakatu vitvakatu commented Jun 12, 2023

Pull Request Description

Fixes #6702

The issue was in the code for hiding/showing the node label. When showing it for the first time, the position of the label was updated only in the next frame, so the whole calculation was incorrect.

It is fixed using the DETACHED scene layer to hide the label when needed. Its position is always correct.

2023-06-12.14-42-45.mp4

Important Notes

I added a bit of additional code to ensure we always use the correct layer. The label is a complicated entity, as it lives in different layers in different application states. Also, I removed the code for setting the initial layer from the init method, as it seems unused.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@vitvakatu vitvakatu self-assigned this Jun 12, 2023
@vitvakatu vitvakatu marked this pull request as ready for review June 12, 2023 10:45
Comment on lines 247 to 250
*self.label_layer.borrow_mut() = layer.downgrade();
// We're taking extra measures to ensure that the actual layer of the label will be updated
// even if it is already displayed. It should be unnecessary with the current
// implementation. See [`Self::show_edit_mode_label`] and [`Self::hide_edit_mode_label`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be unnecessary with the current implementation.

I don't understand this. If it's unnecessary, why do we do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we have no control over when the set_label_layer method will be called from outside of this component, and technically it can happen when we already have the label visible. As far as I understand the code, it shouldn't happen, but one can refactor it in the future and accidentally change the behavior. So it is just a preventative measure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the docs rephrased this way would be more understandable to me:

Currently, we never sets label layer when it's already displayed, but - as `set_label_layer` is a public method of this component - we're taking extra measures.

Copy link
Member

@wdanilo wdanilo Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Adam asked a question because the comment in the code is confusing. I see that the code did not change (the docs are not improved / expanded) and it is still confusing, so the question was not addressed yet. The comment is also very confusing to me – if it "should be unnecessary with the current implementation", it should not be there.
  2. You have full control of if the set_label_layer will be called from outside of this component – the method is private, so it will not be called from outside.

I don't think we should include "dead code" that does nothing and is there just in case someone refactors code without thinking about the logic. This makes the whole code hard to understand and follow. In the future, when browsing this code, I would probably spend a lot of time trying to understand why edit_mode_label_displayed is needed and why we are managing this state, thinking that probably this solves some issue. If it is not needed, lets not add it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have full control of if the set_label_layer will be called from outside of this component – the method is private, so it will not be called from outside.

This is not true, it is called from the public method of view.

Copy link
Contributor

@farmaazon farmaazon Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github have fooled me. I actually added a comment yesterday, but it was kept in a pending state, and I didn't notice.

Now it should be visible. I proposed an alternative comment. Check @wdanilo if it's ok to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I like your proposal.

@kazcw
Copy link
Contributor

kazcw commented Jun 12, 2023

QA: 🟢

CHANGELOG.md Outdated
@@ -183,6 +183,7 @@
execution failed][6918].
- [Performance and readability of documentation panel was improved][6893]. The
documentation is now split into separate pages, which are much smaller.
- [Fixed cursor position when ctrl-clicking the node][7014].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are user-facing logs. Users reading them should understand what changed without the need to click something and without prior knowledge. Telling "fixed cursor position" does not really explain what changed to the reader. I'd be thankful If you could expand that a little bit.

Comment on lines 247 to 250
*self.label_layer.borrow_mut() = layer.downgrade();
// We're taking extra measures to ensure that the actual layer of the label will be updated
// even if it is already displayed. It should be unnecessary with the current
// implementation. See [`Self::show_edit_mode_label`] and [`Self::hide_edit_mode_label`].
Copy link
Member

@wdanilo wdanilo Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Adam asked a question because the comment in the code is confusing. I see that the code did not change (the docs are not improved / expanded) and it is still confusing, so the question was not addressed yet. The comment is also very confusing to me – if it "should be unnecessary with the current implementation", it should not be there.
  2. You have full control of if the set_label_layer will be called from outside of this component – the method is private, so it will not be called from outside.

I don't think we should include "dead code" that does nothing and is there just in case someone refactors code without thinking about the logic. This makes the whole code hard to understand and follow. In the future, when browsing this code, I would probably spend a lot of time trying to understand why edit_mode_label_displayed is needed and why we are managing this state, thinking that probably this solves some issue. If it is not needed, lets not add it :)

@vitvakatu vitvakatu requested a review from wdanilo June 13, 2023 12:33
@sylwiabr
Copy link
Member

@wdanilo can you re-review this?

@farmaazon farmaazon added the CI: Ready to merge This PR is eligible for automatic merge label Jun 15, 2023
@xvcgreg
Copy link

xvcgreg commented Jun 19, 2023

@vitvakatu What's the status here? It's 4 days old w/o any action.

@vitvakatu
Copy link
Contributor Author

@xvcgreg blame engine CI on windows, I don't know what has happened to it. Restarting one more time...

@wdanilo
Copy link
Member

wdanilo commented Jun 19, 2023

@vitvakatu in case of random failures, ping me and I will merge it :)

@wdanilo wdanilo merged commit 20edc2d into develop Jun 19, 2023
23 of 25 checks passed
@wdanilo wdanilo deleted the wip/vitvakatu/ctrl-clicking-position branch June 19, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl+click is placing cursor in a random place on a node
6 participants