pub struct NumericFormat<'a, T> { /* private fields */ }Expand description
A validated C-style format for one Dear ImGui numeric value.
The value type is part of the format type, so a format validated for f32
cannot be passed to an integer widget. Borrowed strings remain zero-copy,
while owned strings remain stable after validation.
use dear_imgui_rs::{Context, NumericFormat};
let mut context = Context::create();
let ui = context.frame();
let integer_format = NumericFormat::<u32>::new("%u").unwrap();
let _ = ui
.slider_config("value", 0.0_f32, 1.0_f32)
.display_format(integer_format);use dear_imgui_rs::Context;
let mut context = Context::create();
let ui = context.frame();
let _ = ui
.slider_config("value", 0.0_f32, 1.0_f32)
.display_format("%.2f");Implementations§
Source§impl<'a, T> NumericFormat<'a, T>where
T: DataTypeKind,
impl<'a, T> NumericFormat<'a, T>where
T: DataTypeKind,
Sourcepub fn new(storage: impl Into<Cow<'a, str>>) -> Result<Self, NumericFormatError>
pub fn new(storage: impl Into<Cow<'a, str>>) -> Result<Self, NumericFormatError>
Validates and retains a numeric format.
Safe formats may contain ordinary UTF-8 decoration, escaped percent
signs (%%), and at most one conversion matching T. The portable ll and MSVC
I64 modifiers are normalized for the compilation target. Width is
limited to 31, precision to 99, and the complete UTF-8 string to 4096
bytes so downstream native parsing remains bounded.
use dear_imgui_rs::NumericFormat;
let percent = NumericFormat::<f32>::new("%.1f%%")?;
assert_eq!(percent.as_str(), "%.1f%%");
assert!(NumericFormat::<f32>::new("%s").is_err());Sourcepub unsafe fn new_unchecked(storage: impl Into<Cow<'a, str>>) -> Self
pub unsafe fn new_unchecked(storage: impl Into<Cow<'a, str>>) -> Self
Creates a numeric format without validation.
§Safety
The format must be valid for the exact C variadic argument represented
by T::KIND. It must consume at most one value argument, must not use
dynamic width or precision, positional arguments, %n, or any other
conversion that consumes a different argument type. Width must not exceed
31, precision must not exceed 99, flags must be valid for the conversion,
and the complete string must not exceed 4096 bytes. Violating this contract
can cause undefined behavior, including arbitrary memory writes.
Sourcepub fn borrowed(&self) -> NumericFormat<'_, T>
pub fn borrowed(&self) -> NumericFormat<'_, T>
Borrows this format without revalidating it.
Sourcepub fn into_owned(self) -> NumericFormat<'static, T>
pub fn into_owned(self) -> NumericFormat<'static, T>
Converts this format into an owned value that can be stored indefinitely.
Sourcepub fn into_inner(self) -> Cow<'a, str>
pub fn into_inner(self) -> Cow<'a, str>
Returns the target-normalized string storage.
Trait Implementations§
Source§impl<T> AsRef<str> for NumericFormat<'_, T>where
T: DataTypeKind,
impl<T> AsRef<str> for NumericFormat<'_, T>where
T: DataTypeKind,
Source§impl<'a, T: Clone> Clone for NumericFormat<'a, T>
impl<'a, T: Clone> Clone for NumericFormat<'a, T>
Source§fn clone(&self) -> NumericFormat<'a, T>
fn clone(&self) -> NumericFormat<'a, T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more