1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
//!
use crate::{
c_api::{self, NcChannels_u64},
error, NcAlpha, NcChannel, NcPaletteIndex, NcResult, NcRgb,
};
/// 64 bits containing a foreground and background [`NcChannel`]
///
/// At render time, both 24-bit [`NcRgb`] values are quantized down to terminal
/// capabilities, if necessary. There's a clear path to 10-bit support should
/// we one day need it.
///
/// ## Default Color
///
/// The "default color" is best explained by [color(3NCURSES)][0] and
/// [default_colors(3NCURSES)][1]. Ours is the same concept.
///
/// [0]: https://manpages.debian.org/stretch/ncurses-doc/color.3ncurses.en.html
/// [1]: https://manpages.debian.org/stretch/ncurses-doc/default_colors.3ncurses.en.html
///
/// **Until the "not default color" bit is set, any color you load will be ignored.**
///
/// ## Diagram
///
/// ```txt
/// ~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB║~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB
/// ↑↑↑↑↑↑↑↑↑↑↑↑ foreground ↑↑↑↑↑↑↑↑↑↑↑║↑↑↑↑↑↑↑↑↑↑↑↑ background ↑↑↑↑↑↑↑↑↑↑↑
/// ```
///
/// Detailed info (specially on the context-dependent bits on each
/// [`NcChannel`]'s 4th byte):
///
/// ```txt
/// ~foreground channel~
/// reserved, must be 0 ↓bits view↓ ↓hex mask↓
/// 0·······|········|········|········║········|········|········|········ = 8·······|········
///
/// NcChannels::FG_DEFAULT_MASK: foreground is NOT "default color"
/// ·1······|········|········|········║········|········|········|········ = 4·······|········
///
/// NcChannels::FG_ALPHA_MASK: foreground alpha (2bits)
/// ··11····|········|········|········║········|········|········|········ = 3·······|········
///
/// NcChannels::FG_PALETTE: foreground uses palette index
/// ····1···|········|········|········║········|········|········|········ = ·8······|········
///
/// NcChannels::NOBACKGROUND_MASK: glyph is entirely foreground
/// ·····1··|········|········|········║········|········|········|········ = ·4······|········
///
/// reserved, must be 0
/// ······00|········|········|········║········|········|········|········ = ·3······|········
///
/// NcChannels::FG_RGB_MASK: foreground in 3x8 RGB (rrggbb)
/// ········|11111111|11111111|11111111║········|········|········|········ = ··FFFFFF|········
/// ```
///
/// ```txt
/// ~background channel~
/// reserved, must be 0 ↓bits view↓ ↓hex mask↓
/// ········|········|········|········║0·······|········|········|········ = ········|8·······
///
/// NcChannels::BGDEFAULT_MASK: background is NOT "default color"
/// ········|········|········|········║·1······|········|········|········ = ········|4·······
///
/// NcChannels::BG_ALPHA_MASK: background alpha (2 bits)
/// ········|········|········|········║··11····|········|········|········ = ········|3·······
///
/// NcChannels::BG_PALETTE: background uses palette index
/// ········|········|········|········║····1···|········|········|········ = ········|·8······
///
/// reserved, must be 0
/// ········|········|········|········║·····000|········|········|········ = ········|·7······
///
/// NcChannels::BG_RGB_MASK: background in 3x8 RGB (rrggbb)
/// ········|········|········|········║········|11111111|11111111|11111111 = ········|··FFFFFF
/// ```
/// `type in C: channels (uint64_t)`
///
/// ## `NcChannels` Mask Flags
///
/// - [`NcChannels::BG_DEFAULT_MASK`][NcChannels#associatedconstant.BGDEFAULT_MASK]
/// - [`NcChannels::BG_ALPHA_MASK`][NcChannels#associatedconstant.BG_ALPHA_MASK]
/// - [`NcChannels::BG_PALETTE`][NcChannels#associatedconstant.BG_PALETTE]
/// - [`NcChannels::BG_RGB_MASK`][NcChannels#associatedconstant.BG_RGB_MASK]
/// - [`NcChannels::FG_DEFAULT_MASK`][NcChannels#associatedconstant.FGDEFAULT_MASK]
/// - [`NcChannels::FG_ALPHA_MASK`][NcChannels#associatedconstant.FG_ALPHA_MASK]
/// - [`NcChannels::FG_PALETTE`][NcChannels#associatedconstant.FG_PALETTE]
/// - [`NcChannels::FG_RGB_MASK`][NcChannels#associatedconstant.FG_RGB_MASK]
///
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NcChannels(pub NcChannels_u64);
mod std_impls {
use super::{NcChannels, NcChannels_u64};
impl Default for NcChannels {
fn default() -> Self {
Self::with_default()
}
}
crate::from_primitive![NcChannels, NcChannels_u64];
crate::unit_impl_from![NcChannels, NcChannels_u64];
crate::unit_impl_fmt![bases+display; NcChannels];
// Different background and foreground:
impl From<NcChannels> for [u8; 6] {
#[inline]
fn from(rgb: NcChannels) -> Self {
let fg: (u8, u8, u8) = rgb.fg_rgb().into();
let bg: (u8, u8, u8) = rgb.bg_rgb().into();
[fg.0, fg.1, fg.2, bg.0, bg.1, bg.2]
}
}
impl From<[u8; 6]> for NcChannels {
#[inline]
fn from(a: [u8; 6]) -> Self {
Self::from_rgb((a[0], a[1], a[2]), (a[3], a[4], a[5]))
}
}
impl From<NcChannels> for (u8, u8, u8, u8, u8, u8) {
#[inline]
fn from(rgb: NcChannels) -> Self {
let fg: (u8, u8, u8) = rgb.fg_rgb().into();
let bg: (u8, u8, u8) = rgb.bg_rgb().into();
(fg.0, fg.1, fg.2, bg.0, bg.1, bg.2)
}
}
impl From<(u8, u8, u8, u8, u8, u8)> for NcChannels {
fn from(t: (u8, u8, u8, u8, u8, u8)) -> Self {
Self::from_rgb([t.0, t.1, t.2], [t.3, t.4, t.5])
}
}
}
/// # NcChannels constants
impl NcChannels {
/// If this bit is set, we are *not* using the default background color.
///
/// See the detailed diagram at [`NcChannels`][crate::NcChannels]
pub const BG_DEFAULT_MASK: u32 = super::c_api::NC_BGDEFAULT_MASK;
/// Extract these bits to get the background [`NcAlpha`] mask.
///
/// See the detailed diagram at [`NcChannels`][crate::NcChannels]
pub const BG_ALPHA_MASK: u32 = super::c_api::NC_BG_ALPHA_MASK;
/// If this bit *and*
/// [`BG_DEFAULT_MASK`][NcChannels#associatedconstant.BG_DEFAULT_MASK]
/// are set, we're using a palette-indexed background color.
///
/// See the detailed diagram at [`NcChannels`][crate::NcChannels]
pub const BG_PALETTE_MASK: u32 = super::c_api::NC_BG_PALETTE;
/// Extract these bits to get the background [`NcRgb`][crate::NcRgb] value.
pub const BG_RGB_MASK: u32 = super::c_api::NC_BG_RGB_MASK;
/// Does this glyph completely obscure the background? If so, there's no need
/// to emit a background when rasterizing, a small optimization. These are
/// also used to track regions into which we must not cellblit.
pub const NOBACKGROUND_MASK: u64 = c_api::NC_NOBACKGROUND_MASK;
}
/// # NcChannels constructors
impl NcChannels {
/// New `NcChannels`, set to black and NOT using the "default color".
pub fn new() -> Self {
Self::combine(NcChannel::new(), NcChannel::new())
}
/// New `NcChannels`, set to black and using the "default color".
pub fn with_default() -> Self {
Self::combine(NcChannel::with_default(), NcChannel::with_default())
}
/// New `NcChannels`, expects two separate [`NcRgb`]s for the foreground
/// and background channels.
pub fn from_rgb(fg_rgb: impl Into<NcRgb>, bg_rgb: impl Into<NcRgb>) -> Self {
Self::combine(NcChannel::from_rgb(fg_rgb), NcChannel::from_rgb(bg_rgb))
}
/// New `NcChannels`, expects a single [`NcRgb`] for both foreground
/// and background channels.
pub fn from_rgb_both(rgb: impl Into<NcRgb>) -> Self {
let channel = NcChannel::new().set(rgb.into());
Self::combine(channel, channel)
}
/// New `NcChannels`, expects two separate [`NcRgb`] & [`NcAlpha`] for the
/// foreground and background channels.
pub fn from_rgb_alpha(
fg_rgb: impl Into<NcRgb>,
fg_alpha: impl Into<NcAlpha>,
bg_rgb: impl Into<NcRgb>,
bg_alpha: impl Into<NcAlpha>,
) -> Self {
Self::combine(
NcChannel::from_rgb(fg_rgb).set_alpha(fg_alpha),
NcChannel::from_rgb(bg_rgb).set_alpha(bg_alpha),
)
}
/// New `NcChannels`, expects [`NcRgb`] & [`NcAlpha`] for both
/// channels.
pub fn from_rgb_alpha_both(rgb: impl Into<NcRgb>, alpha: impl Into<NcAlpha>) -> Self {
let channel = NcChannel::new().set(rgb.into()).set_alpha(alpha.into());
Self::combine(channel, channel)
}
// Combine & Reverse
/// Combines two [`NcChannel`]s into an [`NcChannels`].
///
/// *C style function: [channels_combine()][c_api::ncchannels_combine].*
pub fn combine(fchannel: impl Into<NcChannel>, bchannel: impl Into<NcChannel>) -> Self {
c_api::ncchannels_combine(fchannel.into().0, bchannel.into().0).into()
}
/// Returns the `NcChannels` with the fore- and background's color
/// information swapped, but without touching housekeeping bits.
///
/// Alpha is retained unless it would lead to an illegal state:
/// `HIGHCONTRAST`, `TRANSPARENT` and `BLEND` are taken to `OPAQUE`
/// unless the new value is RGB.
///
/// [`HIGHCONTRAST`][NcAlpha#associatedconstant.HIGHCONTRAST]
/// [`TRANSPARENT`][NcAlpha#associatedconstant.TRANSPARENT]
/// [`BLEND`][NcAlpha#associatedconstant.BLEND]
/// [`OPAQUE`][NcAlpha#associatedconstant.OPAQUE]
///
/// *C style function: [ncchannels_reverse()][c_api::ncchannels_reverse].*
pub fn reverse(&mut self) -> Self {
*self = c_api::ncchannels_reverse(self.0).into();
*self
}
}
/// # NcChannels methods
impl NcChannels {
// NcChannel
/// Gets the foreground alpha and coloring bits as an [`NcChannel`].
///
/// *C style function: [ncchannels_fchannel()][c_api::ncchannels_fchannel].*
pub fn fchannel(&self) -> NcChannel {
c_api::ncchannels_fchannel(self.0).into()
}
/// Gets the background alpha and coloring bits as an [`NcChannel`].
///
/// *C style function: [ncchannels_bchannel()][c_api::ncchannels_bchannel].*
pub fn bchannel(&self) -> NcChannel {
c_api::ncchannels_bchannel(self.0).into()
}
/// Sets the foreground alpha and coloring bits from an [`NcChannel`].
///
/// *C style function: [ncchannels_set_fchannel()][c_api::ncchannels_set_fchannel].*
pub fn set_fchannel(&mut self, fchannel: impl Into<NcChannel>) -> Self {
c_api::ncchannels_set_fchannel(&mut self.0, fchannel.into().0).into()
}
/// Sets the background alpha and coloring bits from an [`NcChannel`].
///
/// *C style function: [ncchannels_set_bchannel()][c_api::ncchannels_set_bchannel].*
pub fn set_bchannel(&mut self, bchannel: impl Into<NcChannel>) -> Self {
c_api::ncchannels_set_bchannel(&mut self.0, bchannel.into().0).into()
}
/// Gets the alpha and coloring bits as an [`NcChannels`].
///
/// *C style function: [ncchannels_bchannel()][c_api::ncchannels_bchannel].*
pub fn channels(&self) -> NcChannels {
c_api::ncchannels_channels(self.0).into()
}
/// Sets the foreground alpha and coloring bits as an [`NcChannels`],
/// from another [`NcChannels`].
///
/// *C style function: [ncchannels_set_fchannel()][c_api::ncchannels_set_fchannel].*
pub fn set_channels(&mut self, from_channels: impl Into<NcChannels>) -> Self {
c_api::ncchannels_set_channels(&mut self.0, from_channels.into().0).into()
}
// Alpha
/// Gets the foreground [`NcAlpha`].
///
/// *C style function: [ncchannels_fg_alpha()][c_api::ncchannels_fg_alpha].*
pub fn fg_alpha(&self) -> NcAlpha {
c_api::ncchannels_fg_alpha(self.0).into()
}
/// Gets the background [`NcAlpha`].
///
/// *C style function: [ncchannels_bg_alpha()][c_api::ncchannels_bg_alpha].*
pub fn bg_alpha(&self) -> NcAlpha {
c_api::ncchannels_bg_alpha(self.0).into()
}
/// Sets the foreground [`NcAlpha`].
///
/// *C style function: [ncchannels_set_fg_alpha()][c_api::ncchannels_set_fg_alpha].*
pub fn set_fg_alpha(&mut self, alpha: impl Into<NcAlpha>) -> NcResult<()> {
error![c_api::ncchannels_set_fg_alpha(&mut self.0, alpha.into())]
}
/// Sets the background [`NcAlpha`].
///
/// *C style function: [ncchannels_set_bg_alpha()][c_api::ncchannels_set_bg_alpha].*
pub fn set_bg_alpha(&mut self, alpha: impl Into<NcAlpha>) -> NcResult<()> {
error![c_api::ncchannels_set_bg_alpha(&mut self.0, alpha.into())]
}
// NcRgb
/// Returns true if the foreground channel is set to RGB color.
///
/// *C style function: [ncchannels_fg_rgb_p()][c_api::ncchannels_fg_rgb_p].*
pub fn fg_rgb_p(&self) -> bool {
c_api::ncchannels_fg_rgb_p(self.0)
}
/// Returns true if the background channel is set to RGB color.
///
/// *C style function: [ncchannels_bg_rgb_p()][c_api::ncchannels_bg_rgb_p].*
pub fn bg_rgb_p(&self) -> bool {
c_api::ncchannels_bg_rgb_p(self.0)
}
/// Gets the foreground [`NcRgb`].
///
/// *C style function: [ncchannels_fg_rgb()][c_api::ncchannels_fg_rgb].*
pub fn fg_rgb(&self) -> NcRgb {
c_api::ncchannels_fg_rgb(self.0).into()
}
/// Gets the background [`NcRgb`].
///
/// *C style function: [ncchannels_bg_rgb()][c_api::ncchannels_bg_rgb].*
pub fn bg_rgb(&self) -> NcRgb {
c_api::ncchannels_bg_rgb(self.0).into()
}
/// Sets the foreground [`NcRgb`].
///
/// *C style function: [channels_set_fg_rgb()][c_api::ncchannels_set_fg_rgb].*
pub fn set_fg_rgb(&mut self, rgb: impl Into<NcRgb>) -> Self {
c_api::ncchannels_set_fg_rgb(&mut self.0, rgb.into().0);
*self
}
/// Sets the background [`NcRgb`].
///
/// *C style function: [channels_set_bg_rgb()][c_api::ncchannels_set_bg_rgb].*
pub fn set_bg_rgb(&mut self, rgb: impl Into<NcRgb>) -> Self {
c_api::ncchannels_set_bg_rgb(&mut self.0, rgb.into().0);
*self
}
/// Gets the foreground red component.
///
/// *(No equivalent C style function)*
pub fn fg_r(&self) -> u8 {
c_api::ncchannel_r(c_api::ncchannels_fchannel(self.0))
}
/// Gets the foreground green component.
///
/// *(No equivalent C style function)*
pub fn fg_g(&self) -> u8 {
c_api::ncchannel_g(c_api::ncchannels_fchannel(self.0))
}
/// Gets the foreground blue component.
///
/// *(No equivalent C style function)*
pub fn fg_b(&self) -> u8 {
c_api::ncchannel_b(c_api::ncchannels_fchannel(self.0))
}
/// Gets the background red component.
///
/// *(No equivalent C style function)*
pub fn bg_r(&self) -> u8 {
c_api::ncchannel_r(c_api::ncchannels_bchannel(self.0))
}
/// Gets the background green component.
///
/// *(No equivalent C style function)*
pub fn bg_g(&self) -> u8 {
c_api::ncchannel_g(c_api::ncchannels_bchannel(self.0))
}
/// Gets the background blue component.
///
/// *(No equivalent C style function)*
pub fn bg_b(&self) -> u8 {
c_api::ncchannel_b(c_api::ncchannels_bchannel(self.0))
}
/// Sets the foreground red component, and returns the new `NcChannels`.
///
/// *(No equivalent C style function)*
pub fn fg_set_r(&mut self, r: impl Into<u8>) -> Self {
let (_, g, b) = self.bg_rgb().into();
c_api::ncchannels_set_fg_rgb8(&mut self.0, r.into(), g, b).into()
}
/// Sets the foreground green component, and returns the new `NcChannels`.
///
/// *(No equivalent C style function)*
pub fn fg_set_g(&mut self, g: impl Into<u8>) -> Self {
let (r, _, b) = self.bg_rgb().into();
c_api::ncchannels_set_fg_rgb8(&mut self.0, r, g.into(), b).into()
}
/// Sets the foreground blue component, and returns the new `NcChannels`.
///
/// *(No equivalent C style function)*
pub fn fg_set_b(&mut self, b: impl Into<u8>) -> Self {
let (r, g, _) = self.bg_rgb().into();
c_api::ncchannels_set_fg_rgb8(&mut self.0, r, g, b.into()).into()
}
/// Sets the background red component, and returns the new `NcChannels`.
///
/// *(No equivalent C style function)*
pub fn bg_set_r(&mut self, r: impl Into<u8>) -> Self {
let (_, g, b) = self.bg_rgb().into();
c_api::ncchannels_set_bg_rgb8(&mut self.0, r.into(), g, b).into()
}
/// Sets the background green component, and returns the new `NcChannels`.
///
/// *(No equivalent C style function)*
pub fn bg_set_g(&mut self, g: impl Into<u8>) -> Self {
let (r, _, b) = self.bg_rgb().into();
c_api::ncchannels_set_bg_rgb8(&mut self.0, r, g.into(), b).into()
}
/// Sets the background blue component, and returns the new `NcChannels`.
///
/// *(No equivalent C style function)*
pub fn bg_set_b(&mut self, b: impl Into<u8>) -> Self {
let (r, g, _) = self.bg_rgb().into();
c_api::ncchannels_set_bg_rgb8(&mut self.0, r, g, b.into()).into()
}
// default color
/// Is the background using the "default background color"?
///
/// *C style function: [channels_fg_default_p()][c_api::ncchannels_fg_default_p].*
pub fn fg_default_p(&self) -> bool {
c_api::ncchannels_fg_default_p(self.0)
}
/// Is the background using the "default background color"?
///
/// The "default background color" must generally be used to take advantage
/// of terminal-effected transparency.
///
/// *C style function: [channels_bg_default_p()][c_api::ncchannels_bg_default_p].*
pub fn bg_default_p(&self) -> bool {
c_api::ncchannels_bg_default_p(self.0)
}
/// Marks the foreground as using its "default color", and
/// returns the new [`NcChannels`].
///
/// *C style function: [channels_set_fg_default()][c_api::ncchannels_set_fg_default].*
pub fn set_fg_default(&mut self) -> Self {
c_api::ncchannels_set_fg_default(&mut self.0).into()
}
/// Marks the background as using its "default color", and
/// returns the new [`NcChannels`].
///
/// *C style function: [channels_set_bg_default()][c_api::ncchannels_set_bg_default].*
pub fn set_bg_default(&mut self) -> Self {
c_api::ncchannels_set_bg_default(&mut self.0).into()
}
/// Marks the foreground as NOT using its "default color", and
/// returns the new [`NcChannels`].
///
/// *C style function: [channels_set_fg_default()][c_api::ncchannels_set_fg_default].*
//
// Not in the C API
pub fn set_fg_not_default(&mut self) -> Self {
c_api::ncchannels_set_fg_not_default(&mut self.0).into()
}
/// Marks the background as NOT using its "default color", and
/// returns the new [`NcChannels`].
///
/// *C style function: [channels_set_bg_not_default()][c_api::ncchannels_set_bg_not_default].*
//
// Not in the C API
pub fn set_bg_not_default(&mut self) -> Self {
c_api::ncchannels_set_bg_not_default(&mut self.0).into()
}
/// Marks both the foreground and background as using its "default color", and
/// returns the new [`NcChannels`].
///
//
// Not in the C API
pub fn set_default(&mut self) -> Self {
c_api::ncchannels_set_fg_default(&mut c_api::ncchannels_set_bg_default(&mut self.0)).into()
}
/// Marks both the foreground and background as NOT using its "default color",
/// and returns the new [`NcChannels`].
///
//
// Not in the C API
pub fn set_not_default(&mut self) -> Self {
c_api::ncchannels_set_fg_not_default(&mut c_api::ncchannels_set_bg_not_default(&mut self.0))
.into()
}
// NcPaletteIndex
/// Gets the [`NcPaletteIndex`] from the foreground [`NcChannel`].
///
/// *C style function: [channels_fg_palindex()][c_api::ncchannels_fg_palindex].*
pub fn fg_palindex(&self) -> NcPaletteIndex {
c_api::ncchannels_fg_palindex(self.0)
}
/// Gets the [`NcPaletteIndex`] from the background [`NcChannel`].
///
/// *C style function: [channels_bg_palindex()][c_api::ncchannels_bg_palindex].*
pub fn bg_palindex(&self) -> NcPaletteIndex {
c_api::ncchannels_bg_palindex(self.0)
}
/// Is the foreground of using an [*indexed*][NcPaletteIndex]
/// [`NcPalette`][crate::NcPalette] color?
///
/// *C style function: [channels_fg_palindex_p()][c_api::ncchannels_fg_palindex_p].*
pub fn fg_palindex_p(&self) -> bool {
c_api::ncchannels_fg_palindex_p(self.0)
}
/// Is the background of using an [*indexed*][NcPaletteIndex]
/// [`NcPalette`][crate::NcPalette] color?
///
/// *C style function: [channels_bg_palindex_p()][c_api::ncchannels_bg_palindex_p].*
pub fn bg_palindex_p(&self) -> bool {
c_api::ncchannels_bg_palindex_p(self.0)
}
/// Sets the foreground of an [`NcChannels`] as using an
/// [*indexed*][NcPaletteIndex] [`NcPalette`][crate::NcPalette] color.
///
/// *C style function: [channels_set_fg_palindex()][c_api::ncchannels_set_fg_palindex].*
pub fn set_fg_palindex(&mut self, index: impl Into<NcPaletteIndex>) -> Self {
c_api::ncchannels_set_fg_palindex(&mut self.0, index.into());
*self
}
/// Sets the background of an [`NcChannels`] as using an
/// [*indexed*][NcPaletteIndex] [`NcPalette`][crate::NcPalette] color.
///
/// *C style function: [channels_set_bg_palindex()][c_api::ncchannels_set_bg_palindex].*
pub fn set_bg_palindex(&mut self, index: impl Into<NcPaletteIndex>) -> Self {
c_api::ncchannels_set_bg_palindex(&mut self.0, index.into());
*self
}
}