[rust] rename `NCCELL_`* constants to `NCALPHA_`*

- move `NCALPHA_`* constants to the channel module where `NcAlphaBits`
is defined.
- fix several docs and doclinks.
- rustfmt.
pull/1785/head
joseLuís 3 years ago
parent 9950d71e89
commit 2ba4777443

@ -226,9 +226,9 @@ impl NcCell {
/// Sets the background [NcPaletteIndex].
///
/// Also sets [NCCELL_BG_PALETTE][crate::NCCELL_BG_PALETTE] and
/// [NCCELL_OPAQUE][crate::NCCELL_OPAQUE], and clears out
/// [NCCELL_BGDEFAULT_MASK][crate::NCCELL_BGDEFAULT_MASK].
/// Also sets [NCALPHA_BG_PALETTE][crate::NCALPHA_BG_PALETTE] and
/// [NCALPHA_OPAQUE][crate::NCALPHA_OPAQUE], and clears out
/// [NCALPHA_BGDEFAULT_MASK][crate::NCALPHA_BGDEFAULT_MASK].
///
/// *C style function: [nccell_set_bg_palindex()][crate::nccell_set_bg_palindex].*
pub fn set_bg_palindex(&mut self, index: NcPaletteIndex) {
@ -266,9 +266,9 @@ impl NcCell {
/// Sets the foreground [NcPaletteIndex].
///
/// Also sets [NCCELL_FG_PALETTE][crate::NCCELL_FG_PALETTE] and
/// [NCCELL_OPAQUE][crate::NCCELL_OPAQUE], and clears out
/// [NCCELL_BGDEFAULT_MASK][crate::NCCELL_BGDEFAULT_MASK].
/// Also sets [NCALPHA_FG_PALETTE][crate::NCALPHA_FG_PALETTE] and
/// [NCALPHA_OPAQUE][crate::NCALPHA_OPAQUE], and clears out
/// [NCALPHA_BGDEFAULT_MASK][crate::NCALPHA_BGDEFAULT_MASK].
///
/// *C style function: [nccell_set_fg_palindex()][crate::nccell_set_fg_palindex].*
pub fn set_fg_palindex(&mut self, index: NcPaletteIndex) {

@ -73,6 +73,9 @@ mod methods;
mod reimplemented;
pub use reimplemented::*;
#[allow(unused_imports)] // TEMP
use crate::{NcChannel, NcPlane};
// NcCell
/// A coordinate on an [`NcPlane`][crate::NcPlane] storing 128 bits of data.
///
@ -86,12 +89,12 @@ pub use reimplemented::*;
///
/// # Description
///
/// An `NcCell` corresponds to a single character cell on some NcPlane`,
/// An `NcCell` corresponds to a single character cell on some `NcPlane`,
/// which can be occupied by a single [`NcEgc`] grapheme cluster (some root
/// spacing glyph, along with possible combining characters, which might span
/// multiple columns).
///
/// An NcCell is bounded to an NcPlane, but the cell doesn't store anything
/// An NcCell is bounded to an `NcPlane`, but the cell doesn't store anything
/// about the plane.
///
/// At any `NcCell`, we can have a theoretically arbitrarily long UTF-8 string,
@ -161,19 +164,19 @@ pub use reimplemented::*;
/// have two bits of inverted alpha. The actual grapheme written to a cell is
/// the topmost non-zero grapheme.
///
/// - If its alpha is 00 ([`NCCELL_OPAQUE`]) its foreground color is used unchanged.
/// - If its alpha is 00 ([`NCALPHA_OPAQUE`]) its foreground color is used unchanged.
///
/// - If its alpha is 10 ([`NCCELL_TRANSPARENT`]) its foreground color is derived
/// - If its alpha is 10 ([`NCALPHA_TRANSPARENT`]) its foreground color is derived
/// entirely from cells underneath it.
///
/// - If its alpha is 01 ([`NCCELL_BLEND`]) the result will be a composite.
/// - If its alpha is 01 ([`NCALPHA_BLEND`]) the result will be a composite.
///
/// Likewise for the background. If the bottom of a coordinate's zbuffer is
/// reached with a cumulative alpha of zero, the default is used. In this way,
/// a terminal configured with transparent background can be supported through
/// multiple occluding ncplanes.
///
/// A foreground alpha of 11 ([`NCCELL_HIGHCONTRAST`]) requests high-contrast
/// A foreground alpha of 11 ([`NCALPHA_HIGHCONTRAST`]) requests high-contrast
/// text (relative to the computed background).
/// A background alpha of 11 is currently forbidden.
///
@ -200,88 +203,6 @@ pub use reimplemented::*;
///
pub type NcCell = crate::bindings::ffi::cell;
#[allow(unused_imports)]
use crate::{NcAlphaBits, NcChannel, NcPlane};
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground or background color will be a composite between
/// its color and the `NcCell`s' corresponding colors underneath it
pub const NCCELL_BLEND: u32 = crate::bindings::ffi::NCALPHA_BLEND;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground color will be high-contrast (relative to the
/// computed background). Background cannot be highcontrast
pub const NCCELL_HIGHCONTRAST: u32 = crate::bindings::ffi::NCALPHA_HIGHCONTRAST;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground or background color is used unchanged
pub const NCCELL_OPAQUE: u32 = crate::bindings::ffi::NCALPHA_OPAQUE;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground or background color is derived entirely from the
/// `NcCell`s underneath it
pub const NCCELL_TRANSPARENT: u32 = crate::bindings::ffi::NCALPHA_TRANSPARENT;
/// If this bit is set, we are *not* using the default background color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: This can also be used against a single [`NcChannel`]
pub const NCCELL_BGDEFAULT_MASK: u32 = crate::bindings::ffi::CELL_BGDEFAULT_MASK;
/// Extract these bits to get the background alpha mask
/// ([`NcAlphaBits`])
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: This can also be used against a single [`NcChannel`]
pub const NCCELL_BG_ALPHA_MASK: u32 = crate::bindings::ffi::CELL_BG_ALPHA_MASK;
/// If this bit *and* [`NCCELL_BGDEFAULT_MASK`] are set, we're using a
/// palette-indexed background color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: This can also be used against a single [`NcChannel`]
pub const NCCELL_BG_PALETTE: u32 = crate::bindings::ffi::CELL_BG_PALETTE;
/// Extract these bits to get the background [`NcRgb`][crate::NcRgb] value
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: This can also be used against a single [`NcChannel`]
pub const NCCELL_BG_RGB_MASK: u32 = crate::bindings::ffi::CELL_BG_RGB_MASK;
/// If this bit is set, we are *not* using the default foreground color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: When working with a single [`NcChannel`] use [`NCCELL_BGDEFAULT_MASK`];
pub const NCCELL_FGDEFAULT_MASK: u64 = crate::bindings::ffi::CELL_FGDEFAULT_MASK;
/// Extract these bits to get the foreground alpha mask
/// ([`NcAlphaBits`])
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: When working with a single [`NcChannel`] use [`NCCELL_BG_ALPHA_MASK`];
pub const NCCELL_FG_ALPHA_MASK: u64 = crate::bindings::ffi::CELL_FG_ALPHA_MASK;
/// If this bit *and* [`NCCELL_FGDEFAULT_MASK`] are set, we're using a
/// palette-indexed background color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: When working with a single [`NcChannel`] use [`NCCELL_BG_PALETTE`];
pub const NCCELL_FG_PALETTE: u64 = crate::bindings::ffi::CELL_FG_PALETTE;
/// Extract these bits to get the foreground [`NcRgb`][crate::NcRgb] value
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// NOTE: When working with a single [`NcChannel`] use [`NCCELL_BG_RGB_MASK`];
pub const NCCELL_FG_RGB_MASK: u64 = crate::bindings::ffi::CELL_FG_RGB_MASK;
// NcEgc
//
/// Extended Grapheme Cluster. A 32-bit [`char`]-like type
@ -322,7 +243,7 @@ pub const NCCELL_FG_RGB_MASK: u64 = crate::bindings::ffi::CELL_FG_RGB_MASK;
/// in a cell, and therefore it must not be allowed through the API.
///
/// -----
/// NOTE that even if the `NcEgc` is <= 4 bytes and inlined, is still interpreted as
/// Note that even if the `NcEgc` is <= 4 bytes and inlined, is still interpreted as
/// a NUL-terminated char * (technically, &cell->gcluster is treated as a char*).
/// If it is more than 4 bytes, cell->gcluster has a first byte of 0x01,
/// and the remaining 24 bits are an index into the plane's egcpool,

@ -4,9 +4,9 @@ use libc::strcmp;
use crate::{
cstring, nccell_release, NcAlphaBits, NcCell, NcChannel, NcChannelPair, NcColor, NcEgc,
NcIntResult, NcPaletteIndex, NcPlane, NcRgb, NcStyle, NCCELL_BGDEFAULT_MASK, NCCELL_BG_PALETTE,
NCCELL_FGDEFAULT_MASK, NCCELL_FG_PALETTE, NCCELL_OPAQUE, NCRESULT_ERR, NCRESULT_OK,
NCSTYLE_MASK,
NcIntResult, NcPaletteIndex, NcPlane, NcRgb, NcStyle, NCALPHA_BGDEFAULT_MASK,
NCALPHA_BG_PALETTE, NCALPHA_FGDEFAULT_MASK, NCALPHA_FG_PALETTE, NCALPHA_OPAQUE, NCRESULT_ERR,
NCRESULT_OK, NCSTYLE_MASK,
};
// Alpha -----------------------------------------------------------------------
@ -208,8 +208,8 @@ pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex {
/// Sets an [NcCell]'s foreground [NcPaletteIndex].
///
/// Also sets [NCCELL_FG_PALETTE] and [NCCELL_OPAQUE],
/// and clears out [NCCELL_FGDEFAULT_MASK].
/// Also sets [NCALPHA_FG_PALETTE] and [NCALPHA_OPAQUE],
/// and clears out [NCALPHA_FGDEFAULT_MASK].
///
/// *Method: NcCell.[set_fg_palindex()][NcCell#method.set_fg_palindex].*
//
@ -217,26 +217,26 @@ pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex {
#[inline]
#[allow(clippy::unnecessary_cast)]
pub fn nccell_set_fg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
cell.channels |= NCCELL_FGDEFAULT_MASK;
cell.channels |= NCCELL_FG_PALETTE;
nccell_set_fg_alpha(cell, NCCELL_OPAQUE);
cell.channels |= NCALPHA_FGDEFAULT_MASK;
cell.channels |= NCALPHA_FG_PALETTE;
nccell_set_fg_alpha(cell, NCALPHA_OPAQUE);
cell.channels &= 0xff000000ffffffff as NcChannelPair;
cell.channels |= (index as NcChannelPair) << 32;
}
/// Sets an [NcCell]'s background [NcPaletteIndex].
///
/// Also sets [NCCELL_BG_PALETTE] and [NCCELL_OPAQUE],
/// and clears out [NCCELL_BGDEFAULT_MASK].
/// Also sets [NCALPHA_BG_PALETTE] and [NCALPHA_OPAQUE],
/// and clears out [NCALPHA_BGDEFAULT_MASK].
///
/// *Method: NcCell.[set_bg_palindex()][NcCell#method.set_bg_palindex].*
//
// NOTE: unlike the original C function, this one can't fail
#[inline]
pub fn nccell_set_bg_palindex(cell: &mut NcCell, index: NcPaletteIndex) {
cell.channels |= NCCELL_BGDEFAULT_MASK as NcChannelPair;
cell.channels |= NCCELL_BG_PALETTE as NcChannelPair;
nccell_set_bg_alpha(cell, NCCELL_OPAQUE);
cell.channels |= NCALPHA_BGDEFAULT_MASK as NcChannelPair;
cell.channels |= NCALPHA_BG_PALETTE as NcChannelPair;
nccell_set_bg_alpha(cell, NCALPHA_OPAQUE);
cell.channels &= 0xffffffffff000000;
cell.channels |= index as NcChannelPair;
}

@ -1,6 +1,6 @@
//! Test `NcCell` methods and associated functions.
use crate::{NcCell, NcPlane, Nc};
use crate::{Nc, NcCell, NcPlane};
use serial_test::serial;

@ -26,12 +26,12 @@ fn rgb() {
crate::nccell_set_fg_rgb8(&mut c2, 0x11, 0x22, 0x33);
let fchannel = crate::nccell_fg_rgb8(&c2, &mut r, &mut g, &mut b);
assert_eq!((0x11, 0x22, 0x33), (r, g, b));
assert_eq![0x112233, fchannel & !crate::NCCELL_BGDEFAULT_MASK];
assert_eq![0x112233, fchannel & !crate::NCALPHA_BGDEFAULT_MASK];
crate::nccell_set_bg_rgb8(&mut c2, 0x44, 0x55, 0x66);
let bchannel = crate::nccell_bg_rgb8(&c2, &mut r, &mut g, &mut b);
assert_eq!((0x44, 0x55, 0x66), (r, g, b));
assert_eq![0x445566, bchannel & !crate::NCCELL_BGDEFAULT_MASK];
assert_eq![0x445566, bchannel & !crate::NCALPHA_BGDEFAULT_MASK];
}
#[test]
@ -41,11 +41,11 @@ fn alpha() {
assert_eq![0, crate::nccell_fg_alpha(&c1)];
assert_eq![0, crate::nccell_bg_alpha(&c1)];
crate::nccell_set_fg_alpha(&mut c1, crate::NCCELL_TRANSPARENT);
assert_eq![crate::NCCELL_TRANSPARENT, crate::nccell_fg_alpha(&c1)];
crate::nccell_set_fg_alpha(&mut c1, crate::NCALPHA_TRANSPARENT);
assert_eq![crate::NCALPHA_TRANSPARENT, crate::nccell_fg_alpha(&c1)];
crate::nccell_set_bg_alpha(&mut c1, crate::NCCELL_BLEND);
assert_eq![crate::NCCELL_BLEND, crate::nccell_bg_alpha(&c1)];
crate::nccell_set_bg_alpha(&mut c1, crate::NCALPHA_BLEND);
assert_eq![crate::NCALPHA_BLEND, crate::nccell_bg_alpha(&c1)];
}
#[test]

@ -3,7 +3,7 @@
use crate::{NcAlphaBits, NcChannel, NcChannelPair, NcColor, NcPaletteIndex, NcRgb};
/// Enables the [NcChannel] methods.
/// Enables the [`NcChannel`] methods.
pub trait NcChannelMethods {
// constructors
fn new() -> Self;
@ -41,7 +41,7 @@ pub trait NcChannelMethods {
fn palindex_p(&self) -> bool;
}
/// Enables the [NcChannelPair] methods.
/// Enables the [`NcChannelPair`] methods.
pub trait NcChannelPairMethods {
// constructors
fn new() -> Self;
@ -134,7 +134,7 @@ impl NcChannelMethods for NcChannel {
/// New NcChannel, set to black and NOT using the "default color".
fn new() -> Self {
0 as NcChannel | crate::NCCELL_BGDEFAULT_MASK
0 as NcChannel | crate::NCALPHA_BGDEFAULT_MASK
}
/// New NcChannel, set to black but using the "default color".
@ -142,30 +142,30 @@ impl NcChannelMethods for NcChannel {
0 as NcChannel
}
/// New NcChannel, expects [NcRgb].
/// New NcChannel, expects [`NcRgb`].
fn with_rgb(rgb: NcRgb) -> Self {
Self::new().set(rgb)
}
/// New NcChannel, expects [NcRgb] & [NcAlphaBits].
/// New NcChannel, expects [`NcRgb`] & [`NcAlphaBits`].
fn with_rgb_alpha(rgb: NcRgb, alpha: NcAlphaBits) -> Self {
Self::new().set(rgb).set_alpha(alpha)
}
/// New NcChannel, expects three RGB [NcColor] components.
/// New NcChannel, expects three RGB [`NcColor`] components.
fn with_rgb8(r: NcColor, g: NcColor, b: NcColor) -> Self {
Self::new().set_rgb8(r, g, b)
}
/// New NcChannel, expects three RGB [NcColor] components & [NcAlphaBits].
/// New NcChannel, expects three RGB [`NcColor`] components & [`NcAlphaBits`].
fn with_rgb8_alpha(r: NcColor, g: NcColor, b: NcColor, alpha: NcAlphaBits) -> Self {
Self::new().set_rgb8(r, g, b).set_alpha(alpha)
}
// Combine
/// Combines this [NcChannel] as foreground, with another as background
/// into an [NcChannelPair].
/// Combines this [`NcChannel`] as foreground, with another as background
/// into an [`NcChannelPair`].
///
/// *C style function: [channels_combine()][crate::ncchannels_combine].*
//
@ -174,8 +174,8 @@ impl NcChannelMethods for NcChannel {
crate::ncchannels_combine(*self, bchannel)
}
/// Combines this [NcChannel] as background, with another as foreground
/// into an [NcChannelPair].
/// Combines this [`NcChannel`] as background, with another as foreground
/// into an [`NcChannelPair`].
///
/// *C style function: [channels_combine()][crate::ncchannels_combine].*
//
@ -186,14 +186,14 @@ impl NcChannelMethods for NcChannel {
// Alpha
/// Gets the [NcAlphaBits].
/// Gets the [`NcAlphaBits`].
///
/// *C style function: [channel_alpha()][crate::ncchannel_alpha].*
fn alpha(&self) -> NcAlphaBits {
crate::ncchannel_alpha(*self)
}
/// Sets the [NcAlphaBits].
/// Sets the [`NcAlphaBits`].
///
/// *C style function: [channel_set_alpha()][crate::ncchannel_set_alpha].*
fn set_alpha(&mut self, alpha: NcAlphaBits) -> Self {
@ -203,7 +203,7 @@ impl NcChannelMethods for NcChannel {
// NcRgb
/// Sets the [NcRgb], and marks the NcChannel as NOT using the
/// Sets the [`NcRgb`], and marks the NcChannel as NOT using the
/// "default color", retaining the other bits unchanged.
///
/// *C style function: [channel_set()][crate::ncchannel_set].*
@ -214,7 +214,7 @@ impl NcChannelMethods for NcChannel {
// NcColor
/// Gets the three [NcColor]s.
/// Gets the three [`NcColor`]s.
///
/// *C style function: [channel_rgb8()][crate::ncchannel_rgb8].*
fn rgb8(&self) -> (NcColor, NcColor, NcColor) {
@ -223,7 +223,7 @@ impl NcChannelMethods for NcChannel {
(r, g, b)
}
/// Sets the three [NcColor]s, and
/// Sets the three [`NcColor`]s, and
/// marks the NcChannel as NOT using the "default color".
///
/// *C style function: [channel_set_rgb8()][crate::ncchannel_set_rgb8].*
@ -232,28 +232,28 @@ impl NcChannelMethods for NcChannel {
*self
}
/// Gets the red [NcColor].
/// Gets the red [`NcColor`].
///
/// *C style function: [channel_r()][crate::ncchannel_r].*
fn r(&self) -> NcColor {
crate::ncchannel_r(*self)
}
/// Gets the green [NcColor].
/// Gets the green [`NcColor`].
///
/// *C style function: [channel_g()][crate::ncchannel_g].*
fn g(&self) -> NcColor {
crate::ncchannel_g(*self)
}
/// Gets the blue [NcColor].
/// Gets the blue [`NcColor`].
///
/// *C style function: [channel_b()][crate::ncchannel_b].*
fn b(&self) -> NcColor {
crate::ncchannel_b(*self)
}
/// Sets the red [NcColor], and returns the new NcChannel.
/// Sets the red [`NcColor`], and returns the new `NcChannel`.
///
/// *C style function: [channel_set_r()][crate::ncchannel_set_r].*
//
@ -262,7 +262,7 @@ impl NcChannelMethods for NcChannel {
crate::ncchannel_set_r(self, r)
}
/// Sets the green [NcColor], and returns the new NcChannel.
/// Sets the green [`NcColor`], and returns the new `NcChannel`.
///
/// *C style function: [channel_set_g()][crate::ncchannel_set_g].*
//
@ -271,7 +271,7 @@ impl NcChannelMethods for NcChannel {
crate::ncchannel_set_g(self, g)
}
/// Sets the blue [NcColor], and returns the new NcChannel.
/// Sets the blue [`NcColor`], and returns the new `NcChannel`.
///
/// *C style function: [channel_set_b()][crate::ncchannel_set_b].*
//
@ -282,7 +282,7 @@ impl NcChannelMethods for NcChannel {
// NcRgb
/// Gets the [NcRgb].
/// Gets the [`NcRgb`].
///
/// *C style function: [channel_rgb()][crate::ncchannel_rgb].*
//
@ -291,7 +291,7 @@ impl NcChannelMethods for NcChannel {
crate::ncchannel_rgb(*self)
}
/// Sets the [NcRgb] and marks it as NOT using the "default color",
/// Sets the [`NcRgb`] and marks it as NOT using the "default color",
/// retaining the other bits unchanged.
///
/// *C style function: [channel_set()][crate::ncchannel_set].*
@ -350,8 +350,8 @@ impl NcChannelPairMethods for NcChannelPair {
/// New NcChannelPair, set to black and NOT using the "default color".
fn new() -> Self {
Self::combine(
0 as NcChannel | crate::NCCELL_BGDEFAULT_MASK,
0 as NcChannel | crate::NCCELL_BGDEFAULT_MASK,
0 as NcChannel | crate::NCALPHA_BGDEFAULT_MASK,
0 as NcChannel | crate::NCALPHA_BGDEFAULT_MASK,
)
}
@ -360,20 +360,20 @@ impl NcChannelPairMethods for NcChannelPair {
Self::combine(0 as NcChannel, 0 as NcChannel)
}
/// New NcChannel, expects two separate [NcRgb]s for the foreground
/// New NcChannel, expects two separate [`NcRgb`]s for the foreground
/// and background channels.
fn with_rgb(fg_rgb: NcRgb, bg_rgb: NcRgb) -> Self {
Self::combine(NcChannel::with_rgb(fg_rgb), NcChannel::with_rgb(bg_rgb))
}
/// New NcChannelPair, expects a single [NcRgb] for both foreground
/// New NcChannelPair, expects a single [`NcRgb`] for both foreground
/// and background channels.
fn with_rgb_both(rgb: NcRgb) -> Self {
let channel = NcChannel::new().set(rgb);
Self::combine(channel, channel)
}
/// New NcChannel, expects two separate [NcRgb] & [NcAlphaBits] for the
/// New NcChannel, expects two separate [`NcRgb`] & [`NcAlphaBits`] for the
/// foreground and background channels.
fn with_rgb_alpha(
fg_rgb: NcRgb,
@ -387,13 +387,13 @@ impl NcChannelPairMethods for NcChannelPair {
)
}
/// New NcChannel, expects [NcRgb] & [NcAlphaBits] for both channels.
/// New NcChannel, expects [`NcRgb`] & [`NcAlphaBits`] for both channels.
fn with_rgb_alpha_both(rgb: NcRgb, alpha: NcAlphaBits) -> Self {
let channel = NcChannel::new().set(rgb).set_alpha(alpha);
Self::combine(channel, channel)
}
/// New NcChannelPair, expects three RGB [NcColor] components for each channel.
/// New NcChannelPair, expects three RGB [`NcColor`] components for each channel.
fn with_rgb8(
fg_r: NcColor,
fg_g: NcColor,
@ -408,14 +408,14 @@ impl NcChannelPairMethods for NcChannelPair {
)
}
/// New NcChannelPair, expects three RGB [NcColor] components for both
/// New NcChannelPair, expects three RGB [`NcColor`] components for both
/// the foreground and background channels.
fn with_rgb8_both(r: NcColor, g: NcColor, b: NcColor) -> Self {
let channel = NcChannel::new().set_rgb8(r, g, b);
Self::combine(channel, channel)
}
/// New NcChannelPair, expects three RGB [NcColor] components & [NcAlphaBits]
/// New NcChannelPair, expects three RGB [`NcColor`] components & [`NcAlphaBits`]
/// for both foreground and background channels.
fn with_rgb8_alpha(
fg_r: NcColor,
@ -433,7 +433,7 @@ impl NcChannelPairMethods for NcChannelPair {
)
}
/// New NcChannel, expects three RGB [NcColor] components.
/// New NcChannel, expects three RGB [`NcColor`] components.
fn with_rgb8_alpha_both(r: NcColor, g: NcColor, b: NcColor, alpha: NcAlphaBits) -> Self {
let channel = NcChannel::new().set_rgb8(r, g, b).set_alpha(alpha);
Self::combine(channel, channel)
@ -441,7 +441,7 @@ impl NcChannelPairMethods for NcChannelPair {
// Combine
/// Combines two [NcChannel]s into an [NcChannelPair].
/// Combines two [`NcChannel`]s into an [`NcChannelPair`].
///
/// *C style function: [channels_combine()][crate::ncchannels_combine].*
fn combine(fchannel: NcChannel, bchannel: NcChannel) -> Self {
@ -450,28 +450,28 @@ impl NcChannelPairMethods for NcChannelPair {
// NcChannel
/// Extracts the foreground [NcChannel].
/// Extracts the foreground [`NcChannel`].
///
/// *C style function: [channels_fchannel()][crate::ncchannels_fchannel].*
fn fchannel(&self) -> NcChannel {
crate::ncchannels_fchannel(*self)
}
/// Extracts the background [NcChannel].
/// Extracts the background [`NcChannel`].
///
/// *C style function: [channels_bchannel()][crate::ncchannels_bchannel].*
fn bchannel(&self) -> NcChannel {
crate::ncchannels_bchannel(*self)
}
/// Sets the foreground [NcChannel].
/// Sets the foreground [`NcChannel`].
///
/// *C style function: [channels_set_fchannel()][crate::ncchannels_set_fchannel].*
fn set_fchannel(&mut self, fchannel: NcChannel) -> Self {
crate::ncchannels_set_fchannel(self, fchannel)
}
/// Sets the background [NcChannel].
/// Sets the background [`NcChannel`].
///
/// *C style function: [channels_set_bchannel()][crate::ncchannels_set_bchannel].*
fn set_bchannel(&mut self, bchannel: NcChannel) -> Self {
@ -480,28 +480,28 @@ impl NcChannelPairMethods for NcChannelPair {
// Alpha
/// Gets the foreground [NcAlphaBits].
/// Gets the foreground [`NcAlphaBits`].
///
/// *C style function: [channels_fg_alpha()][crate::ncchannels_fg_alpha].*
fn fg_alpha(&self) -> NcAlphaBits {
crate::ncchannels_fg_alpha(*self)
}
/// Gets the background [NcAlphaBits].
/// Gets the background [`NcAlphaBits`].
///
/// *C style function: [channels_bg_alpha()][crate::ncchannels_bg_alpha].*
fn bg_alpha(&self) -> NcAlphaBits {
crate::ncchannels_bg_alpha(*self)
}
/// Sets the foreground [NcAlphaBits].
/// Sets the foreground [`NcAlphaBits`].
///
/// *C style function: [channels_set_fg_alpha()][crate::ncchannels_set_fg_alpha].*
fn set_fg_alpha(&mut self, alpha: NcAlphaBits) {
crate::ncchannels_set_fg_alpha(self, alpha)
}
/// Sets the background [NcAlphaBits].
/// Sets the background [`NcAlphaBits`].
///
/// *C style function: [channels_set_bg_alpha()][crate::ncchannels_set_bg_alpha].*
fn set_bg_alpha(&mut self, alpha: NcAlphaBits) {
@ -510,21 +510,21 @@ impl NcChannelPairMethods for NcChannelPair {
// NcRgb
/// Gets the foreground [NcRgb].
/// Gets the foreground [`NcRgb`].
///
/// *C style function: [channels_fg_rgb()][crate::ncchannels_fg_rgb].*
fn fg_rgb(&self) -> NcRgb {
crate::ncchannels_fg_rgb(*self)
}
/// Gets the background [NcRgb].
/// Gets the background [`NcRgb`].
///
/// *C style function: [channels_bg_rgb()][crate::ncchannels_bg_rgb].*
fn bg_rgb(&self) -> NcRgb {
crate::ncchannels_bg_rgb(*self)
}
/// Sets the foreground [NcRgb].
/// Sets the foreground [`NcRgb`].
///
/// *C style function: [channels_set_fg_rgb()][crate::ncchannels_set_fg_rgb].*
fn set_fg_rgb(&mut self, rgb: NcRgb) -> Self {
@ -532,7 +532,7 @@ impl NcChannelPairMethods for NcChannelPair {
*self
}
/// Sets the background [NcRgb].
/// Sets the background [`NcRgb`].
///
/// *C style function: [channels_set_bg_rgb()][crate::ncchannels_set_bg_rgb].*
fn set_bg_rgb(&mut self, rgb: NcRgb) -> Self {
@ -542,7 +542,7 @@ impl NcChannelPairMethods for NcChannelPair {
// NcColor
/// Gets the three foreground [NcColor]s (r, g, b).
/// Gets the three foreground [`NcColor`]s (r, g, b).
///
/// *C style function: [channels_fg_rgb8()][crate::ncchannels_fg_rgb8].*
fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor) {
@ -551,7 +551,7 @@ impl NcChannelPairMethods for NcChannelPair {
(r, g, b)
}
/// Gets the three background [NcColor]s (r, g, b).
/// Gets the three background [`NcColor`]s (r, g, b).
///
/// *C style function: [channels_bg_rgb8()][crate::ncchannels_bg_rgb8].*
fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor) {
@ -560,65 +560,65 @@ impl NcChannelPairMethods for NcChannelPair {
(r, g, b)
}
/// Sets the three foreground [NcColor]s (r, g, b), and
/// marks the foreground [NcChannel] as not using the "default color".
/// Sets the three foreground [`NcColor`]s (r, g, b), and
/// marks the foreground [`NcChannel`] as not using the "default color".
///
/// *C style function: [channels_set_fg_rgb8()][crate::ncchannels_set_fg_rgb8].*
fn set_fg_rgb8(&mut self, r: NcColor, g: NcColor, b: NcColor) -> Self {
crate::ncchannels_set_fg_rgb8(self, r, g, b)
}
/// Sets the three background [NcColor]s (r, g, b), and
/// marks the background [NcChannel] as not using the "default color".
/// Sets the three background [`NcColor`]s (r, g, b), and
/// marks the background [`NcChannel`] as not using the "default color".
///
/// *C style function: [channels_set_bg_rgb8()][crate::ncchannels_set_bg_rgb8].*
fn set_bg_rgb8(&mut self, r: NcColor, g: NcColor, b: NcColor) -> Self {
crate::ncchannels_set_bg_rgb8(self, r, g, b)
}
/// Gets the foreground red [NcColor].
/// Gets the foreground red [`NcColor`].
///
/// *(No equivalent C style function)*
fn fg_r(&self) -> NcColor {
crate::ncchannel_r(crate::ncchannels_fchannel(*self))
}
/// Gets the foreground green [NcColor].
/// Gets the foreground green [`NcColor`].
///
/// *(No equivalent C style function)*
fn fg_g(&self) -> NcColor {
crate::ncchannel_g(crate::ncchannels_fchannel(*self))
}
/// Gets the foreground blue [NcColor].
/// Gets the foreground blue [`NcColor`].
///
/// *(No equivalent C style function)*
fn fg_b(&self) -> NcColor {
crate::ncchannel_b(crate::ncchannels_fchannel(*self))
}
/// Gets the background red [NcColor].
/// Gets the background red [`NcColor`].
///
/// *(No equivalent C style function)*
fn bg_r(&self) -> NcColor {
crate::ncchannel_r(crate::ncchannels_bchannel(*self))
}
/// Gets the background green [NcColor].
/// Gets the background green [`NcColor`].
///
/// *(No equivalent C style function)*
fn bg_g(&self) -> NcColor {
crate::ncchannel_g(crate::ncchannels_bchannel(*self))
}
/// Gets the background blue [NcColor].
/// Gets the background blue [`NcColor`].
///
/// *(No equivalent C style function)*
fn bg_b(&self) -> NcColor {
crate::ncchannel_b(crate::ncchannels_bchannel(*self))
}
/// Sets the foreground red [NcColor], and returns the new NcChannelPair.
/// Sets the foreground red [`NcColor`], and returns the new `NcChannelPair`.
///
/// *(No equivalent C style function)*
fn fg_set_r(&mut self, r: NcColor) -> Self {
@ -626,7 +626,7 @@ impl NcChannelPairMethods for NcChannelPair {
crate::ncchannels_set_fg_rgb8(self, r, g, b)
}
/// Sets the foreground green [NcColor], and returns the new NcChannelPair.
/// Sets the foreground green [`NcColor`], and returns the new `NcChannelPair`.
///
/// *(No equivalent C style function)*
fn fg_set_g(&mut self, g: NcColor) -> Self {
@ -634,7 +634,7 @@ impl NcChannelPairMethods for NcChannelPair {
crate::ncchannels_set_fg_rgb8(self, r, g, b)
}
/// Sets the foreground blue [NcColor], and returns the new NcChannelPair.
/// Sets the foreground blue [`NcColor`], and returns the new `NcChannelPair`.
///
/// *(No equivalent C style function)*
fn fg_set_b(&mut self, b: NcColor) -> Self {
@ -642,7 +642,7 @@ impl NcChannelPairMethods for NcChannelPair {
crate::ncchannels_set_fg_rgb8(self, r, g, b)
}
/// Sets the background red [NcColor], and returns the new NcChannelPair.
/// Sets the background red [`NcColor`], and returns the new `NcChannelPair`.
///
/// *(No equivalent C style function)*
fn bg_set_r(&mut self, r: NcColor) -> Self {
@ -650,7 +650,7 @@ impl NcChannelPairMethods for NcChannelPair {
crate::ncchannels_set_bg_rgb8(self, r, g, b)
}
/// Sets the background green [NcColor], and returns the new NcChannelPair.
/// Sets the background green [`NcColor`], and returns the new `NcChannelPair`.
///
/// *(No equivalent C style function)*
fn bg_set_g(&mut self, g: NcColor) -> Self {
@ -658,7 +658,7 @@ impl NcChannelPairMethods for NcChannelPair {
crate::ncchannels_set_bg_rgb8(self, r, g, b)
}
/// Sets the background blue [NcColor], and returns the new NcChannelPair.
/// Sets the background blue [`NcColor`], and returns the new `NcChannelPair`.
///
/// *(No equivalent C style function)*
fn bg_set_b(&mut self, b: NcColor) -> Self {
@ -686,7 +686,7 @@ impl NcChannelPairMethods for NcChannelPair {
}
/// Marks the foreground as using its "default color", and
/// returns the new [NcChannelPair].
/// returns the new [`NcChannelPair`].
///
/// *C style function: [channels_set_fg_default()][crate::ncchannels_set_fg_default].*
fn set_fg_default(&mut self) -> Self {
@ -694,7 +694,7 @@ impl NcChannelPairMethods for NcChannelPair {
}
/// Marks the background as using its "default color", and
/// returns the new [NcChannelPair].
/// returns the new [`NcChannelPair`].
///
/// *C style function: [channels_set_bg_default()][crate::ncchannels_set_bg_default].*
fn set_bg_default(&mut self) -> Self {
@ -702,7 +702,7 @@ impl NcChannelPairMethods for NcChannelPair {
}
/// Marks the foreground as NOT using its "default color", and
/// returns the new [NcChannelPair].
/// returns the new [`NcChannelPair`].
///
/// *C style function: [channels_set_fg_default()][crate::ncchannels_set_fg_default].*
//
@ -712,7 +712,7 @@ impl NcChannelPairMethods for NcChannelPair {
}
/// Marks the background as NOT using its "default color", and
/// returns the new [NcChannelPair].
/// returns the new [`NcChannelPair`].
///
/// *C style function: [channels_set_bg_not_default()][crate::ncchannels_set_bg_not_default].*
//
@ -722,7 +722,7 @@ impl NcChannelPairMethods for NcChannelPair {
}
/// Marks both the foreground and background as using its "default color", and
/// returns the new [NcChannelPair].
/// returns the new [`NcChannelPair`].
///
//
// Not in the C API
@ -731,7 +731,7 @@ impl NcChannelPairMethods for NcChannelPair {
}
/// Marks both the foreground and background as NOT using its "default color",
/// and returns the new [NcChannelPair].
/// and returns the new [`NcChannelPair`].
///
//
// Not in the C API
@ -757,7 +757,7 @@ impl NcChannelPairMethods for NcChannelPair {
crate::ncchannels_bg_palindex_p(*self)
}
/// Sets the foreground of an [NcChannelPair] as using an
/// Sets the foreground of an [`NcChannelPair`] as using an
/// [indexed][NcPaletteIndex] [NcPalette][crate::NcPalette] color.
///
/// *C style function: [channels_set_fg_palindex()][crate::ncchannels_set_fg_palindex].*
@ -766,7 +766,7 @@ impl NcChannelPairMethods for NcChannelPair {
*self
}
/// Sets the background of an [NcChannelPair] as using an
/// Sets the background of an [`NcChannelPair`] as using an
/// [indexed][NcPaletteIndex] [NcPalette][crate::NcPalette] color.
///
/// *C style function: [channels_set_bg_palindex()][crate::ncchannels_set_bg_palindex].*

@ -116,6 +116,85 @@ pub const NCCHANNEL_ALPHA_MASK: u32 = crate::bindings::ffi::CELL_BG_ALPHA_MASK;
///
pub type NcAlphaBits = u32;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground or background color will be a composite between
/// its color and the `NcCell`s' corresponding colors underneath it
pub const NCALPHA_BLEND: u32 = crate::bindings::ffi::NCALPHA_BLEND;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground color will be high-contrast (relative to the
/// computed background). Background cannot be highcontrast
pub const NCALPHA_HIGHCONTRAST: u32 = crate::bindings::ffi::NCALPHA_HIGHCONTRAST;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground or background color is used unchanged
pub const NCALPHA_OPAQUE: u32 = crate::bindings::ffi::NCALPHA_OPAQUE;
/// [`NcAlphaBits`] bits indicating
/// [`NcCell`]'s foreground or background color is derived entirely from the
/// `NcCell`s underneath it
pub const NCALPHA_TRANSPARENT: u32 = crate::bindings::ffi::NCALPHA_TRANSPARENT;
/// If this bit is set, we are *not* using the default background color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BGDEFAULT_MASK: u32 = crate::bindings::ffi::CELL_BGDEFAULT_MASK;
/// Extract these bits to get the background alpha mask
/// ([`NcAlphaBits`])
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BG_ALPHA_MASK: u32 = crate::bindings::ffi::CELL_BG_ALPHA_MASK;
/// If this bit *and* [`NCALPHA_BGDEFAULT_MASK`] are set, we're using a
/// palette-indexed background color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BG_PALETTE: u32 = crate::bindings::ffi::CELL_BG_PALETTE;
/// Extract these bits to get the background [`NcRgb`][crate::NcRgb] value
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BG_RGB_MASK: u32 = crate::bindings::ffi::CELL_BG_RGB_MASK;
/// If this bit is set, we are *not* using the default foreground color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BGDEFAULT_MASK`];
pub const NCALPHA_FGDEFAULT_MASK: u64 = crate::bindings::ffi::CELL_FGDEFAULT_MASK;
/// Extract these bits to get the foreground alpha mask
/// ([`NcAlphaBits`])
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_ALPHA_MASK`];
pub const NCALPHA_FG_ALPHA_MASK: u64 = crate::bindings::ffi::CELL_FG_ALPHA_MASK;
/// If this bit *and* [`NCALPHA_FGDEFAULT_MASK`] are set, we're using a
/// palette-indexed background color
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_PALETTE`];
pub const NCALPHA_FG_PALETTE: u64 = crate::bindings::ffi::CELL_FG_PALETTE;
/// Extract these bits to get the foreground [`NcRgb`][crate::NcRgb] value
///
/// See the detailed diagram at [`NcChannelPair`][crate::NcChannelPair]
///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_RGB_MASK`];
pub const NCALPHA_FG_RGB_MASK: u64 = crate::bindings::ffi::CELL_FG_RGB_MASK;
// NcChannelPair
//
/// 64 bits containing a foreground and background [`NcChannel`]
@ -145,25 +224,25 @@ pub type NcAlphaBits = u32;
///
/// ```txt
/// ~foreground channel~
/// NCCELL_WIDEASIAN_MASK: part of a wide glyph ↓bits view↓ ↓hex mask↓
/// NCALPHA_WIDEASIAN_MASK: part of a wide glyph ↓bits view↓ ↓hex mask↓
/// 1······· ········ ········ ········ ········ ········ ········ ········ = 8······· ········
///
/// NCCELL_FGDEFAULT_MASK: foreground is NOT "default color"
/// NCALPHA_FGDEFAULT_MASK: foreground is NOT "default color"
/// ·1······ ········ ········ ········ ········ ········ ········ ········ = 4······· ········
///
/// NCCELL_FG_ALPHA_MASK: foreground alpha (2bits)
/// NCALPHA_FG_ALPHA_MASK: foreground alpha (2bits)
/// ··11···· ········ ········ ········ ········ ········ ········ ········ = 3······· ········
///
/// NCCELL_FG_PALETTE: foreground uses palette index
/// NCALPHA_FG_PALETTE: foreground uses palette index
/// ····1··· ········ ········ ········ ········ ········ ········ ········ = ·8······ ········
///
/// NCCELL_NOBACKGROUND_MASK: glyph is entirely foreground
/// NCALPHA_NOBACKGROUND_MASK: glyph is entirely foreground
/// ·····1·· ········ ········ ········ ········ ········ ········ ········ = ·4······ ········
///
/// reserved, must be 0
/// ······00 ········ ········ ········ ········ ········ ········ ········ = ·3······ ········
///
/// NCCELL_FG_RGB_MASK: foreground in 3x8 RGB (rrggbb)
/// NCALPHA_FG_RGB_MASK: foreground in 3x8 RGB (rrggbb)
/// ········ 11111111 11111111 11111111 ········ ········ ········ ········ = ··FFFFFF ········
/// ```
@ -172,33 +251,33 @@ pub type NcAlphaBits = u32;
/// reserved, must be 0 ↓bits view↓ ↓hex mask↓
/// ········ ········ ········ ········ 0······· ········ ········ ········ = ········ 8·······
///
/// NCCELL_BGDEFAULT_MASK: background is NOT "default color"
/// NCALPHA_BGDEFAULT_MASK: background is NOT "default color"
/// ········ ········ ········ ········ ·1······ ········ ········ ········ = ········ 4·······
///
/// NCCELL_BG_ALPHA_MASK: background alpha (2 bits)
/// NCALPHA_BG_ALPHA_MASK: background alpha (2 bits)
/// ········ ········ ········ ········ ··11···· ········ ········ ········ = ········ 3·······
///
/// NCCELL_BG_PALETTE: background uses palette index
/// NCALPHA_BG_PALETTE: background uses palette index
/// ········ ········ ········ ········ ····1··· ········ ········ ········ = ········ ·8······
///
/// reserved, must be 0
/// ········ ········ ········ ········ ·····000 ········ ········ ········ = ········ ·7······
///
/// NCCELL_BG_RGB_MASK: background in 3x8 RGB (rrggbb)
/// NCALPHA_BG_RGB_MASK: background in 3x8 RGB (rrggbb)
/// 0········ ········ ········ ········ ········11111111 11111111 11111111 = ········ ··FFFFFF
/// ```
/// `type in C: channels (uint64_t)`
///
/// ## `NcCell` Mask Flags
///
/// - [`NCCELL_BGDEFAULT_MASK`][crate::NCCELL_BGDEFAULT_MASK]
/// - [`NCCELL_BG_ALPHA_MASK`][crate::NCCELL_BG_ALPHA_MASK]
/// - [`NCCELL_BG_PALETTE`][crate::NCCELL_BG_PALETTE]
/// - [`NCCELL_BG_RGB_MASK`][crate::NCCELL_BG_RGB_MASK]
/// - [`NCCELL_FGDEFAULT_MASK`][crate::NCCELL_FGDEFAULT_MASK]
/// - [`NCCELL_FG_ALPHA_MASK`][crate::NCCELL_FG_ALPHA_MASK]
/// - [`NCCELL_FG_PALETTE`][crate::NCCELL_FG_PALETTE]
/// - [`NCCELL_FG_RGB_MASK`][crate::NCCELL_FG_RGB_MASK]
/// - [`NCALPHA_BGDEFAULT_MASK`][crate::NCALPHA_BGDEFAULT_MASK]
/// - [`NCALPHA_BG_ALPHA_MASK`][crate::NCALPHA_BG_ALPHA_MASK]
/// - [`NCALPHA_BG_PALETTE`][crate::NCALPHA_BG_PALETTE]
/// - [`NCALPHA_BG_RGB_MASK`][crate::NCALPHA_BG_RGB_MASK]
/// - [`NCALPHA_FGDEFAULT_MASK`][crate::NCALPHA_FGDEFAULT_MASK]
/// - [`NCALPHA_FG_ALPHA_MASK`][crate::NCALPHA_FG_ALPHA_MASK]
/// - [`NCALPHA_FG_PALETTE`][crate::NCALPHA_FG_PALETTE]
/// - [`NCALPHA_FG_RGB_MASK`][crate::NCALPHA_FG_RGB_MASK]
///
pub type NcChannelPair = u64;

@ -1,9 +1,9 @@
//! `channel*_*` reimplemented functions.
use crate::{
NcAlphaBits, NcChannel, NcChannelPair, NcColor, NcPaletteIndex, NcRgb, NCCELL_BGDEFAULT_MASK,
NCCELL_BG_PALETTE, NCCELL_BG_RGB_MASK, NCCELL_FGDEFAULT_MASK, NCCELL_FG_PALETTE,
NCCELL_HIGHCONTRAST, NCCELL_OPAQUE, NCCHANNEL_ALPHA_MASK,
NcAlphaBits, NcChannel, NcChannelPair, NcColor, NcPaletteIndex, NcRgb, NCALPHA_BGDEFAULT_MASK,
NCALPHA_BG_PALETTE, NCALPHA_BG_RGB_MASK, NCALPHA_FGDEFAULT_MASK, NCALPHA_FG_PALETTE,
NCALPHA_HIGHCONTRAST, NCALPHA_OPAQUE, NCCHANNEL_ALPHA_MASK,
};
// Alpha -----------------------------------------------------------------------
@ -24,9 +24,9 @@ pub fn ncchannel_set_alpha(channel: &mut NcChannel, alpha: NcAlphaBits) {
let alpha_clean = alpha & NCCHANNEL_ALPHA_MASK;
*channel = alpha_clean | (*channel & !NCCHANNEL_ALPHA_MASK);
if alpha != NCCELL_OPAQUE {
if alpha != NCALPHA_OPAQUE {
// indicate that we are *not* using the default background color
*channel |= NCCELL_BGDEFAULT_MASK;
*channel |= NCALPHA_BGDEFAULT_MASK;
}
}
@ -62,9 +62,9 @@ pub fn ncchannels_set_fg_alpha(channels: &mut NcChannelPair, alpha: NcAlphaBits)
#[inline]
pub fn ncchannels_set_bg_alpha(channels: &mut NcChannelPair, alpha: NcAlphaBits) {
let mut alpha_clean = alpha;
if alpha == NCCELL_HIGHCONTRAST {
if alpha == NCALPHA_HIGHCONTRAST {
// forbidden for background alpha, so makes it opaque
alpha_clean = NCCELL_OPAQUE;
alpha_clean = NCALPHA_OPAQUE;
}
let mut channel = ncchannels_bchannel(*channels);
ncchannel_set_alpha(&mut channel, alpha_clean);
@ -200,7 +200,7 @@ pub fn ncchannel_rgb8(
#[inline]
pub fn ncchannel_set_rgb8(channel: &mut NcChannel, r: NcColor, g: NcColor, b: NcColor) {
let rgb: NcRgb = (r as NcChannel) << 16 | (g as NcChannel) << 8 | (b as NcChannel);
*channel = (*channel & !NCCELL_BG_RGB_MASK) | NCCELL_BGDEFAULT_MASK | rgb;
*channel = (*channel & !NCALPHA_BG_RGB_MASK) | NCALPHA_BGDEFAULT_MASK | rgb;
}
/// Gets the three foreground RGB [NcColor]s from an [NcChannelPair], and
@ -276,7 +276,7 @@ pub fn ncchannels_set_bg_rgb8(
/// *Method: NcChannelPair.[fg_rgb()][NcChannelPair#method.fg_rgb]*
#[inline]
pub fn ncchannels_fg_rgb(channels: NcChannelPair) -> NcRgb {
ncchannels_fchannel(channels) & NCCELL_BG_RGB_MASK
ncchannels_fchannel(channels) & NCALPHA_BG_RGB_MASK
}
/// Gets the background [NcRgb] from an [NcChannelPair], shifted to LSBs.
@ -284,7 +284,7 @@ pub fn ncchannels_fg_rgb(channels: NcChannelPair) -> NcRgb {
/// *Method: NcChannelPair.[bg_rgb()][NcChannelPair#method.bg_rgb]*
#[inline]
pub fn ncchannels_bg_rgb(channels: NcChannelPair) -> NcRgb {
ncchannels_bchannel(channels) & NCCELL_BG_RGB_MASK
ncchannels_bchannel(channels) & NCALPHA_BG_RGB_MASK
}
/// Gets the [NcRgb] of an [NcChannel].
@ -296,7 +296,7 @@ pub fn ncchannels_bg_rgb(channels: NcChannelPair) -> NcRgb {
// Not in the C API
#[inline]
pub const fn ncchannel_rgb(channel: NcChannel) -> NcRgb {
channel & NCCELL_BG_RGB_MASK
channel & NCALPHA_BG_RGB_MASK
}
/// Sets the [NcRgb] of an [NcChannel], and marks it as NOT using the
@ -305,7 +305,7 @@ pub const fn ncchannel_rgb(channel: NcChannel) -> NcRgb {
/// *Method: NcChannel.[set()][NcChannel#method.set]*
#[inline]
pub fn ncchannel_set(channel: &mut NcChannel, rgb: NcRgb) {
*channel = (*channel & !NCCELL_BG_RGB_MASK) | NCCELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
*channel = (*channel & !NCALPHA_BG_RGB_MASK) | NCALPHA_BGDEFAULT_MASK | (rgb & 0x00ffffff);
}
/// Sets the foreground [NcRgb] of an [NcChannelPair], and marks it as NOT using
@ -337,7 +337,7 @@ pub fn ncchannels_set_bg_rgb(channels: &mut NcChannelPair, rgb: NcRgb) {
/// *Method: NcChannel.[default_p()][NcChannel#method.default_p]*
#[inline]
pub const fn ncchannel_default_p(channel: NcChannel) -> bool {
(channel & NCCELL_BGDEFAULT_MASK) == 0
(channel & NCALPHA_BGDEFAULT_MASK) == 0
}
/// Marks an [NcChannel] as using its "default color", which also marks it opaque.
@ -345,7 +345,7 @@ pub const fn ncchannel_default_p(channel: NcChannel) -> bool {
/// *Method: NcChannel.[set_default()][NcChannel#method.set_default]*
#[inline]
pub fn ncchannel_set_default(channel: &mut NcChannel) -> NcChannel {
*channel &= !(NCCELL_BGDEFAULT_MASK | NCCELL_HIGHCONTRAST);
*channel &= !(NCALPHA_BGDEFAULT_MASK | NCALPHA_HIGHCONTRAST);
*channel
}
@ -357,7 +357,7 @@ pub fn ncchannel_set_default(channel: &mut NcChannel) -> NcChannel {
// Not in the C API
#[inline]
pub fn ncchannel_set_not_default(channel: &mut NcChannel) -> NcChannel {
*channel |= NCCELL_BGDEFAULT_MASK;
*channel |= NCALPHA_BGDEFAULT_MASK;
*channel
}
@ -461,7 +461,7 @@ pub fn ncchannels_set_not_default(channels: &mut NcChannelPair) -> NcChannelPair
/// *Method: NcChannel.[palindex_p()][NcChannel#method.palindex_p]*
#[inline]
pub fn ncchannel_palindex_p(channel: NcChannel) -> bool {
!(ncchannel_default_p(channel) && (channel & NCCELL_BG_PALETTE) == 0)
!(ncchannel_default_p(channel) && (channel & NCALPHA_BG_PALETTE) == 0)
}
/// Is the foreground of an [NcChannelPair] using an [indexed][NcPaletteIndex]
@ -489,9 +489,9 @@ pub fn ncchannels_bg_palindex_p(channels: NcChannelPair) -> bool {
#[inline]
#[allow(clippy::unnecessary_cast)]
pub fn ncchannels_set_fg_palindex(channels: &mut NcChannelPair, index: NcPaletteIndex) {
*channels |= NCCELL_FGDEFAULT_MASK;
*channels |= NCCELL_FG_PALETTE as NcChannelPair;
ncchannels_set_fg_alpha(channels, NCCELL_OPAQUE);
*channels |= NCALPHA_FGDEFAULT_MASK;
*channels |= NCALPHA_FG_PALETTE as NcChannelPair;
ncchannels_set_fg_alpha(channels, NCALPHA_OPAQUE);
*channels &= 0xff000000ffffffff as NcChannelPair;
*channels |= (index as NcChannelPair) << 32;
}
@ -502,9 +502,9 @@ pub fn ncchannels_set_fg_palindex(channels: &mut NcChannelPair, index: NcPalette
/// *Method: NcChannelPair.[set_bg_palindex()][NcChannelPair#method.set_bg_palindex]*
#[inline]
pub fn ncchannels_set_bg_palindex(channels: &mut NcChannelPair, index: NcPaletteIndex) {
*channels |= NCCELL_BGDEFAULT_MASK as NcChannelPair;
*channels |= NCCELL_BG_PALETTE as NcChannelPair;
ncchannels_set_bg_alpha(channels, NCCELL_OPAQUE);
*channels |= NCALPHA_BGDEFAULT_MASK as NcChannelPair;
*channels |= NCALPHA_BG_PALETTE as NcChannelPair;
ncchannels_set_bg_alpha(channels, NCALPHA_OPAQUE);
*channels &= 0xffffffffff000000;
*channels |= index as NcChannelPair;
}

@ -3,7 +3,8 @@
use serial_test::serial;
use crate::{
NcChannel, NcChannelPair, NCCELL_BLEND, NCCELL_HIGHCONTRAST, NCCELL_OPAQUE, NCCELL_TRANSPARENT,
NcChannel, NcChannelPair, NCALPHA_BLEND, NCALPHA_HIGHCONTRAST, NCALPHA_OPAQUE,
NCALPHA_TRANSPARENT,
};
// NcChannel tests -------------------------------------------------------------
@ -88,10 +89,10 @@ fn channel_set() {
#[serial]
fn channel_alpha() {
let c: NcChannel = 0x112233;
assert_ne!(crate::ncchannel_alpha(c), NCCELL_TRANSPARENT);
assert_ne!(crate::ncchannel_alpha(c), NCALPHA_TRANSPARENT);
let c: NcChannel = 0x112233 | NCCELL_TRANSPARENT;
assert_eq!(crate::ncchannel_alpha(c), NCCELL_TRANSPARENT);
let c: NcChannel = 0x112233 | NCALPHA_TRANSPARENT;
assert_eq!(crate::ncchannel_alpha(c), NCALPHA_TRANSPARENT);
}
/// sets the alpha component
@ -99,18 +100,18 @@ fn channel_alpha() {
#[serial]
fn channel_set_alpha() {
let mut c: NcChannel = 0x112233;
crate::ncchannel_set_alpha(&mut c, NCCELL_HIGHCONTRAST);
assert_eq!(NCCELL_HIGHCONTRAST, crate::ncchannel_alpha(c));
crate::ncchannel_set_alpha(&mut c, NCALPHA_HIGHCONTRAST);
assert_eq!(NCALPHA_HIGHCONTRAST, crate::ncchannel_alpha(c));
crate::ncchannel_set_alpha(&mut c, NCCELL_TRANSPARENT);
assert_eq!(NCCELL_TRANSPARENT, crate::ncchannel_alpha(c));
crate::ncchannel_set_alpha(&mut c, NCALPHA_TRANSPARENT);
assert_eq!(NCALPHA_TRANSPARENT, crate::ncchannel_alpha(c));
crate::ncchannel_set_alpha(&mut c, NCCELL_BLEND);
assert_eq!(NCCELL_BLEND, crate::ncchannel_alpha(c));
crate::ncchannel_set_alpha(&mut c, NCALPHA_BLEND);
assert_eq!(NCALPHA_BLEND, crate::ncchannel_alpha(c));
crate::ncchannel_set_alpha(&mut c, NCCELL_OPAQUE);
assert_eq!(NCCELL_OPAQUE, crate::ncchannel_alpha(c));
// TODO: CHECK for NCCELL_BGDEFAULT_MASK
crate::ncchannel_set_alpha(&mut c, NCALPHA_OPAQUE);
assert_eq!(NCALPHA_OPAQUE, crate::ncchannel_alpha(c));
// TODO: CHECK for NCALPHA_BGDEFAULT_MASK
}
/// sets the channel as using the default color
@ -122,7 +123,7 @@ fn channel_set_default() {
assert_eq!(true, crate::ncchannel_default_p(channel));
// If we change it from being opaque...
let mut channel_transp = channel | NCCELL_TRANSPARENT;
let mut channel_transp = channel | NCALPHA_TRANSPARENT;
assert_eq!(0x_20_112233, channel_transp); // the transparent bit is now set
crate::ncchannel_set_not_default(&mut channel_transp);
@ -161,7 +162,7 @@ fn channel_default_p() {
let mut c: NcChannel = 0x112233;
assert_eq!(true, crate::ncchannel_default_p(c));
let _ = crate::ncchannel_set_alpha(&mut c, NCCELL_OPAQUE);
let _ = crate::ncchannel_set_alpha(&mut c, NCALPHA_OPAQUE);
assert_eq!(true, crate::ncchannel_default_p(c));
crate::ncchannel_set(&mut c, 0x112233);

@ -11,7 +11,7 @@
use std::ffi::c_void;
use crate::{NcIntResult, NcPlane, NcTime, Nc};
use crate::{Nc, NcIntResult, NcPlane, NcTime};
/// Called for each fade iteration on the NcPlane.
///
@ -19,9 +19,8 @@ use crate::{NcIntResult, NcPlane, NcTime, Nc};
/// and that value is propagated out.
///
/// The recommended absolute display time target is passed in 'tspec'.
pub type NcFadeCb = Option<
unsafe extern "C" fn(*mut Nc, *mut NcPlane, *const NcTime, *mut c_void) -> NcIntResult,
>;
pub type NcFadeCb =
Option<unsafe extern "C" fn(*mut Nc, *mut NcPlane, *const NcTime, *mut c_void) -> NcIntResult>;
/// Context for a palette fade operation
pub type NcFadeCtx = crate::bindings::ffi::ncfadectx;

@ -5,7 +5,7 @@
#[allow(unused_imports)]
// enjoy briefer doc comments
use crate::{NcDirect, NcError, NcPlane, NcResult, Nc, NCRESULT_ERR, NCRESULT_OK};
use crate::{Nc, NcDirect, NcError, NcPlane, NcResult, NCRESULT_ERR, NCRESULT_OK};
// Sleep, Render & Flush Macros ------------------------------------------------

@ -3,10 +3,10 @@
use core::ptr::{null, null_mut};
use crate::{
cstring, error, error_ref_mut, notcurses_init, rstring, NcAlign, NcBlitter, NcChannelPair,
NcDim, NcEgc, NcError, NcFile, NcInput, NcLogLevel, NcPlane, NcResult, NcScale, NcSignalSet,
NcStats, NcStyle, NcTime, Nc, NcOptions, NCOPTION_NO_ALTERNATE_SCREEN,
NCOPTION_SUPPRESS_BANNERS, NCRESULT_ERR,
cstring, error, error_ref_mut, notcurses_init, rstring, Nc, NcAlign, NcBlitter, NcChannelPair,
NcDim, NcEgc, NcError, NcFile, NcInput, NcLogLevel, NcOptions, NcPlane, NcResult, NcScale,
NcSignalSet, NcStats, NcStyle, NcTime, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS,
NCRESULT_ERR,
};
/// # `NcOptions` Constructors
@ -110,9 +110,7 @@ impl Nc {
/// New notcurses context, expects [NcLogLevel] and flags.
pub fn with_debug<'a>(loglevel: NcLogLevel, flags: u64) -> NcResult<&'a mut Nc> {
Self::with_options(NcOptions::with_all_options(
loglevel, 0, 0, 0, 0, flags,
))
Self::with_options(NcOptions::with_all_options(loglevel, 0, 0, 0, 0, flags))
}
}
@ -405,11 +403,7 @@ impl Nc {
if res as u32 as i32 != -1 {
Ok(res)
} else {
error![
-1,
&format!("Nc.getc_blocking({:?})", input_txt),
res
]
error![-1, &format!("Nc.getc_blocking({:?})", input_txt), res]
}
}
@ -506,10 +500,7 @@ impl Nc {
pub fn palette_size(&self) -> NcResult<u32> {
let res = unsafe { crate::notcurses_palette_size(self) };
if res == 1 {
return Err(NcError::with_msg(
1,
"No color support ← Nc.palette_size()",
));
return Err(NcError::with_msg(1, "No color support ← Nc.palette_size()"));
}
Ok(res)
}
@ -539,10 +530,7 @@ impl Nc {
///
/// *C style function: [notcurses_render()][crate::notcurses_render].*
pub fn render(&mut self) -> NcResult<()> {
error![
unsafe { crate::notcurses_render(self) },
"Nc.render()"
]
error![unsafe { crate::notcurses_render(self) }, "Nc.render()"]
}
/// Performs the rendering and rasterization portion of

@ -3,7 +3,7 @@
use core::ptr::{null, null_mut};
use crate::{
NcAlign, NcDim, NcError, NcInput, NcOffset, NcPlane, NcResult, NcSignalSet, NcTime, Nc,
Nc, NcAlign, NcDim, NcError, NcInput, NcOffset, NcPlane, NcResult, NcSignalSet, NcTime,
NCALIGN_CENTER, NCALIGN_LEFT, NCALIGN_RIGHT, NCRESULT_MAX,
};

@ -1,6 +1,6 @@
//! `NcPalette` methods and associated functions.
use crate::{error, NcChannel, NcColor, NcPalette, NcPaletteIndex, NcResult, NcRgb, Nc};
use crate::{error, Nc, NcChannel, NcColor, NcPalette, NcPaletteIndex, NcResult, NcRgb};
impl NcPalette {
/// New NcPalette.

@ -1,4 +1,4 @@
use crate::{NcDim, NcOffset, NcPlane, NcPlaneOptions, Nc};
use crate::{Nc, NcDim, NcOffset, NcPlane, NcPlaneOptions};
/// Helper function for a new NcPlane on C style tests.
#[allow(dead_code)]

@ -5,10 +5,10 @@ use core::{
};
use crate::{
cstring, error, error_ref, error_ref_mut, rstring, NcAlign, NcAlphaBits, NcBlitter, NcBoxMask,
NcCell, NcChannel, NcChannelPair, NcColor, NcDim, NcEgc, NcError, NcFadeCb, NcOffset,
NcPaletteIndex, NcPixelGeometry, NcPlane, NcPlaneOptions, NcResizeCb, NcResult, NcRgb, NcStyle,
NcTime, Nc, NCRESULT_ERR,
cstring, error, error_ref, error_ref_mut, rstring, Nc, NcAlign, NcAlphaBits, NcBlitter,
NcBoxMask, NcCell, NcChannel, NcChannelPair, NcColor, NcDim, NcEgc, NcError, NcFadeCb,
NcOffset, NcPaletteIndex, NcPixelGeometry, NcPlane, NcPlaneOptions, NcResizeCb, NcResult,
NcRgb, NcStyle, NcTime, NCRESULT_ERR,
};
/// # NcPlaneOptions Constructors
@ -98,10 +98,7 @@ impl NcPlane {
/// The returned plane will be the top, bottom, and root of this new pile.
///
/// *C style function: [ncpile_create()][crate::ncpile_create].*
pub fn with_options<'a>(
nc: &mut Nc,
options: NcPlaneOptions,
) -> NcResult<&'a mut NcPlane> {
pub fn with_options<'a>(nc: &mut Nc, options: NcPlaneOptions) -> NcResult<&'a mut NcPlane> {
error_ref_mut![
unsafe { crate::ncpile_create(nc, &options) },
&format!["NcPlane::with_options(Nc, {:?})", &options]

@ -4,9 +4,9 @@ use core::ptr::null_mut;
use libc::c_void;
use crate::{
cstring, error, error_ref_mut, rstring, NcBlitter, NcDim, NcDirect, NcDirectF, NcDirectV,
cstring, error, error_ref_mut, rstring, Nc, NcBlitter, NcDim, NcDirect, NcDirectF, NcDirectV,
NcError, NcIntResult, NcPixel, NcPlane, NcResult, NcRgba, NcScale, NcTime, NcVGeom, NcVisual,
NcVisualOptions, Nc, NCBLIT_PIXEL, NCRESULT_ERR,
NcVisualOptions, NCBLIT_PIXEL, NCRESULT_ERR,
};
/// # NcVisualOptions Constructors
@ -333,11 +333,7 @@ impl NcVisual {
/// See [`NcVisualOptions`].
///
/// *C style function: [ncvisual_render()][crate::ncvisual_render].*
pub fn render(
&mut self,
nc: &mut Nc,
options: &NcVisualOptions,
) -> NcResult<&mut NcPlane> {
pub fn render(&mut self, nc: &mut Nc, options: &NcVisualOptions) -> NcResult<&mut NcPlane> {
error_ref_mut![
unsafe { crate::ncvisual_render(nc, self, options) },
"NcVisual.render(Nc, &NcVisualOptions)"

@ -146,7 +146,7 @@ pub type NcRgba = u32;
/// Treats as transparent the color specified in the `transcolor` field.
pub const NCVISUAL_OPTION_ADDALPHA: u32 = crate::bindings::ffi::NCVISUAL_OPTION_ADDALPHA;
/// Uses [`NCCELL_BLEND`][crate::NCCELL_BLEND] with visual.
/// Uses [`NCALPHA_BLEND`][crate::NCALPHA_BLEND] with visual.
pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::ffi::NCVISUAL_OPTION_BLEND;
/// allows you to indicate that the n field of ncvisual_options refers not to

Loading…
Cancel
Save