libnotcurses_sys/fade.rs
1//! `NcFadeCb` & `NcFadeCtx`
2
3// functions already exported by bindgen : 3
4// -------------------------------------------
5// (#) test: 0
6// (W) wrap: 3 / 0
7// -------------------------------------------
8//W ncfadectx_free
9//W ncfadectx_iterations
10//W ncfadectx_setup
11
12use core::ffi::c_void;
13
14use crate::{
15 c_api::{self, NcResult_i32},
16 Nc, NcPlane, NcTime,
17};
18
19/// Called for each fade iteration on a fading [`NcPlane`].
20///
21/// If anything but 0 is returned, the fading operation ceases immediately,
22/// and that value is propagated out.
23///
24/// The recommended absolute display time target is passed in 'tspec'.
25pub type NcFadeCb =
26 Option<unsafe extern "C" fn(*mut Nc, *mut NcPlane, *const NcTime, *mut c_void) -> NcResult_i32>;
27
28/// Context for a palette fade operation
29pub type NcFadeCtx = crate::c_api::ffi::ncfadectx;
30
31impl NcFadeCtx {
32 /// `NcFadeCtx` constructor.
33 ///
34 /// Rather than the simple ncplane_fade{in/out}(),
35 /// ncfadectx_setup() can be paired with a loop over
36 /// ncplane_fade{in/out}_iteration() + ncfadectx_free().
37 pub fn setup(plane: &mut NcPlane) -> &mut NcFadeCtx {
38 unsafe { &mut *c_api::ncfadectx_setup(plane) }
39 }
40
41 /// Releases the resources associated.
42 pub fn free(&mut self) {
43 unsafe {
44 c_api::ncfadectx_free(self);
45 }
46 }
47
48 /// Returns the number of iterations through which will fade.
49 pub fn iterations(&self) -> u32 {
50 unsafe { c_api::ncfadectx_iterations(self) as u32 }
51 }
52}