rust: add NcProgBar widget

pull/1253/head
joseLuís 4 years ago
parent 4c048ef625
commit af11b123fa

@ -484,6 +484,27 @@ pub use ffi::{
ncreader_write_egc,
};
// ncprogbar -------------------------------------------------------------------
//
// already wrapped:
//
// // structs
// ncprogbar,
// ncprogbar_options,
//
// // constants
// NCPROGBAR_OPTION_RETROGRADE
#[doc(inline)]
pub use ffi::{
// functions
ncprogbar_create,
ncprogbar_destroy,
ncprogbar_plane,
ncprogbar_progress,
ncprogbar_set_progress,
};
// ncreel ----------------------------------------------------------------------
//
// already wrapped:

@ -3,6 +3,7 @@
mod menu;
mod multiselector;
mod plot;
mod progbar;
mod reader;
mod reel;
mod selector;
@ -10,6 +11,7 @@ mod selector;
pub use menu::*;
pub use multiselector::*;
pub use plot::*;
pub use progbar::*;
pub use reader::*;
pub use reel::*;
pub use selector::*;

@ -0,0 +1,67 @@
//! `NcProgBar` & `NcProgBarOptions` methods and associated functions.
use crate::{NcPlane, NcProgBar, NcProgBarOptions, NcResult};
/// # `NcProgBarOptions` Methods
impl NcProgBarOptions {
/// New NcProgBarOptions for [NcProgBar].
pub fn new() -> Self {
Self {
ulchannel: 0,
urchannel: 0,
blchannel: 0,
brchannel: 0,
flags: 0,
}
}
}
/// # `NcProgBar` Methods
impl NcProgBar {
/// New NcProgBar.
///
/// Takes ownership of the `plane`, which will be destroyed by
/// [destroy][NcProgBar#method.destroy](). The progress bar is initially at 0%.
pub fn new<'a>(plane: &mut NcPlane) -> &'a mut Self {
Self::with_options(plane, &NcProgBarOptions::new())
}
/// New NcProgBar. Expects an [NcProgBarOptions] struct.
///
/// C style function: [ncprogbar_create][crate::ncprogbar_create]
pub fn with_options<'a>(plane: &mut NcPlane, options: &NcProgBarOptions) -> &'a mut Self {
unsafe { &mut *crate::ncprogbar_create(plane, options) }
}
/// Destroy the progress bar and its underlying ncplane.
///
/// C style function: [ncprogbar_destroy][crate::ncprogbar_destroy]
pub fn destroy(&mut self) {
unsafe {
crate::ncprogbar_destroy(self);
}
}
/// Return a reference to the ncprogbar's underlying ncplane.
///
/// C style function: [ncprogbar_plane][crate::ncprogbar_plane]
pub fn plane<'a>(&'a mut self) -> &'a mut NcPlane {
unsafe { &mut *crate::ncprogbar_plane(self) }
}
/// Get the progress bar's completion, an [f64] on [0, 1].
///
/// C style function: [ncprogbar_progress][crate::ncprogbar_progress]
pub fn progress(&self) -> f64 {
unsafe { crate::ncprogbar_progress(self) }
}
/// Sets the progress bar's completion, an 0 <= [f64] <= 1.
///
/// Returns [NCRESULT_ERR][crate::NCRESULT_ERR] if progress is < 0 || > 1.
///
/// C style function: [ncprogbar_set_progress][crate::ncprogbar_set_progress]
pub fn set_progress(&mut self, progress: f64) -> NcResult {
unsafe { crate::ncprogbar_set_progress(self, progress) }
}
}

@ -0,0 +1,43 @@
//! `NcProgbar` widget.
// functions already exported by bindgen : 5
// -----------------------------------------
// (#) test: 0
// (W) wrap: 5 / 0
// -----------------------------------------
//W ncprogbar_create,
//W ncprogbar_destroy,
//W ncprogbar_plane,
//W ncprogbar_progress,
//W ncprogbar_set_progress,
mod methods;
/// Progress bars. They proceed linearly in any of four directions.
///
/// The entirety of the plane will be used -- any border should be provided by
/// the caller on another plane.
///
/// The plane will not be erased; text preloaded into the plane will be consumed
/// by the progress indicator.
///
/// The bar is redrawn for each provided progress report (a double between 0
/// and 1), and can regress with lower values.
///
/// The procession will take place along the longer dimension at the time of each
/// redraw, with the horizontal length scaled by 2 for purposes of comparison.
/// I.e. for a plane of 20 rows and 50 columns, the progress will be to the
/// right (50 > 40), or left with [NCPROGBAR_OPTION_RETROGRADE].
///
/// `type in C: ncprogbar (struct)`
///
pub type NcProgBar = crate::bindings::ffi::ncprogbar;
/// Options struct for [`NcProgBar`]
///
/// `type in C: ncprogbar_options (struct)`
///
pub type NcProgBarOptions = crate::bindings::ffi::ncprogbar_options;
/// proceed left/down
pub const NCPROGBAR_OPTION_RETROGRADE: u32 = crate::bindings::ffi::NCPROGBAR_OPTION_RETROGRADE;
Loading…
Cancel
Save