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 binding.NewStringWithFormat #2890

Closed
PaulDotSH opened this issue Apr 2, 2022 · 4 comments · Fixed by #3027
Closed

Add binding.NewStringWithFormat #2890

PaulDotSH opened this issue Apr 2, 2022 · 4 comments · Fixed by #3027
Labels
enhancement New feature or request

Comments

@PaulDotSH
Copy link

PaulDotSH commented Apr 2, 2022

Is your feature request related to a problem? Please describe:

I.e. in my game, I have a word that the user needs to do something with, so I would want to show them something like
"Generated word: $word", instead of just $word

Is it possible to construct a solution with the existing API?

Shouldn't be very hard to implement since we have the same thing for int and floats

Describe the solution you'd like to see:

binding.NewStringWithFormat, working similar to binding.NewIntWithFormat

@andydotxyz andydotxyz changed the title Add binding.NewIntStringWithFormat Add binding.NewStringWithFormat Apr 2, 2022
@andydotxyz andydotxyz added the enhancement New feature or request label Apr 2, 2022
@Bluebugs
Copy link
Contributor

Bluebugs commented Apr 2, 2022

Something that might satisfy you need would be binding.NewSprintf that is currently in the developer branch. It take a string like Sprintf, a series of data bindings and provide a string data binding. It will automatically update the content of the string if any of the source data binding change and if the string is set, it will parse it with scanf and update the source data binding accordingly.

You can have a look at https://github.com/fyne-io/fyne/blob/develop/data/binding/sprintf.go#L23 .

@andydotxyz
Copy link
Member

Good point @Bluebugs - I wonder if NewStringWithFormat would be a helpful wrapper for the Sprintf binding that takes a single string, to fit with the FloatWithFormat pattern?

@Bluebugs
Copy link
Contributor

Bluebugs commented Apr 4, 2022

@andydotxyz indeed for discoverability and matching developers expectation, might be a good idea to propose NewStringWithFormat as a wrapper on top of the Sprintf binding.

@andydotxyz
Copy link
Member

Resolved with the less attractive but matching name of StringToStringWithFormat.
A shorthand could be added but we have no precedent for that...
Will be in v2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants