@ -2,26 +2,33 @@
use core ::ptr ::{ null , null_mut } ;
use core ::ptr ::{ null , null_mut } ;
// for constructors
use crate ::{
use crate ::{
ncpile_create , ncplane_create , notcurses_term_dim_yx , NcAlign , NcPlane , NcPlaneOptions ,
ncpile_create , ncplane_create , notcurses_term_dim_yx , NcAlign , NcPlane , NcPlaneOptions ,
Notcurses , NCPLANE_OPTION_HORALIGNED ,
Notcurses , NCPLANE_OPTION_HORALIGNED ,
} ;
} ;
// for methods
use crate ::{
NcCell , NcResult , ncplane_cursor_yx , ncplane_dim_yx , ncplane_erase , ncplane_putc , ncplane_putc_yx ,
} ;
/// # `NcPlaneOptions` Constructors
impl NcPlaneOptions {
impl NcPlaneOptions {
/// [`NcPlaneOptions`] simple constructor with horizontal x
/// New NcPlaneOptions using the horizontal x.
pub fn new ( y : i32 , x : i32 , rows : u32 , cols : u32 ) -> Self {
pub fn new ( y : i32 , x : i32 , rows : u32 , cols : u32 ) -> Self {
Self ::with_flags ( y , x , rows , cols , 0 )
Self ::with_flags ( y , x , rows , cols , 0 )
}
}
/// [`NcPlaneOptions`] simple constructor with horizontal alignment
/// New NcPlaneOptions with horizontal alignment.
pub fn new_halign ( y : i32 , align : NcAlign , rows : u32 , cols : u32 ) -> Self {
pub fn new_halign ( y : i32 , align : NcAlign , rows : u32 , cols : u32 ) -> Self {
Self ::with_flags ( y , align as i32 , rows , cols , NCPLANE_OPTION_HORALIGNED )
Self ::with_flags ( y , align as i32 , rows , cols , NCPLANE_OPTION_HORALIGNED )
}
}
/// [`NcPlaneOptions`] constructor
/// New NcPlaneOptions, with flags.
///
///
/// Note: If you use `NCPLANE_OPTION_HORALIGNED` flag, you must provide
/// Note: If you use [NCPLANE_OPTION_HORALIGNED] flag, you must provide
/// the `NcAlign` value as the `x` parameter, casted to `i32`.
/// the [NcAlign] value to the `x` parameter, casted to `i32`.
pub fn with_flags ( y : i32 , x : i32 , rows : u32 , cols : u32 , flags : u64 ) -> Self {
pub fn with_flags ( y : i32 , x : i32 , rows : u32 , cols : u32 , flags : u64 ) -> Self {
NcPlaneOptions {
NcPlaneOptions {
y ,
y ,
@ -36,8 +43,9 @@ impl NcPlaneOptions {
}
}
}
}
/// # `NcPlane` Constructors
impl NcPlane {
impl NcPlane {
/// [`NcPlane`] constructor
/// New NcPlane.
///
///
/// The returned plane will be the top, bottom, and root of this new pile.
/// The returned plane will be the top, bottom, and root of this new pile.
pub unsafe fn new < ' a > (
pub unsafe fn new < ' a > (
@ -51,7 +59,7 @@ impl NcPlane {
& mut * ncpile_create ( nc , & options )
& mut * ncpile_create ( nc , & options )
}
}
/// [`NcPlane`] constructor, expecting an [`NcPlaneOptions`] struct
/// New NcPlane, expects an [NcPlaneOptions] struct.
///
///
/// The returned plane will be the top, bottom, and root of this new pile.
/// The returned plane will be the top, bottom, and root of this new pile.
pub unsafe fn with_options < ' a > (
pub unsafe fn with_options < ' a > (
@ -61,7 +69,7 @@ impl NcPlane {
& mut * ncpile_create ( nc , options )
& mut * ncpile_create ( nc , options )
}
}
/// [`NcPlane`] constructor, bound to another plane
/// New NcPlane, bound to another NcPlane.
pub unsafe fn new_bound < ' a > (
pub unsafe fn new_bound < ' a > (
bound_to : & mut NcPlane ,
bound_to : & mut NcPlane ,
y : i32 ,
y : i32 ,
@ -73,8 +81,7 @@ impl NcPlane {
& mut * ncplane_create ( bound_to , & options )
& mut * ncplane_create ( bound_to , & options )
}
}
/// [`NcPlane`] constructor, bound to another plane,
/// New NcPlane, bound to another plane, expects an [NcPlaneOptions] struct.
/// expecting an [`NcPlaneOptions`] struct
///
///
/// The returned plane will be the top, bottom, and root of this new pile.
/// The returned plane will be the top, bottom, and root of this new pile.
pub unsafe fn with_options_bound < ' a > (
pub unsafe fn with_options_bound < ' a > (
@ -84,10 +91,9 @@ impl NcPlane {
& mut * ncpile_create ( nc , options )
& mut * ncpile_create ( nc , options )
}
}
/// [`NcPlane`] constructor , with the same dimensions of the terminal.
/// New NcPlane , with the same dimensions of the terminal.
///
///
/// The returned plane will be the top, bottom, and root of this new pile.
/// The returned plane will be the top, bottom, and root of this new pile.
// FIXME BUG
pub unsafe fn new_termsize < ' a > ( nc : & mut Notcurses ) -> & ' a mut NcPlane {
pub unsafe fn new_termsize < ' a > ( nc : & mut Notcurses ) -> & ' a mut NcPlane {
let ( mut trows , mut tcols ) = ( 0 , 0 ) ;
let ( mut trows , mut tcols ) = ( 0 , 0 ) ;
notcurses_term_dim_yx ( nc , & mut trows , & mut tcols ) ;
notcurses_term_dim_yx ( nc , & mut trows , & mut tcols ) ;
@ -95,3 +101,58 @@ impl NcPlane {
& mut * ncpile_create ( nc , & NcPlaneOptions ::new ( 0 , 0 , trows as u32 , tcols as u32 ) )
& mut * ncpile_create ( nc , & NcPlaneOptions ::new ( 0 , 0 , trows as u32 , tcols as u32 ) )
}
}
}
}
/// # `NcPlane` Methods
impl NcPlane {
/// Returns the current position of the cursor within the [NcPlane].
///
/// Unlike [ncplane_cursor_yx] which uses `i32`, this uses [u32].
//
// NOTE: y and/or x may be NULL.
// FIXME: CHECK for NULL and return Some() or None.
pub fn cursor_yx ( & self ) -> ( u32 , u32 ) {
let ( mut y , mut x ) = ( 0 , 0 ) ;
unsafe { ncplane_cursor_yx ( self , & mut y , & mut x ) } ;
( y as u32 , x as u32 )
}
/// Returns the current row of the cursor within the [NcPlane].
pub fn cursor_y ( & self ) -> u32 {
self . cursor_yx ( ) . 0
}
/// Returns the current column of the cursor within the [NcPlane].
pub fn cursor_x ( & self ) -> u32 {
self . cursor_yx ( ) . 1
}
/// Return the dimensions of this [NcPlane].
///
/// Unlike [ncplane_dim_yx] which uses `i32`, this uses [u32].
pub fn dim_yx ( & self ) -> ( u32 , u32 ) {
let ( mut y , mut x ) = ( 0 , 0 ) ;
unsafe { ncplane_dim_yx ( self , & mut y , & mut x ) } ;
( y as u32 , x as u32 )
}
/// Return the rows of this [NcPlane].
pub fn dim_y ( & self ) -> u32 {
self . dim_yx ( ) . 0
}
/// Return the columns of this [NcPlane].
pub fn dim_x ( & self ) -> u32 {
self . dim_yx ( ) . 1
}
///
// FIXME segfaults
pub fn putc_yx ( & mut self , y : i32 , x : i32 , cell : & NcCell ) -> NcResult {
unsafe { ncplane_putc_yx ( self , y , x , cell ) }
}
// ///
// pub fn putc(&mut self) -> NcResult {
// unsafe { ncplane_putc(self) }
// }
}