mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 21:48:36 +00:00
commit
c6a0edd085
@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Support for progress bar
|
||||
|
||||
### Removed
|
||||
|
||||
- `Window::always_vertical_scollbar` (typo)
|
||||
|
||||
20
src/lib.rs
20
src/lib.rs
@ -45,6 +45,7 @@ pub use input::{ColorEdit3, ColorEdit4, InputFloat, InputFloat2, InputFloat3, In
|
||||
pub use menus::{Menu, MenuItem};
|
||||
pub use plothistogram::PlotHistogram;
|
||||
pub use plotlines::PlotLines;
|
||||
pub use progressbar::ProgressBar;
|
||||
pub use sliders::{SliderFloat, SliderInt};
|
||||
pub use trees::{CollapsingHeader, TreeNode};
|
||||
pub use window::Window;
|
||||
@ -53,6 +54,7 @@ mod input;
|
||||
mod menus;
|
||||
mod plothistogram;
|
||||
mod plotlines;
|
||||
mod progressbar;
|
||||
mod sliders;
|
||||
mod trees;
|
||||
mod window;
|
||||
@ -668,3 +670,21 @@ impl<'ui> Ui<'ui> {
|
||||
PlotHistogram::new(label, values)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Creates a progress bar. Fraction is the progress level with 0.0 = 0% and 1.0 = 100%.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust,no_run
|
||||
/// # use imgui::*;
|
||||
/// # let mut imgui = ImGui::init();
|
||||
/// # let ui = imgui.frame((0, 0), (0, 0), 0.1);
|
||||
/// ui.progress_bar(0.6)
|
||||
/// .size(imgui::ImVec2::new(100.0, 12.0))
|
||||
/// .overlay_text(im_str!("Progress!"))
|
||||
/// .build();
|
||||
/// ```
|
||||
pub fn progress_bar<'p>(&self, fraction: f32) -> ProgressBar<'p> {
|
||||
ProgressBar::new(fraction)
|
||||
}
|
||||
}
|
||||
|
||||
55
src/progressbar.rs
Normal file
55
src/progressbar.rs
Normal file
@ -0,0 +1,55 @@
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use imgui_sys;
|
||||
use std::ptr;
|
||||
use super::{ImStr, ImVec2};
|
||||
|
||||
|
||||
/// Progress bar widget.
|
||||
#[must_use]
|
||||
pub struct ProgressBar<'p> {
|
||||
fraction: f32,
|
||||
size: ImVec2,
|
||||
overlay_text: Option<ImStr<'p>>,
|
||||
}
|
||||
|
||||
impl<'p> ProgressBar<'p> {
|
||||
/// Creates a progress bar with a given fraction showing
|
||||
/// the progress (0.0 = 0%, 1.0 = 100%).
|
||||
/// The progress bar will be automatically sized to fill
|
||||
/// the entire width of the window if no custom size is
|
||||
/// specified.
|
||||
pub fn new(fraction: f32) -> Self {
|
||||
ProgressBar {
|
||||
fraction: fraction,
|
||||
size: ImVec2::new(-1.0, 0.0),
|
||||
overlay_text: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets an optional text that will be drawn over the progress bar.
|
||||
#[inline]
|
||||
pub fn overlay_text(mut self, overlay_text: ImStr<'p>) -> Self {
|
||||
self.overlay_text = Some(overlay_text);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the size of the progress bar. Negative values will automatically
|
||||
/// align to the end of the axis, zero will let the progress bar choose a
|
||||
/// size and positive values will use the given size.
|
||||
#[inline]
|
||||
pub fn size(mut self, size: ImVec2) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
/// Builds the progress bar. This has to be called after setting all parameters
|
||||
/// of the progress bar, otherwise the it will not be shown.
|
||||
pub fn build(self) {
|
||||
unsafe {
|
||||
imgui_sys::igProgressBar(self.fraction,
|
||||
&self.size,
|
||||
self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user