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

Add functionality to make TextInput disabled #1744

Merged
merged 8 commits into from
Apr 12, 2023

Conversation

JungleTryne
Copy link
Contributor

@JungleTryne JungleTryne commented Mar 3, 2023

People have been asking to add disabled state for several widgets in #1066. The most liked comment was about adding the state to the TextEdit widget. Indeed, it's quite useful to have functionalty to prevent user from changing the content of the text edit fields.

I added new logic and a theme for the widget to implement the functionality.

Now text edit can be enabled/disabled like this:

text_input(
  "Write something here",
  &self.data,
  Message::TextInputChanged,
).disabled(true);

@13r0ck
Copy link
Member

13r0ck commented Mar 3, 2023

I would rather this be like the button. Have the text input by default be disabled like a button, but have an on_change(MESSAGE) method.

@JungleTryne
Copy link
Contributor Author

I would rather this be like the button. Have the text input by default be disabled like a button, but have an on_change(MESSAGE) method.

But that requires changing the API, which might break back-compatibility. It's not a problem to rewrite it, but I would like to know if it is okay to actually implement breaking changes at this point

@JungleTryne JungleTryne changed the title Add .disabled() option for TextInput Add functionality to make TextInput disabled Mar 3, 2023
@JungleTryne
Copy link
Contributor Author

I changed API, now it works like a button. It is not enabled if there is no callback for on_change.

I also change the example, I added an async 3 seconds timer to test an edge-case when the field is focused and gets disabled, suggested in discord by nicoburns#9458.

Finally, I updated all examples for the new API

@hecrj hecrj added the widget label Mar 14, 2023
@hecrj hecrj added this to the 0.9.0 milestone Mar 14, 2023
@hecrj hecrj added the feature New feature or request label Mar 14, 2023
@hecrj hecrj added the styling label Apr 12, 2023
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

Thank your taking a shot at this! 🙇

I have made some important changes:

  • Renamed on_change to on_input in e6a93e9. I believe it conveys more intent.
  • Added some diffing logic to unfocus the input if it suddenly becomes disabled in 7e69cb4.
  • Fine-tuned the disabled styling a bit in 1de794a.
  • Changed the mouse_interaction to display a new NotAllowed mouse icon when hovering a disabled input in 7e7e665.

And that's it! Let's merge!

@hecrj hecrj enabled auto-merge April 12, 2023 02:46
@hecrj hecrj merged commit ce8e92c into iced-rs:master Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request styling widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants