From acbd0ffeebed11a4789f24b9a3043fa2e49fe237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Sat, 31 Jul 2021 17:10:55 +0200 Subject: [PATCH] [rust] add nccell_cols, deprecate nccell_width --- rust/src/bindings.rs | 1 - rust/src/cells/mod.rs | 2 +- rust/src/cells/reimplemented.rs | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/rust/src/bindings.rs b/rust/src/bindings.rs index 9e337fb43..0f9c39fd1 100644 --- a/rust/src/bindings.rs +++ b/rust/src/bindings.rs @@ -63,7 +63,6 @@ pub use ffi::{ nccell_extended_gcluster, nccell_load, nccell_release, - nccell_width, nccells_double_box, nccells_rounded_box, }; diff --git a/rust/src/cells/mod.rs b/rust/src/cells/mod.rs index 4e14fa721..6263b8e98 100644 --- a/rust/src/cells/mod.rs +++ b/rust/src/cells/mod.rs @@ -7,7 +7,6 @@ // ------------------------------------------ //… nccell_extended_gcluster //… nccell_load -// nccell_width //W nccells_double_box //W nccells_rounded_box //W nccell_duplicate @@ -26,6 +25,7 @@ //W# nccell_bg_palindex_p //W# nccell_bg_rgb //W# nccell_bg_rgb8 +// + nccell_cols //W+ nccell_double_wide_p //W+ nccell_extract //W# nccell_fchannel diff --git a/rust/src/cells/reimplemented.rs b/rust/src/cells/reimplemented.rs index 00bb3c6c4..343c80fcf 100644 --- a/rust/src/cells/reimplemented.rs +++ b/rust/src/cells/reimplemented.rs @@ -289,6 +289,22 @@ pub fn nccell_set_styles(cell: &mut NcCell, stylebits: NcStyle) { // Chars ----------------------------------------------------------------------- +/// Returns the number of columns occupied by 'c'. see ncstrwidth() for an +/// equivalent for multiple EGCs. +#[inline] +pub const fn nccell_cols(cell: &NcCell) -> u8 { + if cell.width != 0 { + cell.width + } else { + 1 + } +} + +#[deprecated] +pub fn nccell_width(plane: &NcPlane, cell: &NcCell) -> NcIntResult { + unsafe { crate::ffi::nccell_width(plane, cell) } +} + /// Does the [`NcCell`] contain an East Asian Wide codepoint? /// /// *Method: NcCell.[double_wide_p()][NcCell#method.double_wide_p].*