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

Should hidden widget keep the focus ? #1858

Closed
lisael opened this issue Jul 6, 2021 · 5 comments · Fixed by #1860
Closed

Should hidden widget keep the focus ? #1858

lisael opened this issue Jul 6, 2021 · 5 comments · Fixed by #1860
Labels
bug does not behave the way it is supposed to widget concerns a particular widget

Comments

@lisael
Copy link
Contributor

lisael commented Jul 6, 2021

To illustrate the issue, get my branch and run the either example (the branch is misnamed, I'm not sure it's a bug, now. I thought it was because of the storm of TimerEvent I kept recieving, without a visible focused widget):

cd /tmp
git clone [email protected]:lisael/druid.git
cd druid/druid
git checkout buggy_focus_on_either
cargo run --example either

the code

  • click on [Edit 1] -> the textbox appears
  • start typing in the textbox
  • click on [Edit 1] -> the textbox becomes a label
  • keep typing -> the label is still updated

I understand that this can be desirable, but it's surprising, and somewhat annoying because it's not easy to change the focus in update(...), as the UpdateCxt has no method for this.

Ideas:

  1. add a ctx method to release the focus unconditionally
  2. add a lifecycle event on widget show/hide (well... the LifecycleCtx can't change the focus, but at least it can submit a command)
@cmyr cmyr added bug does not behave the way it is supposed to widget concerns a particular widget labels Jul 6, 2021
@cmyr
Copy link
Member

cmyr commented Jul 6, 2021

no, I think this is a bug. the hidden widget in Either should not be interactive.

My first thought is that Either should check to see if a child has focus when it changes children, and it should handle resigning if needed?

@lisael
Copy link
Contributor Author

lisael commented Jul 6, 2021

I tried to do that, checking is just self.current_widget().has_focus(). The harder part is I couldn't find a way to just drop the focus without using Commands sent to the children, so they can sort this out in their respective event(...). Maybe it's the only way? Maybe I'm missing something (quite new to druid...)?

@xarvic
Copy link
Collaborator

xarvic commented Jul 7, 2021

I think calling children_changed() in Either when switching the widgets should suffice.
This was the reason for #1724, but i forgot to update the docs.

@lisael
Copy link
Contributor Author

lisael commented Jul 7, 2021

@xarvic It suffice, indeed. Thanks! I send a PR, for this.

@xarvic
Copy link
Collaborator

xarvic commented Jul 7, 2021

That was quick :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug does not behave the way it is supposed to widget concerns a particular widget
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants