+notcurses_align & modify ncplane_align #937

pull/944/head
joseLuís 4 years ago
parent 80c66d5d7a
commit 246cde91f9

@ -38,9 +38,10 @@
//
// static inline functions to reimplement: 4
// ----------------------------------------- (done / (x) wont / remaining)
// (+) implement : 4 / 0 / 0
// (#) unit tests: 0 / 0 / 4
// (+) implement : 4 / 0 / 1
// (#) unit tests: 0 / 0 / 5
// -----------------------------------------
//+notcurses_align
//+notcurses_getc_blocking
//+notcurses_getc_nblock
//+notcurses_stddim_yx
@ -49,7 +50,23 @@
use core::ptr::null;
use crate as nc;
use nc::{ncinput, ncplane, notcurses};
use nc::types::{Align, Input, FullMode, Plane, ALIGN_CENTER, ALIGN_LEFT};
/// return the offset into 'availcols' at which 'cols' ought be output given the requirements of 'align'
// TODO: TEST
#[inline]
pub fn notcurses_align(availcols: i32, align: Align, cols: i32) -> i32 {
if align == ALIGN_LEFT {
return 0;
}
if cols > availcols {
return 0;
}
if align == ALIGN_CENTER {
return (availcols - cols) / 2;
}
availcols - cols // ALIGN_RIGHT
}
/// 'input' may be NULL if the caller is uninterested in event details.
/// If no event is ready, returns 0.

@ -144,7 +144,7 @@ use cstr_core::CString;
use crate as nc;
use nc::types::{
Align, AlphaBits, Cell, Channel, ChannelPair, Color, EGCBackstop, IntResult, Plane, StyleMask,
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, EGC,
EGC,
};
/// Return the column at which 'cols' columns ought start in order to be aligned
@ -155,21 +155,7 @@ use nc::types::{
// TODO: TEST
#[inline]
pub fn ncplane_align(plane: &Plane, align: Align, cols: i32) -> i32 {
if align == ALIGN_LEFT {
return 0;
}
let plane_cols = ncplane_dim_x(plane);
if cols > plane_cols {
return 0;
}
if align == ALIGN_CENTER {
return plane_cols - cols / 2;
} else if align == ALIGN_RIGHT {
return plane_cols - cols;
}
core::i32::MAX
nc::notcurses_align(nc::ncplane_dim_x(plane), align, cols)
}
/// Retrieve the current contents of the cell under the cursor into 'cell'.

Loading…
Cancel
Save