Files
imhex/plugins/libimhex-rust/imgui-rs/src/widget/progress_bar.rs
WerWolv 46ba46ce9d build/plugins: Added initial support for Rust plugins (#327)
* build: Added initial support for Rust plugins

* github: Install correct rust version

* github: Fixed rustup command

* github: Fix swapped win/linux commands

* github: Install linux rust toolchain on Linux

* github: Add rustup parameters to correct command

* build: libimhex-rust -> hex

* rust-plugins: Disable optimization to export functions correctly

* build: Use cdylib instead of dylib

* build: Fixed rust building and artifact copying

* build: Fixed installing plugins

* build: Fix copying and installing on Windows

* github: Added windows debugging

* github: Use curl instead of wget

* github: Added debug on failure

* github: Update path variable with rust toolchain path

* build/github: Set rust location so cmake can find it

* build: Remove leftovers

* api: Added rust wrappers for the ImHexAPI

* rust: Fixed compile flags with older gcc/clang

* build: Enable concepts for cxx.rs

* build: Explicitly set compiler for cxx.rs

* rust: Added imgui-rs to libimhex-rust

* rust: Export functions with double underscore prefix on mac

* rust: Export functions adjusted for ABI

* Add Rust target folder to gitignore

* Add vendored imgui-rs copy

* Add Context::current() to vendored imgui-rs

* Fix libimhex not exporting cimgui symbols

* Simplify plugin export mangling

* build: Fixed cimgui linking

* build: Only specify --export-all-symbols on Windows

* Add context setting to Rust plugins

* rust: Cleanup

* deps: Update curl

Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00

74 lines
1.9 KiB
Rust
Vendored

use crate::sys;
// use crate::ImStr;
use crate::Ui;
/// Builder for a progress bar widget.
///
/// # Examples
///
/// ```no_run
/// # use imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// ProgressBar::new(0.6)
/// .size([100.0, 12.0])
/// .overlay_text("Progress!")
/// .build(&ui);
/// ```
#[derive(Copy, Clone, Debug)]
#[must_use]
pub struct ProgressBar<T = &'static str> {
fraction: f32,
size: [f32; 2],
overlay_text: Option<T>,
}
impl ProgressBar {
/// 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.
#[inline]
#[doc(alias = "ProgressBar")]
pub fn new(fraction: f32) -> Self {
ProgressBar {
fraction,
size: [-1.0, 0.0],
overlay_text: None,
}
}
}
impl<T: AsRef<str>> ProgressBar<T> {
/// Sets an optional text that will be drawn over the progress bar.
pub fn overlay_text<T2: AsRef<str>>(self, overlay_text: T2) -> ProgressBar<T2> {
ProgressBar {
fraction: self.fraction,
size: self.size,
overlay_text: Some(overlay_text),
}
}
/// 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: [f32; 2]) -> Self {
self.size = size;
self
}
/// Builds the progress bar
pub fn build(self, ui: &Ui<'_>) {
unsafe {
sys::igProgressBar(
self.fraction,
self.size.into(),
ui.scratch_txt_opt(self.overlay_text),
);
}
}
}