rust: add methods for NcResizeCb & NcPalette.
- fix intra-doc links. - refactor palette module.pull/1253/head
parent
1afa9cc1db
commit
bda47b7403
@ -0,0 +1,54 @@
|
||||
//! `NcPalette` methods and associated functions.
|
||||
|
||||
use crate::{NcChannel, NcColor, NcPalette, NcPaletteIndex, NcResult, NcRgb, Notcurses};
|
||||
|
||||
impl NcPalette {
|
||||
/// New NcPalette.
|
||||
///
|
||||
/// *C style function: [palette256_new()][crate::palette256_new].*
|
||||
pub fn new<'a>(nc: &mut Notcurses) -> &'a mut Self {
|
||||
unsafe { &mut *crate::palette256_new(nc) }
|
||||
}
|
||||
|
||||
/// Frees this NcPalette.
|
||||
///
|
||||
/// *C style function: [palette256_free()][crate::palette256_free].*
|
||||
pub fn free(&mut self) {
|
||||
unsafe {
|
||||
crate::palette256_free(self);
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to configure the terminal with this NcPalette.
|
||||
///
|
||||
/// *C style function: [palette256_use()][crate::palette256_use].*
|
||||
pub fn r#use(&self, nc: &mut Notcurses) -> NcResult {
|
||||
unsafe { crate::palette256_use(nc, self) }
|
||||
}
|
||||
|
||||
/// Returns the [NcColor] RGB components from the [NcChannel] in this NcPalette.
|
||||
///
|
||||
/// *C style function: [palette256_get_rgb()][crate::palette256_get_rgb].*
|
||||
pub fn get_rgb8(&self, index: NcPaletteIndex) -> (NcColor, NcColor, NcColor) {
|
||||
let (mut r, mut g, mut b) = (0, 0, 0);
|
||||
crate::channel_rgb8(self.chans[index as usize], &mut r, &mut g, &mut b);
|
||||
(r, g, b)
|
||||
}
|
||||
|
||||
/// Extracts the [NcColor] RGB components from an [NcChannel] entry inside
|
||||
/// this NcPalette, and returns the NcChannel.
|
||||
///
|
||||
/// *C style function: [palette256_get_rgb()][crate::palette256_get_rgb].*
|
||||
pub fn get_rgb(&self, index: NcPaletteIndex) -> NcChannel {
|
||||
let (mut r, mut g, mut b) = (0, 0, 0);
|
||||
crate::channel_rgb8(self.chans[index as usize], &mut r, &mut g, &mut b)
|
||||
}
|
||||
|
||||
/// Sets the [NcRgb] value of the [NcChannel][crate::NcChannel] entry
|
||||
/// inside this NcPalette.
|
||||
///
|
||||
/// *C style function: [palette256_set()][crate::palette256_set].*
|
||||
pub fn set(&mut self, index: NcPaletteIndex, rgb: NcRgb) {
|
||||
crate::channel_set(&mut self.chans[index as usize], rgb);
|
||||
}
|
||||
}
|
@ -1,36 +1,41 @@
|
||||
//! `palette256_*` reimplemented functions.
|
||||
|
||||
use crate::{
|
||||
channel_rgb8, channel_set, channel_set_rgb8, NcChannel, NcColor, NcPalette, NcPaletteIndex,
|
||||
NcRgb,
|
||||
};
|
||||
use crate::{NcChannel, NcColor, NcPalette, NcPaletteIndex, NcRgb};
|
||||
|
||||
/// Set the different color components of an entry inside a palette store.
|
||||
#[inline]
|
||||
pub fn palette256_set_rgb(
|
||||
palette: &mut NcPalette,
|
||||
idx: NcPaletteIndex,
|
||||
red: NcColor,
|
||||
green: NcColor,
|
||||
blue: NcColor,
|
||||
) {
|
||||
channel_set_rgb8(&mut palette.chans[idx as usize], red, green, blue)
|
||||
}
|
||||
|
||||
/// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once.
|
||||
#[inline]
|
||||
pub fn palette256_set(palette: &mut NcPalette, idx: NcPaletteIndex, rgb: NcRgb) {
|
||||
channel_set(&mut palette.chans[idx as usize], rgb);
|
||||
}
|
||||
|
||||
/// Extract the three 8-bit R/G/B components from an entry inside a palette store.
|
||||
/// Extracts the [NcColor] RGB components from an [NcChannel] entry inside
|
||||
/// an [NcPalette], and returns the NcChannel.
|
||||
///
|
||||
/// *Method: NcPalette.[get_rgb()][NcPalette#method.get_rgb].*
|
||||
/// *Method: NcPalette.[get_rgb8()][NcPalette#method.get_rgb8].*
|
||||
#[inline]
|
||||
pub fn palette256_get_rgb(
|
||||
palette: &NcPalette,
|
||||
idx: NcPaletteIndex,
|
||||
index: NcPaletteIndex,
|
||||
red: &mut NcColor,
|
||||
green: &mut NcColor,
|
||||
blue: &mut NcColor,
|
||||
) -> NcChannel {
|
||||
channel_rgb8(palette.chans[idx as usize], red, green, blue)
|
||||
crate::channel_rgb8(palette.chans[index as usize], red, green, blue)
|
||||
}
|
||||
|
||||
/// Sets the [NcRgb] value of the [NcChannel] entry inside an [NcPalette].
|
||||
///
|
||||
/// *Method: NcPalette.[set()][NcPalette#method.set].*
|
||||
#[inline]
|
||||
pub fn palette256_set(palette: &mut NcPalette, index: NcPaletteIndex, rgb: NcRgb) {
|
||||
crate::channel_set(&mut palette.chans[index as usize], rgb);
|
||||
}
|
||||
|
||||
/// Sets the [NcColor] components of the [NcChannel] entry inside an [NcPalette].
|
||||
///
|
||||
/// *Method: NcPalette.[set_rgb()][NcPalette#method.set_rgb].*
|
||||
#[inline]
|
||||
pub fn palette256_set_rgb(
|
||||
palette: &mut NcPalette,
|
||||
index: NcPaletteIndex,
|
||||
red: NcColor,
|
||||
green: NcColor,
|
||||
blue: NcColor,
|
||||
) {
|
||||
crate::channel_set_rgb8(&mut palette.chans[index as usize], red, green, blue)
|
||||
}
|
||||
|
Loading…
Reference in New Issue