pub struct ValueFormat<'a> {
pub prefix: Atoms<'a>,
pub suffix: Atoms<'a>,
pub min_decimals: usize,
pub max_decimals: Option<usize>,
pub custom_formatter: Option<Arc<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a>>,
pub custom_parser: Option<Arc<dyn Fn(&str) -> Option<f64> + 'a>>,
pub update_while_editing: bool,
}Expand description
How a number is written, read back, and applied while being edited.
Owned by crate::DragValue, and by crate::Slider and crate::RangeSlider
for the numbers they show beside the rail.
Fields§
§prefix: Atoms<'a>Shown before the number, e.g. "x: ".
suffix: Atoms<'a>Shown after the number, e.g. a unit.
min_decimals: usizeShow at least this many decimals.
max_decimals: Option<usize>Show at most this many decimals, and round values to it.
custom_formatter: Option<Arc<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a>>Turns a value into text. Default: crate::style::NumberFormatter.
custom_parser: Option<Arc<dyn Fn(&str) -> Option<f64> + 'a>>Turns text back into a value. Default: accepts plain decimal numbers.
update_while_editing: boolApply each keystroke while typing, rather than on enter.
Implementations§
Source§impl<'a> ValueFormat<'a>
impl<'a> ValueFormat<'a>
Sourcepub fn prefix(self, prefix: impl IntoAtoms<'a>) -> ValueFormat<'a>
pub fn prefix(self, prefix: impl IntoAtoms<'a>) -> ValueFormat<'a>
Show a prefix before the number, e.g. “x: “.
Goes in front of any prefix already set, so .prefix("b").prefix("a") shows ab.
Sourcepub fn suffix(self, suffix: impl IntoAtoms<'a>) -> ValueFormat<'a>
pub fn suffix(self, suffix: impl IntoAtoms<'a>) -> ValueFormat<'a>
Add a suffix to the number, this can be e.g. a unit (“°” or “ m“).
Goes after any suffix already set, so .suffix("a").suffix("b") shows ab.
Sourcepub fn min_decimals(self, min_decimals: usize) -> ValueFormat<'a>
pub fn min_decimals(self, min_decimals: usize) -> ValueFormat<'a>
Set a minimum number of decimals to display.
Sourcepub fn max_decimals(self, max_decimals: usize) -> ValueFormat<'a>
pub fn max_decimals(self, max_decimals: usize) -> ValueFormat<'a>
Set a maximum number of decimals to display. Values will also be rounded to this number of decimals.
Sourcepub fn max_decimals_opt(self, max_decimals: Option<usize>) -> ValueFormat<'a>
pub fn max_decimals_opt(self, max_decimals: Option<usize>) -> ValueFormat<'a>
Set the maximum number of decimals to display, or None to let the widget pick.
Values will also be rounded to this number of decimals when it is set.
Sourcepub fn fixed_decimals(self, num_decimals: usize) -> ValueFormat<'a>
pub fn fixed_decimals(self, num_decimals: usize) -> ValueFormat<'a>
Set an exact number of decimals to display. Values will also be rounded to this number of decimals.
Sourcepub fn custom_formatter(
self,
formatter: impl Fn(f64, RangeInclusive<usize>) -> String + 'a,
) -> ValueFormat<'a>
pub fn custom_formatter( self, formatter: impl Fn(f64, RangeInclusive<usize>) -> String + 'a, ) -> ValueFormat<'a>
Set custom formatter defining how numbers are converted into text.
A custom formatter takes a f64 for the numeric value and a RangeInclusive<usize> representing
the decimal range i.e. minimum and maximum number of decimal places shown.
See also: Self::custom_parser
Sourcepub fn custom_parser(
self,
parser: impl Fn(&str) -> Option<f64> + 'a,
) -> ValueFormat<'a>
pub fn custom_parser( self, parser: impl Fn(&str) -> Option<f64> + 'a, ) -> ValueFormat<'a>
Set custom parser defining how the text input is parsed into a number.
A custom parser takes an &str to parse into a number and returns a f64 if it was successfully parsed
or None otherwise.
See also: Self::custom_formatter
Sourcepub fn binary(self, min_width: usize, twos_complement: bool) -> ValueFormat<'a>
pub fn binary(self, min_width: usize, twos_complement: bool) -> ValueFormat<'a>
Set custom_formatter and custom_parser to display and parse numbers as binary integers. Floating point
numbers are not supported.
min_width specifies the minimum number of displayed digits; if the number is shorter than this, it will be
prefixed with additional 0s to match min_width.
If twos_complement is true, negative values will be displayed as the 2’s complement representation. Otherwise
they will be prefixed with a ‘-’ sign.
§Panics
Panics if min_width is 0.
Sourcepub fn octal(self, min_width: usize, twos_complement: bool) -> ValueFormat<'a>
pub fn octal(self, min_width: usize, twos_complement: bool) -> ValueFormat<'a>
Set custom_formatter and custom_parser to display and parse numbers as octal integers. Floating point
numbers are not supported.
min_width specifies the minimum number of displayed digits; if the number is shorter than this, it will be
prefixed with additional 0s to match min_width.
If twos_complement is true, negative values will be displayed as the 2’s complement representation. Otherwise
they will be prefixed with a ‘-’ sign.
§Panics
Panics if min_width is 0.
Sourcepub fn hexadecimal(
self,
min_width: usize,
twos_complement: bool,
upper: bool,
) -> ValueFormat<'a>
pub fn hexadecimal( self, min_width: usize, twos_complement: bool, upper: bool, ) -> ValueFormat<'a>
Set custom_formatter and custom_parser to display and parse numbers as hexadecimal integers. Floating point
numbers are not supported.
min_width specifies the minimum number of displayed digits; if the number is shorter than this, it will be
prefixed with additional 0s to match min_width.
If twos_complement is true, negative values will be displayed as the 2’s complement representation. Otherwise
they will be prefixed with a ‘-’ sign.
§Panics
Panics if min_width is 0.
Sourcepub fn update_while_editing(self, update: bool) -> ValueFormat<'a>
pub fn update_while_editing(self, update: bool) -> ValueFormat<'a>
Update the value on each key press when text-editing the value.
Default: true.
If false, the value will only be updated when user presses enter or deselects the value.
Trait Implementations§
Source§impl<'a> Clone for ValueFormat<'a>
impl<'a> Clone for ValueFormat<'a>
Source§fn clone(&self) -> ValueFormat<'a>
fn clone(&self) -> ValueFormat<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for ValueFormat<'_>
impl Default for ValueFormat<'_>
Source§fn default() -> ValueFormat<'_>
fn default() -> ValueFormat<'_>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for ValueFormat<'a>
impl<'a> !Send for ValueFormat<'a>
impl<'a> !Sync for ValueFormat<'a>
impl<'a> !UnwindSafe for ValueFormat<'a>
impl<'a> Forget for ValueFormat<'a>
impl<'a> Freeze for ValueFormat<'a>
impl<'a> Move for ValueFormat<'a>
impl<'a> Unpin for ValueFormat<'a>
impl<'a> UnsafeUnpin for ValueFormat<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more