rust: +14 cell functions

WIP: cell_prime & cells_load_box
pull/922/head
joseLuís 4 years ago
parent 5eb9dc37d4
commit 154d3ef312

@ -7,47 +7,46 @@
// - cells_double_box // - cells_double_box
// - cells_rounded_box // - cells_rounded_box
// //
// static inline functions to reimplement: 45 // static inline functions to reimplement: 42
// ------------------------------------------ (done / (x) wont / remaining) // ------------------------------------------ (done / (x) wont / remaining)
// (+) implement : 24 / 0 / 21 // (+) implement : 38 / 2 / 2
// (#) unit tests: 0 / 0 / 45 // (#) unit tests: 0 / 2 / 40
// ------------------------------------------ // ------------------------------------------
//+cell_bchannel //+cell_bchannel
// cell_bg //+cell_bg
// cell_bg_alpha //+cell_bg_alpha
// cell_bg_default_p //+cell_bg_default_p
// cell_bg_palindex //+cell_bg_palindex
// cell_bg_palindex_p //+cell_bg_palindex_p
//+cell_bg_rgb //+cell_bg_rgb
//+cellcmp //+cellcmp
//+cell_double_wide_p //+cell_double_wide_p
//+cell_extract //+cell_extract
//+cell_fchannel //+cell_fchannel
// cell_fg //+cell_fg
// cell_fg_alpha //+cell_fg_alpha
// cell_fg_default_p //+cell_fg_default_p
// cell_fg_palindex //+cell_fg_palindex
// cell_fg_palindex_p //+cell_fg_palindex_p
//+cell_fg_rgb //+cell_fg_rgb
//+cell_init //+cell_init
//+cell_load_simple //+cell_load_simple
//+cell_prime // cell_prime // FIXME
//+cell_set_bchannel //+cell_set_bchannel
// cell_set_bg //+cell_set_bg
//+cell_set_bg_alpha //+cell_set_bg_alpha
// cell_set_bg_default //+cell_set_bg_default
// cell_set_bg_palindex //+cell_set_bg_palindex
// cell_set_bg_rgb //+cell_set_bg_rgb
// cell_set_bg_rgb_clipped //xcell_set_bg_rgb_clipped // unneeded
//+cell_set_fchannel //+cell_set_fchannel
// cell_set_fg //+cell_set_fg
//+cell_set_fg_alpha //+cell_set_fg_alpha
//+cell_set_fg_default //+cell_set_fg_default
//+cell_set_fg_palindex //+cell_set_fg_palindex
// cell_set_fg_rgb //+cell_set_fg_rgb
// cell_set_fg_rgb_clipped //xcell_set_fg_rgb_clipped // unneeded
// cell_simple_p // cells_load_box // FIXME
//+cells_load_box // FIXME
//+cell_strdup //+cell_strdup
//+cell_styles //+cell_styles
//+cell_styles_off //+cell_styles_off
@ -59,15 +58,16 @@
use cstr_core::CString; use cstr_core::CString;
use crate as ffi; use crate as ffi;
use ffi::types::{AlphaBits, Channel, ChannelPair, Color, GraphemeCluster, IntResult, StyleMask}; use ffi::types::{AlphaBits, Channel, ChannelPair, Color, GraphemeCluster, IntResult, PaletteIndex, StyleMask};
use ffi::{cell, ncplane}; use ffi::{cell, ncplane};
/// cell_load(), plus blast the styling with 'attr' and 'channels'. /*
/// cell_load(), plus blast the styling with 'style' and 'channels'.
// TODO: TEST // TODO: TEST
pub fn cell_prime( pub fn cell_prime(
plane: &mut ffi::ncplane, plane: &mut ffi::ncplane,
cell: &mut ffi::cell, cell: &mut ffi::cell,
gcluster: &str, gcluster: GraphemeCluster,
style: u16, style: u16,
channels: ChannelPair, channels: ChannelPair,
) -> IntResult { ) -> IntResult {
@ -77,61 +77,67 @@ pub fn cell_prime(
ffi::cell_load(plane, cell, CString::new(gcluster).unwrap().as_ptr()) ffi::cell_load(plane, cell, CString::new(gcluster).unwrap().as_ptr())
} }
} }
// static inline int */
// cell_prime(struct ncplane* n, cell* c, const char* gcluster, /*
// uint32_t attr, uint64_t channels){ /// load up six cells with the EGCs necessary to draw a box.
// c->stylemask = attr; ///
// c->channels = channels; /// returns 0 on success, -1 on error.
// int ret = cell_load(n, c, gcluster); ///
// return ret; /// on error, any cells this function might have loaded before the error
// } /// are cell_release()d. There must be at least six EGCs in gcluster.
///
/// load up six cells with the EGCs necessary to draw a box. returns 0 on // TODO: need clarification: https://github.com/dankamongmen/notcurses/issues/918
/// success, -1 on error. on error, any cells this function might
/// have loaded before the error are cell_release()d. There must be at least
/// six EGCs in gcluster.
// TODO: TEST // TODO: TEST
// FIXME missing cell_prime()s
pub fn cells_load_box( pub fn cells_load_box(
plane: &mut ncplane, plane: &mut ncplane,
style: u16, style: StyleMask,
channels: ChannelPair, channels: ChannelPair,
_ul: &mut cell, ul: &mut cell,
_ur: &mut cell, ur: &mut cell,
_ll: &mut cell, ll: &mut cell,
_lr: &mut cell, lr: &mut cell,
_hl: &mut cell, hl: &mut cell,
_vl: &mut cell, vl: &mut cell,
gcluster: &str, gcluster: GraphemeCluster,
) -> IntResult { ) -> IntResult {
cell_prime(plane, _ul, gcluster, style, channels)
} let mut ulen;
// static inline int ulen = cell_prime(plane, ul, gcluster, style, channels);
// cells_load_box(struct ncplane* n, uint32_t style, uint64_t channels, if ulen > 0 {
// cell* ul, cell* ur, cell* ll, cell* lr,
// cell* hl, cell* vl, const char* gclusters){ ulen = cell_prime(plane, ur, gcluster += ulen, style, channels);
// int ulen; if ulen > 0 {
// if((ulen = cell_prime(n, ul, gclusters, style, channels)) > 0){ }
// if((ulen = cell_prime(n, ur, gclusters += ulen, style, channels)) > 0){
// if((ulen = cell_prime(n, ll, gclusters += ulen, style, channels)) > 0){ }
// if((ulen = cell_prime(n, lr, gclusters += ulen, style, channels)) > 0){
// if((ulen = cell_prime(n, hl, gclusters += ulen, style, channels)) > 0){ }
// if((ulen = cell_prime(n, vl, gclusters += ulen, style, channels)) > 0){ */
// return 0;
// } /*
// cell_release(n, hl); int ulen;
// } if((ulen = cell_prime(n, ul, gclusters, style, channels)) > 0){ // done
// cell_release(n, lr); if((ulen = cell_prime(n, ur, gclusters += ulen, style, channels)) > 0){
// }
// cell_release(n, ll); if((ulen = cell_prime(n, ll, gclusters += ulen, style, channels)) > 0){
// } if((ulen = cell_prime(n, lr, gclusters += ulen, style, channels)) > 0){
// cell_release(n, ur); if((ulen = cell_prime(n, hl, gclusters += ulen, style, channels)) > 0){
// } if((ulen = cell_prime(n, vl, gclusters += ulen, style, channels)) > 0){
// cell_release(n, ul); return 0;
// } }
// return -1; cell_release(n, hl);
// } }
cell_release(n, lr);
}
cell_release(n, ll);
}
cell_release(n, ur);
}
cell_release(n, ul);
}
return -1;
*/
// TODO: TEST // TODO: TEST
@ -342,106 +348,104 @@ pub fn cell_bg_rgb(cell: &cell, red: &mut Color, green: &mut Color, blue: &mut C
ffi::channels_bg_rgb(cell.channels, red, green, blue) ffi::channels_bg_rgb(cell.channels, red, green, blue)
} }
// // Set the r, g, and b cell for the foreground component of this 64-bit /// Set the r, g, and b cell for the foreground component of this 64-bit
// // 'cell' variable, and mark it as not using the default color. /// 'cell' variable, and mark it as not using the default color.
// static inline int // TODO: TEST
// cell_set_fg_rgb(cell* cl, int r, int g, int b){ #[inline]
// return channels_set_fg_rgb(&cl->channels, r, g, b); pub fn cell_set_fg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) {
// } ffi::channels_set_fg_rgb(&mut cell.channels, red, green, blue);
// }
// // Same, but clipped to [0..255].
// static inline void /// Same as `cell_set_fg_rgb()` but with an assembled 24-bit RGB value.
// cell_set_fg_rgb_clipped(cell* cl, int r, int g, int b){ // TODO: TEST
// channels_set_fg_rgb_clipped(&cl->channels, r, g, b); #[inline]
// } pub fn cell_set_fg(cell: &mut cell, channel: Channel) {
// ffi::channels_set_fg(&mut cell.channels, channel);
// // Same, but with an assembled 24-bit RGB value. }
// static inline int
// cell_set_fg(cell* c, uint32_t channel){ /// Set the cell's foreground palette index, set the foreground palette index
// return channels_set_fg(&c->channels, channel); /// bit, set it foreground-opaque, and clear the foreground default color bit.
// } ///
// TODO: TEST
// static inline int // NOTE: this function now can't fail
// cell_set_fg_palindex(cell* cl, int idx){ #[inline]
// if(idx < 0 || idx >= NCPALETTESIZE){ pub fn cell_set_fg_palindex(cell: &mut cell, index: PaletteIndex) {
// return -1; cell.channels |= ffi::CELL_FGDEFAULT_MASK;
// } cell.channels |= ffi::CELL_FG_PALETTE;
// cl->channels |= CELL_FGDEFAULT_MASK; cell_set_fg_alpha(cell, ffi::CELL_ALPHA_OPAQUE);
// cl->channels |= CELL_FG_PALETTE; cell.channels &= 0xff000000ffffffff_u64;
// cell_set_fg_alpha(cl, CELL_ALPHA_OPAQUE); cell.channels |= (index as u64) << 32;
// cl->channels &= 0xff000000ffffffffull; }
// cl->channels |= ((uint64_t)idx << 32u);
// return 0; // TODO: TEST
// } #[inline]
// pub fn cell_fg_palindex(cell: &cell) -> PaletteIndex {
// static inline unsigned ((cell.channels & 0xff00000000_u64) >> 32) as PaletteIndex
// cell_fg_palindex(const cell* cl){ }
// return (cl->channels & 0xff00000000ull) >> 32u;
// } /// Set the r, g, and b cell for the background component of this 64-bit
// /// 'cell' variable, and mark it as not using the default color.
// // Set the r, g, and b cell for the background component of this 64-bit ///
// // 'cell' variable, and mark it as not using the default color. // TODO: TEST
// static inline int #[inline]
// cell_set_bg_rgb(cell* cl, int r, int g, int b){ pub fn cell_set_bg_rgb(cell: &mut cell, red: Color, green: Color, blue: Color) {
// return channels_set_bg_rgb(&cl->channels, r, g, b); ffi::channels_set_bg_rgb(&mut cell.channels, red, green, blue);
// } }
//
// // Same, but clipped to [0..255]. /// Same as `cell_set_fg_rgb()` but with an assembled 24-bit RGB value.
// static inline void ///
// cell_set_bg_rgb_clipped(cell* cl, int r, int g, int b){ // TODO: TEST
// channels_set_bg_rgb_clipped(&cl->channels, r, g, b); #[inline]
// } pub fn cell_set_bg(cell: &mut cell, channel: Channel) {
// ffi::channels_set_bg(&mut cell.channels, channel);
// // Same, but with an assembled 24-bit RGB value. A value over 0xffffff }
// // will be rejected, with a non-zero return value.
// static inline int /// Set the cell's background palette index, set the background palette index
// cell_set_bg(cell* c, uint32_t channel){ /// bit, set it background-opaque, and clear the background default color bit.
// return channels_set_bg(&c->channels, channel); ///
// } // TODO: TEST
// // NOTE: this function now can't fail
// // Set the cell's background palette index, set the background palette index #[inline]
// // bit, set it background-opaque, and clear the background default color bit. pub fn cell_set_bg_palindex(cell: &mut cell, index: PaletteIndex) {
// static inline int cell.channels |= ffi::CELL_BGDEFAULT_MASK as u64 ;
// cell_set_bg_palindex(cell* cl, int idx){ cell.channels |= ffi::CELL_BG_PALETTE as u64;
// if(idx < 0 || idx >= NCPALETTESIZE){ cell_set_bg_alpha(cell, ffi::CELL_ALPHA_OPAQUE);
// return -1; cell.channels &= 0xffffffffff000000;
// } cell.channels |= index as u64;
// cl->channels |= CELL_BGDEFAULT_MASK; }
// cl->channels |= CELL_BG_PALETTE;
// cell_set_bg_alpha(cl, CELL_ALPHA_OPAQUE); // TODO: TEST
// cl->channels &= 0xffffffffff000000; #[inline]
// cl->channels |= idx; pub fn cell_bg_palindex(cell: &cell) -> PaletteIndex {
// return 0; (cell.channels & 0xff) as PaletteIndex
// } }
//
// static inline unsigned /// Is the foreground using the "default foreground color"?
// cell_bg_palindex(const cell* cl){ // TODO: TEST
// return (cl->channels & 0xff); #[inline]
// } pub fn cell_fg_default_p(cell: &cell) -> bool {
// ffi::channels_fg_default_p(cell.channels)
// // Is the foreground using the "default foreground color"? }
// static inline bool // TODO: TEST
// cell_fg_default_p(const cell* cl){ #[inline]
// return channels_fg_default_p(cl->channels); pub fn cell_fg_palindex_p(cell: &cell) -> bool {
// } ffi::channels_fg_palindex_p(cell.channels)
// }
// static inline bool
// cell_fg_palindex_p(const cell* cl){ /// Is the background using the "default background color"? The "default
// return channels_fg_palindex_p(cl->channels); /// background color" must generally be used to take advantage of
// } /// terminal-effected transparency.
// // TODO: TEST
// // Is the background using the "default background color"? The "default #[inline]
// // background color" must generally be used to take advantage of pub fn cell_bg_default_p(cell: &cell) -> bool {
// // terminal-effected transparency. ffi::channels_bg_default_p(cell.channels)
// static inline bool }
// cell_bg_default_p(const cell* cl){
// return channels_bg_default_p(cl->channels); // TODO: TEST
// } #[inline]
// pub fn cell_bg_palindex_p(cell: &cell) -> bool {
// static inline bool ffi::channels_bg_palindex_p(cell.channels)
// cell_bg_palindex_p(const cell* cl){ }
// return channels_bg_palindex_p(cl->channels);
// }
#[cfg(test)] #[cfg(test)]
mod test { mod test {

Loading…
Cancel
Save