Skip to content

Filtered Textbox #532

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

Open
TheNeikos opened this issue Jul 31, 2015 · 2 comments
Open

Filtered Textbox #532

TheNeikos opened this issue Jul 31, 2015 · 2 comments

Comments

@TheNeikos
Copy link
Contributor

I have worked up a small change to the textbox so that one could indicate a filter method that will be called on insert allowing to have some control over what gets put into a textbox.

The changes can be seen here: https://github.com/TheNeikos/conrod/tree/add-filter_to_textbox

However I have not put this as a PR yet because of two things:

  1. Is something like this wanted? In my current project I would definitely find several uses, but if 2 is not resolved it might not be worth it.
  2. This is a breaking change to the TextBox as for now it requires static dispatch (I implemented it like the react callback), it also means if you do not want to filter you will have to write at least:
.filter(|_string: &mut String, _ch: char|{true})

This does not differ from the react callback, but for those that do not want to filter their input it adds more boilerplate. (Which also exists for the react callback, but I believe that react is a lot more used than a potential filter)

Could I have some input on whether to drop/continue working on it and whether it should be dynamic dispatch.

@mitchmindtree
Copy link
Contributor

Thanks @TheNeikos, this is sweet! I think it'd be super useful :)

However perhaps we can hold off on adding this until this and implementing the Fn/FnMut/FnOnce traits becomes stable? That way we could make empty function objects to use as defaults for .react and .filter which would mean a user wouldn't have to deal with the boilerplate if they didn't need it?

Btw, does the .filter method need the &mut String as the first param? It should only need the char right?

@TheNeikos
Copy link
Contributor Author

@mitchmindtree Thanks for the feedback!

Well I thought about it, but I was thinking of a specific scenario where you could only insert for example 4 lowercase letters and 4 uppercase? I agree that it is an edge case, but I didn't think that it gave a huge downside for all the possible upsides. (And I believe in llvm to optimize that closure!)

And Function Objects sound like the right thing if they are what I believe them to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants