rust: make modifications to match v2.1.2

- add new ffi::functions: ncplane_resize_maximize, notcurses_cansextant,
- substitute rust reimplementions of ncplane_at_cursor_cell & ncplane_at_yx_cell by ffi ones.
- substitute ncvisual_default_blitter by ncvisual_defblitter.
- rename cell style functions
pull/1259/head
joseLuís 4 years ago
parent 55d49a43f6
commit 9dda358364

@ -326,7 +326,9 @@ pub use ffi::{
// functions
ncplane_above,
ncplane_at_cursor,
ncplane_at_cursor_cell,
ncplane_at_yx,
ncplane_at_yx_cell,
ncplane_base,
ncplane_below,
ncplane_box,
@ -382,8 +384,9 @@ pub use ffi::{
ncplane_reparent,
ncplane_reparent_family,
ncplane_resize,
ncplane_resize_realign,
ncplane_resizecb,
ncplane_resize_maximize,
ncplane_resize_realign,
ncplane_rgba,
ncplane_rotate_ccw,
ncplane_rotate_cw,
@ -636,6 +639,7 @@ pub use ffi::{
ncvisual_from_plane,
ncvisual_from_rgba,
ncvisual_geom,
ncvisual_media_defblitter,
ncvisual_polyfill_yx,
ncvisual_render,
ncvisual_resize,
@ -673,6 +677,7 @@ pub use ffi::{
notcurses_canopen_images,
notcurses_canopen_videos,
notcurses_cansixel,
notcurses_cansextant,
notcurses_cantruecolor,
notcurses_canutf8,
notcurses_cursor_disable,
@ -687,8 +692,6 @@ pub use ffi::{
notcurses_lex_scalemode,
notcurses_linesigs_disable,
notcurses_linesigs_enable,
// Waiting for: https://github.com/dankamongmen/notcurses/issues/1114
// notcurses_media_defblitter,
notcurses_mouse_disable,
notcurses_mouse_enable,
notcurses_palette_size,

@ -9,10 +9,10 @@
// cells_double_box
// cells_rounded_box
//
// functions manually reimplemented: 42
// functions manually reimplemented: 43
// ------------------------------------------
// (X) wont: 2
// (+) done: 40 / 0
// (+) done: 40
// (W) wrap: 27
// (#) test: 26
// ------------------------------------------
@ -35,6 +35,9 @@
//W# cell_fg_rgb8
// + cell_init
// + cell_load_char
// cell_load_egc32
// + cell_off_styles
// + cell_on_styles
// + cell_prime
//W# cell_set_bchannel
//W# cell_set_bg_alpha
@ -50,12 +53,10 @@
//W# cell_set_fg_rgb
//W# cell_set_fg_rgb8
// X cell_set_fg_rgb8_clipped // unneeded
// + cell_set_styles
// + cells_load_box
// + cell_strdup
// + cell_styles
// + cell_styles_off
// + cell_styles_on
// + cell_styles_set
// + cell_wide_left_p
// + cell_wide_right_p

@ -289,7 +289,7 @@ pub const fn cell_styles(cell: &NcCell) -> NcStyleMask {
///
/// *Method: NcCell.[styles_on()][NcCell#method.styles_on].*
#[inline]
pub fn cell_styles_on(cell: &mut NcCell, stylebits: NcStyleMask) {
pub fn cell_on_styles(cell: &mut NcCell, stylebits: NcStyleMask) {
cell.stylemask |= stylebits & NCSTYLE_MASK as u16;
}
@ -297,7 +297,7 @@ pub fn cell_styles_on(cell: &mut NcCell, stylebits: NcStyleMask) {
///
/// *Method: NcCell.[styles_off()][NcCell#method.styles_off].*
#[inline]
pub fn cell_styles_off(cell: &mut NcCell, stylebits: NcStyleMask) {
pub fn cell_off_styles(cell: &mut NcCell, stylebits: NcStyleMask) {
cell.stylemask &= !(stylebits & NCSTYLE_MASK as u16);
}
@ -306,7 +306,7 @@ pub fn cell_styles_off(cell: &mut NcCell, stylebits: NcStyleMask) {
///
/// *Method: NcCell.[styles_set()][NcCell#method.styles_set].*
#[inline]
pub fn cell_styles_set(cell: &mut NcCell, stylebits: NcStyleMask) {
pub fn cell_set_styles(cell: &mut NcCell, stylebits: NcStyleMask) {
cell.stylemask = stylebits & NCSTYLE_MASK as u16;
}

@ -1,10 +1,10 @@
//! `NcDirect`
// functions already exported by bindgen : 38
// functions already exported by bindgen : 40
// ------------------------------------------
// (X) wont: 1
// (#) test: 0
// (W) wrap: 37 / 0
// (W) wrap: 39 / 0
// ------------------------------------------
//W ncdirect_bg_default
//W ncdirect_bg_palindex

@ -211,6 +211,13 @@ impl Notcurses {
unsafe { crate::notcurses_cansixel(self) }
}
/// Returns true if we can reliably use Unicode 13 sextants.
///
/// *C style function: [notcurses_cansextant()][crate::notcurses_cansextant].*
pub fn cansextant(&self) -> bool {
unsafe { crate::notcurses_cansextant(self) }
}
/// Returns true if it's possible to directly specify RGB values per cell,
/// or false if it's only possible to use palettes.
///

@ -1,9 +1,9 @@
//! `Notcurses`
// functions already exported by bindgen : 41
// functions already exported by bindgen : 42
// ------------------------------------------
// (#) test: 10
// (W) wrap: 40 / 1
// (W) wrap: 41 / 1
// ------------------------------------------
//W notcurses_at_yx
//W notcurses_bottom
@ -12,6 +12,7 @@
//W# notcurses_canopen_images
//W# notcurses_canopen_videos
//W# notcurses_cansixel
//W# notcurses_cansextant
//W# notcurses_cantruecolor
//W# notcurses_canutf8
//W notcurses_cursor_disable

@ -76,6 +76,17 @@ fn notcurses_cansixel() {
}
}
#[test]
#[serial]
fn notcurses_cansextant() {
unsafe {
let nc = notcurses_init_test();
let res = crate::notcurses_cansextant(nc);
notcurses_stop(nc);
print!("[{}] ", res);
}
}
#[test]
#[serial]
fn notcurses_cantruecolor() {

@ -493,14 +493,16 @@ impl NcPlane {
Some(egc)
}
/// Retrieves the current contents of the [NcCell] under the cursor.
/// Retrieves the current contents of the [NcCell] under the cursor
/// into `cell`. Returns the number of bytes in the [NcEgc].
///
/// This NcCell is invalidated if the associated NcPlane is destroyed.
///
/// *C style function: [ncplane_at_cursor_cell()][crate::ncplane_at_cursor_cell].*
#[inline]
pub fn at_cursor_cell(&mut self, cell: &mut NcCell) -> NcResult<()> {
error![crate::ncplane_at_cursor_cell(self, cell)]
pub fn at_cursor_cell(&mut self, cell: &mut NcCell) -> NcResult<u32> {
let bytes = unsafe { crate::ncplane_at_cursor_cell(self, cell) };
error![bytes, bytes as u32]
}
/// Retrieves the current contents of the specified [NcCell], returning the
@ -525,7 +527,9 @@ impl NcPlane {
}
/// Retrieves the current contents of the specified [NcCell] into `cell`.
/// This cell is invalidated if the associated plane is destroyed.
/// Returns the number of bytes in the [NcEgc].
///
/// This NcCell is invalidated if the associated plane is destroyed.
///
/// *C style function: [ncplane_at_yx_cell()][crate::ncplane_at_yx_cell].*
#[inline]
@ -534,8 +538,9 @@ impl NcPlane {
y: NcDimension,
x: NcDimension,
cell: &mut NcCell,
) -> NcResult<()> {
error![crate::ncplane_at_yx_cell(self, y, x, cell)]
) -> NcResult<u32> {
let bytes = unsafe { crate::ncplane_at_yx_cell(self, y as i32, x as i32, cell) };
error![bytes, bytes as u32]
}
/// Extracts this NcPlane's base [NcCell] into `cell`.

@ -1,10 +1,11 @@
//! `NcPlane`
// functions already exported by bindgen : 102
// -------------------------------------------
// functions already exported by bindgen : 108 (5 + 103)
// -----------------------------------------------------
// (X) wont: 6
// (D) depr: 4
// (#) test: 13
// (W) wrap: 77
// (W) wrap: 77 of 98
// -------------------------------------------
//W ncpile_bottom
//W# ncpile_create
@ -13,7 +14,9 @@
//W ncpile_top
//W ncplane_above
//W ncplane_at_cursor
//W ncplane_at_cursor_cell
//W ncplane_at_yx
//W ncplane_at_yx_cell
//W ncplane_base
//W ncplane_below
//W ncplane_box
@ -45,6 +48,7 @@
//W ncplane_move_bottom
//W ncplane_move_top
//W ncplane_move_yx
// X ncplane_new // deprecated
//W# ncplane_notcurses
//W# ncplane_notcurses_const
//W ncplane_off_styles
@ -70,6 +74,7 @@
//W ncplane_reparent_family
//W# ncplane_resize
//W ncplane_resizecb
// ncplane_resize_maximize
//W ncplane_resize_realign
// ncplane_rgba
//W ncplane_rotate_ccw
@ -97,6 +102,9 @@
// ncplane_set_userptr
//W ncplane_stain
//W ncplane_styles
// X ncplane_styles_off // deprecated
// X ncplane_styles_on // deprecated
// X ncplane_styles_set // deprecated
//W ncplane_translate
//W ncplane_translate_abs
// ncplane_userptr
@ -108,16 +116,14 @@
//W ncplane_y
//W ncplane_yx
//
// functions manually reimplemented: 41
// functions manually reimplemented: 39
// ------------------------------------------
// (X) wont: 9
// (+) done: 34 / 0
// (+) done: 32 / 0
// (W) wrap: 24
// (#) test: 5
// ------------------------------------------
//W+ ncplane_align
//W+ ncplane_at_cursor_cell
//W+ ncplane_at_yx_cell
//W+ ncplane_bchannel
//W+ ncplane_bg_alpha
//W# ncplane_bg_default_p

@ -1,7 +1,6 @@
//! `ncplane_*` reimplemented functions.
use core::{ffi::c_void, ptr::null_mut};
use libc::free;
use core::ptr::null_mut;
use crate::ffi::__va_list_tag;
use crate::{
@ -174,61 +173,6 @@ pub fn ncplane_vprintf(plane: &mut NcPlane, format: &str, ap: &mut __va_list_tag
unsafe { crate::ncplane_vprintf_yx(plane, -1, -1, cstring![format], ap) }
}
// NcCell ----------------------------------------------------------------------
/// Retrieves the current contents of the [NcCell] under the cursor.
///
/// This NcCell is invalidated if the associated NcPlane is destroyed.
///
/// *Method: NcPlane.[at_cursor_cell()][NcPlane#method.at_cursor_cell].*
#[inline]
pub fn ncplane_at_cursor_cell(plane: &mut NcPlane, cell: &mut NcCell) -> NcIntResult {
let mut egc =
unsafe { crate::ncplane_at_cursor(plane, &mut cell.stylemask, &mut cell.channels) };
if egc.is_null() {
return NCRESULT_ERR;
}
let result: NcIntResult = unsafe { crate::cell_load(plane, cell, egc) };
if result != NCRESULT_OK {
unsafe {
free(&mut egc as *mut _ as *mut c_void);
}
}
result
}
/// Retrieves the current contents of the specified cell into `cell`.
/// This cell is invalidated if the associated plane is destroyed.
///
/// *Method: NcPlane.[at_yx_cell()][NcPlane#method.at_yx_cell].*
#[inline]
pub fn ncplane_at_yx_cell(
plane: &mut NcPlane,
y: NcDimension,
x: NcDimension,
cell: &mut NcCell,
) -> NcIntResult {
let mut egc = unsafe {
crate::ncplane_at_yx(
plane,
y as i32,
x as i32,
&mut cell.stylemask,
&mut cell.channels,
)
};
if egc.is_null() {
return NCRESULT_ERR;
}
let channels = cell.channels; // need to preserve wide flag
let result: NcIntResult = unsafe { crate::cell_load(plane, cell, egc) };
cell.channels = channels;
unsafe {
free(&mut egc as *mut _ as *mut c_void);
}
result
}
// size & alignment ------------------------------------------------------------
/// Gets the columns of the [NcPlane].

@ -2,9 +2,10 @@
// TODO: implement constructors
// functions already exported by bindgen : 17
// functions already exported by bindgen : 18
// -----------------------------------------
// (#) test: 0 / 17
// (W) wrap: 0
// (#) test: 0
// -----------------------------------------
// ncvisual_at_yx
// ncvisual_decode
@ -15,6 +16,7 @@
// ncvisual_from_plane
// ncvisual_from_rgba
// ncvisual_geom
// ncvisual_media_defblitter
// ncvisual_polyfill_yx
// ncvisual_render
// ncvisual_resize
@ -23,15 +25,6 @@
// ncvisual_simple_streamer
// ncvisual_stream
// ncvisual_subtitle
//
// functions manually reimplemented: 1
// ------------------------------------------
// (+) done: 1 / 0
// (#) test: 0 / 1
// ------------------------------------------
// + ncvisual_default_blitter
use crate::{NCBLIT_1x1, NCBLIT_2x1, NCBLIT_2x2, NcBlitter};
/// How to scale an [`NcVisual`] during rendering
///
@ -59,23 +52,3 @@ pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::ffi::NCVISUAL_OPTION_BLE
/// Fails rather than degrade.
pub const NCVISUAL_OPTION_NODEGRADE: u32 = crate::bindings::ffi::NCVISUAL_OPTION_NODEGRADE;
/// Returns the best default blitter available
///
/// NCBLIT_3x2 is better image quality, especially for large images, but
/// it's not the general default because it doesn't preserve aspect ratio.
/// NCSCALE_STRETCH throws away aspect ratio, and can safely use NCBLIT_3x2.
#[deprecated(
since = "2.1.2",
note = "please use `notcurses_media_defblitter` instead"
)]
// Waiting for: https://github.com/dankamongmen/notcurses/issues/1114
pub fn ncvisual_default_blitter(utf8: bool, scale: NcScale) -> NcBlitter {
if utf8 {
if scale == NCSCALE_STRETCH {
return NCBLIT_2x2;
}
return NCBLIT_2x1;
}
NCBLIT_1x1
}

Loading…
Cancel
Save