use crate::sys;
use crate::ui::Ui;
use std::borrow::Cow;
impl Ui {
#[doc(alias = "ProgressBar")]
pub fn progress_bar(&self, fraction: f32) -> ProgressBar<'_> {
ProgressBar::new(self, fraction)
}
#[doc(alias = "ProgressBar")]
pub fn progress_bar_with_overlay<'ui>(
&'ui self,
fraction: f32,
overlay: impl Into<Cow<'ui, str>>,
) -> ProgressBar<'ui> {
ProgressBar::new(self, fraction).overlay_text(overlay)
}
}
#[derive(Clone, Debug)]
#[must_use]
pub struct ProgressBar<'ui> {
fraction: f32,
size: [f32; 2],
overlay_text: Option<Cow<'ui, str>>,
ui: &'ui Ui,
}
impl<'ui> ProgressBar<'ui> {
#[inline]
#[doc(alias = "ProgressBar")]
pub fn new(ui: &'ui Ui, fraction: f32) -> Self {
ProgressBar {
fraction,
size: [-1.0, 0.0], overlay_text: None,
ui,
}
}
pub fn overlay_text(mut self, overlay_text: impl Into<Cow<'ui, str>>) -> Self {
self.overlay_text = Some(overlay_text.into());
self
}
#[inline]
pub fn size(mut self, size: impl Into<[f32; 2]>) -> Self {
self.size = size.into();
self
}
pub fn fraction(mut self, fraction: f32) -> Self {
self.fraction = fraction;
self
}
pub fn build(self) {
let size_vec: sys::ImVec2 = self.size.into();
let overlay_ptr = self
.overlay_text
.as_deref()
.map_or(std::ptr::null(), |txt| self.ui.scratch_txt(txt));
unsafe {
sys::igProgressBar(self.fraction, size_vec, overlay_ptr);
}
}
}