-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 custom parser to DragValue
and Slider
, with additional support for binary, octal, and hexadecimal numbers.
#1967
Conversation
May be return a |
If we do want this, I think It wouldn't make sense to change it in this PR though, since there isn't yet a way to display an error message from a parser, which itself is a whole different feature. The current implementation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Let's wait with that until we actually implement showing the errors (if ever) |
e4ca56c
to
3a5ca9c
Compare
Applied suggested changes, also added a |
Would be awesome to add thousands separator, e.g. |
@enomado Right now you can do it with num_format and use num_format::{Locale, ToFormattedString};
ui.add(DragValue::new(&mut n).custom_formatter(|n, _| n.to_formatted_string(&Locale::en))); |
Closes #1953.
Adds a
custom_parser
method toDragValue
andSlider
, along with extrabinary_u64
,octal_u64
, andhexadecimal_u64
which overwrite thecustom_formatter
andcustom_parser
.The purpose of
custom_parser
is to convert the text input from both widgets to af64
. A parser function returns anOption<f64>
set toSome
when parsing succeeds orNone
when it fails.Additional methods for different number systems all take in a
min_width
parameter that specifies the minimum number of displayed digits. If the number is shorter thanmin_width
, it will be prefixed with additional 0s to match it.hexadecimal_u64
also takes in abool
which specifies if in the output text alphabetic digits should be uppercase or not.Demo (apologies for quality):
Code for the demo: