From 4c0268997cca979aa5d4d0cce8906c7331081a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Wed, 16 Jun 2021 20:26:36 +0200 Subject: [PATCH] [rust] rename `NcColor` to `NcComponent`. - fix docs. --- rust/src/cells/methods.rs | 88 +++--- rust/src/cells/mod.rs | 14 +- rust/src/cells/reimplemented.rs | 122 +++++---- rust/src/channel/methods.rs | 236 ++++++++-------- rust/src/channel/mod.rs | 8 +- rust/src/channel/reimplemented.rs | 170 ++++++------ rust/src/channel/test/reimplemented.rs | 10 +- rust/src/direct/methods.rs | 20 +- rust/src/direct/reimplemented.rs | 18 +- rust/src/fd/methods.rs | 366 +++++++++++++++++++++++++ rust/src/lib.rs | 2 +- rust/src/palette/methods.rs | 14 +- rust/src/palette/reimplemented.rs | 23 +- rust/src/pixel.rs | 117 ++++---- rust/src/plane/methods.rs | 163 +++++------ rust/src/plane/mod.rs | 2 +- rust/src/plane/reimplemented.rs | 20 +- 17 files changed, 903 insertions(+), 490 deletions(-) create mode 100644 rust/src/fd/methods.rs diff --git a/rust/src/cells/methods.rs b/rust/src/cells/methods.rs index 87457084f..4dc21a5b3 100644 --- a/rust/src/cells/methods.rs +++ b/rust/src/cells/methods.rs @@ -1,8 +1,8 @@ //! `NcCell` methods and associated functions. use crate::{ - cstring, error, nccell_load, NcAlphaBits, NcCell, NcChannelPair, NcColor, NcEgc, NcEgcBackstop, - NcPaletteIndex, NcPlane, NcResult, NcRgb, NcStyle, NCRESULT_ERR, + cstring, error, nccell_load, NcAlphaBits, NcCell, NcChannelPair, NcComponent, NcEgc, + NcEgcBackstop, NcPaletteIndex, NcPlane, NcResult, NcRgb, NcStyle, NCRESULT_ERR, }; #[allow(unused_imports)] // for the doc comments @@ -111,7 +111,7 @@ impl NcCell { // ----------------------------------------------------------------------------- /// ## NcCell methods: bg|fg `NcChannel`s manipulation. impl NcCell { - /// Returns the [NcChannelPair] of the NcCell. + /// Returns the [`NcChannelPair`] of the NcCell. /// /// *(No equivalent C style function)* pub fn channels(&mut self, plane: &mut NcPlane) -> NcChannelPair { @@ -120,111 +120,111 @@ impl NcCell { channels } - /// Extracts the background [NcAlphaBits] (shifted to LSBs). + /// Extracts the background [`NcAlphaBits`] (shifted to LSBs). /// /// *C style function: [nccell_bg_alpha()][crate::nccell_bg_alpha].* pub fn bg_alpha(&self) -> NcAlphaBits { crate::nccell_bg_alpha(self) } - /// Is the background [NcChannel] using the "default background color"? + /// Is the background [`NcChannel`] using the "default background color"? /// /// *C style function: [nccell_bg_default_p()][crate::nccell_bg_default_p].* pub fn bg_default_p(&self) -> bool { crate::nccell_bg_default_p(self) } - /// Gets the [NcPaletteIndex] of the background [NcChannel]. + /// Gets the [`NcPaletteIndex`] of the background [`NcChannel`]. /// /// *C style function: [nccell_bg_palindex()][crate::nccell_bg_palindex].* pub fn bg_palindex(&self) -> NcPaletteIndex { crate::nccell_bg_palindex(self) } - /// Is the background [NcChannel] using an [NcPaletteIndex] indexed - /// [NcPalette][crate::NcPalette] color? + /// Is the background [`NcChannel`] using an [`NcPaletteIndex`] indexed + /// [`NcPalette`][crate::NcPalette] color? /// /// *C style function: [nccell_bg_palindex_p()][crate::nccell_bg_palindex_p].* pub fn bg_palindex_p(&self) -> bool { crate::nccell_bg_palindex_p(self) } - /// Gets the background [NcRgb] (shifted to LSBs). + /// Gets the background [`NcRgb`] (shifted to LSBs). /// /// *C style function: [nccell_bg_rgb()][crate::nccell_bg_rgb].* pub fn bg_rgb(&self) -> NcRgb { crate::nccell_bg_rgb(self) } - /// Gets the background [NcColor] RGB components. + /// Gets the background RGB [`NcComponent`]s. /// /// *C style function: [nccell_bg_rgb8()][crate::nccell_bg_rgb8].* - pub fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor) { + pub fn bg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); crate::nccell_bg_rgb8(self, &mut r, &mut g, &mut b); (r, g, b) } - /// Extracts the foreground [NcAlphaBits] (shifted to LSBs). + /// Extracts the foreground [`NcAlphaBits`] (shifted to LSBs). /// /// *C style function: [nccell_fg_alpha()][crate::nccell_fg_alpha].* pub fn fg_alpha(&self) -> NcAlphaBits { crate::nccell_fg_alpha(self) } - /// Is the foreground [NcChannel] using the "default foreground color"? + /// Is the foreground [`NcChannel`] using the "default foreground color"? /// /// *C style function: [nccell_fg_default_p()][crate::nccell_fg_default_p].* pub fn fg_default_p(&self) -> bool { crate::nccell_fg_default_p(self) } - /// Gets the [NcPaletteIndex] of the foreground [NcChannel]. + /// Gets the [`NcPaletteIndex`] of the foreground [`NcChannel`]. /// /// *C style function: [nccell_fg_palindex()][crate::nccell_fg_palindex].* pub fn fg_palindex(&self) -> NcPaletteIndex { crate::nccell_fg_palindex(self) } - /// Is the foreground [NcChannel] using an [NcPaletteIndex] indexed - /// [NcPalette][crate::NcPalette] color? + /// Is the foreground [`NcChannel`] using an [`NcPaletteIndex`] indexed + /// [`NcPalette`][crate::NcPalette] color? /// /// *C style function: [nccell_fg_palindex_p()][crate::nccell_fg_palindex_p].* pub fn fg_palindex_p(&self) -> bool { crate::nccell_fg_palindex_p(self) } - /// Gets the foreground [NcRgb] (shifted to LSBs). + /// Gets the foreground [`NcRgb`] (shifted to LSBs). /// /// *C style function: [nccell_fg_rgb()][crate::nccell_fg_rgb].* pub fn fg_rgb(&self) -> NcRgb { crate::nccell_fg_rgb(self) } - /// Gets the foreground [NcColor] RGB components. + /// Gets the foreground RGB [`NcComponent`]s. /// /// *C style function: [nccell_fg_rgb8()][crate::nccell_fg_rgb8].* - pub fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor) { + pub fn fg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); crate::nccell_fg_rgb8(self, &mut r, &mut g, &mut b); (r, g, b) } - /// Sets the background [NcAlphaBits]. + /// Sets the background [`NcAlphaBits`]. /// /// *C style function: [nccell_set_bg_alpha()][crate::nccell_set_bg_alpha].* pub fn set_bg_alpha(&mut self, alpha: NcAlphaBits) { crate::nccell_set_bg_alpha(self, alpha); } - /// Indicates to use the "default color" for the background [NcChannel]. + /// Indicates to use the "default color" for the background [`NcChannel`]. /// /// *C style function: [nccell_set_bg_default()][crate::nccell_set_bg_default].* pub fn set_bg_default(&mut self) { crate::nccell_set_bg_default(self); } - /// Sets the background [NcPaletteIndex]. + /// Sets the background [`NcPaletteIndex`]. /// /// Also sets [NCALPHA_BG_PALETTE][crate::NCALPHA_BG_PALETTE] and /// [NCALPHA_OPAQUE][crate::NCALPHA_OPAQUE], and clears out @@ -235,36 +235,36 @@ impl NcCell { crate::nccell_set_bg_palindex(self, index); } - /// Sets the background [NcRgb] and marks it as not using the default color. + /// Sets the background [`NcRgb`] and marks it as not using the default color. /// /// *C style function: [nccell_set_bg_rgb()][crate::nccell_set_bg_rgb].* pub fn set_bg_rgb(&mut self, rgb: NcRgb) { crate::nccell_set_bg_rgb(self, rgb); } - /// Sets the background [NcColor] RGB components, and marks it as not using + /// Sets the background RGB [`NcComponent`]s, and marks it as not using /// the "default color". /// /// *C style function: [nccell_set_bg_rgb8()][crate::nccell_set_bg_rgb8].* - pub fn set_bg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) { + pub fn set_bg_rgb8(&mut self, red: NcComponent, green: NcComponent, blue: NcComponent) { crate::nccell_set_bg_rgb8(self, red, green, blue); } - /// Sets the foreground [NcAlphaBits]. + /// Sets the foreground [`NcAlphaBits`]. /// /// *C style function: [nccell_set_fg_alpha()][crate::nccell_set_fg_alpha].* pub fn set_fg_alpha(&mut self, alpha: NcAlphaBits) { crate::nccell_set_fg_alpha(self, alpha); } - /// Indicates to use the "default color" for the foreground [NcChannel]. + /// Indicates to use the "default color" for the foreground [`NcChannel`]. /// /// *C style function: [nccell_set_fg_default()][crate::nccell_set_fg_default].* pub fn set_fg_default(&mut self) { crate::nccell_set_fg_default(self); } - /// Sets the foreground [NcPaletteIndex]. + /// Sets the foreground [`NcPaletteIndex`]. /// /// Also sets [NCALPHA_FG_PALETTE][crate::NCALPHA_FG_PALETTE] and /// [NCALPHA_OPAQUE][crate::NCALPHA_OPAQUE], and clears out @@ -275,26 +275,26 @@ impl NcCell { crate::nccell_set_fg_palindex(self, index); } - /// Sets the foreground [NcRgb] and marks it as not using the default color. + /// Sets the foreground [`NcRgb`] and marks it as not using the default color. /// /// *C style function: [nccell_set_fg_rgb()][crate::nccell_set_fg_rgb].* pub fn set_fg_rgb(&mut self, rgb: NcRgb) { crate::nccell_set_fg_rgb(self, rgb); } - /// Sets the foreground [NcColor] RGB components, and marks it as not using + /// Sets the foreground RGB [`NcComponent`]s, and marks it as not using /// the "default color". /// /// *C style function: [nccell_set_fg_rgb8()][crate::nccell_set_fg_rgb8].* - pub fn set_fg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) { + pub fn set_fg_rgb8(&mut self, red: NcComponent, green: NcComponent, blue: NcComponent) { crate::nccell_set_fg_rgb8(self, red, green, blue); } } /// # `NcCell` methods: other components impl NcCell { - /// Returns true if the two cells have distinct [NcEgc]s, attributes, - /// or [NcChannel]s. + /// Returns true if the two cells have distinct [`NcEgc`]s, attributes, + /// or [`NcChannel`]s. /// /// The actual egcpool index needn't be the same--indeed, the planes /// needn't even be the same. Only the expanded NcEgc must be bit-equal. @@ -304,7 +304,7 @@ impl NcCell { crate::nccellcmp(plane1, cell1, plane2, cell2) } - /// Saves the [NcStyle] and the [NcChannelPair], and returns the [NcEgc]. + /// Saves the [`NcStyle`] and the [`NcChannelPair`], and returns the [`NcEgc`]. /// (These are the three elements of an NcCell). /// /// *C style function: [nccell_fg_alpha()][crate::nccell_fg_alpha].* @@ -317,7 +317,7 @@ impl NcCell { crate::nccell_extract(plane, self, styles, channels) } - /// Returns the [NcEgc] of the NcCell. + /// Returns the [`NcEgc`] of the NcCell. /// /// See also: [extended_gcluster][NcCell#method.extended_gcluster] method. /// @@ -327,28 +327,28 @@ impl NcCell { crate::nccell_extract(plane, self, &mut _styles, &mut _channels) } - /// Returns the [NcStyle] bits. + /// Returns the [`NcStyle`] bits. /// /// *C style function: [nccell_styles()][crate::nccell_styles].* pub fn styles(&mut self) -> NcStyle { crate::nccell_styles(self) } - /// Removes the specified [NcStyle] bits. + /// Removes the specified [`NcStyle`] bits. /// /// *C style function: [nccell_off()][crate::nccell_off_styles].* pub fn off_styles(&mut self, stylebits: NcStyle) { crate::nccell_off_styles(self, stylebits) } - /// Adds the specified [NcStyle] bits. + /// Adds the specified [`NcStyle`] bits. /// /// *C style function: [nccell_on()][crate::nccell_on_styles].* pub fn on_styles(&mut self, stylebits: NcStyle) { crate::nccell_on_styles(self, stylebits) } - /// Sets just the specified [NcStyle] bits. + /// Sets just the specified [`NcStyle`] bits. /// /// *C style function: [nccell_set_styles()][crate::nccell_set_styles].* pub fn set_styles(&mut self, stylebits: NcStyle) { @@ -358,7 +358,7 @@ impl NcCell { /// # `NcCell` methods: text impl NcCell { - // /// Returns a pointer to the [NcEgc] of this NcCell in the [NcPlane] `plane`. + // /// Returns a pointer to the [`NcEgc`] of this NcCell in the [NcPlane] `plane`. // /// // /// This pointer can be invalidated by any further operation on the referred // /// plane, so… watch out! @@ -369,7 +369,7 @@ impl NcCell { // egcpointer // } - /// Copies the UTF8-encoded [NcEgc] out of this NcCell, + /// Copies the UTF8-encoded [`NcEgc`] out of this NcCell, /// whether simple or complex. /// /// The result is not tied to the [NcPlane], @@ -404,11 +404,11 @@ impl NcCell { /// # `NcCell` methods: boxes impl NcCell { - /// Loads up six cells with the [NcEgc]s necessary to draw a box. + /// Loads up six cells with the [`NcEgc`]s necessary to draw a box. /// - /// On error, any [NcCell]s this function might have loaded before the error + /// On error, any [`NcCell`]s this function might have loaded before the error /// are [release][NcCell#method.release]d. - /// There must be at least six [NcEgc]s in `gcluster`. + /// There must be at least six [`NcEgc`]s in `gcluster`. /// /// *C style function: [nccells_load_box()][crate::nccells_load_box].* pub fn load_box( diff --git a/rust/src/cells/mod.rs b/rust/src/cells/mod.rs index 22bc50c5c..f883d9be2 100644 --- a/rust/src/cells/mod.rs +++ b/rust/src/cells/mod.rs @@ -164,20 +164,24 @@ use crate::{NcChannel, NcPlane}; /// have two bits of inverted alpha. The actual grapheme written to a cell is /// the topmost non-zero grapheme. /// -/// - If its alpha is 00 ([`NCALPHA_OPAQUE`]) its foreground color is used unchanged. +/// - If its alpha is 00 ([`NCALPHA_OPAQUE`][crate::NCALPHA_OPAQUE]) +/// its foreground color is used unchanged. /// -/// - If its alpha is 10 ([`NCALPHA_TRANSPARENT`]) its foreground color is derived +/// - If its alpha is 10 ([`NCALPHA_TRANSPARENT`][crate::NCALPHA_TRANSPARENT]) +/// its foreground color is derived /// entirely from cells underneath it. /// -/// - If its alpha is 01 ([`NCALPHA_BLEND`]) the result will be a composite. +/// - If its alpha is 01 ([`NCALPHA_BLEND`][crate::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 ([`NCALPHA_HIGHCONTRAST`]) requests high-contrast -/// text (relative to the computed background). +/// A foreground alpha of 11 +/// ([`NCALPHA_HIGHCONTRAST`][crate::NCALPHA_HIGHCONTRAST]) +/// requests high-contrast text (relative to the computed background). /// A background alpha of 11 is currently forbidden. /// /// ## Precedence diff --git a/rust/src/cells/reimplemented.rs b/rust/src/cells/reimplemented.rs index 2e9ba2923..6e7f354e6 100644 --- a/rust/src/cells/reimplemented.rs +++ b/rust/src/cells/reimplemented.rs @@ -3,7 +3,7 @@ use libc::strcmp; use crate::{ - cstring, nccell_release, NcAlphaBits, NcCell, NcChannel, NcChannelPair, NcColor, NcEgc, + cstring, nccell_release, NcAlphaBits, NcCell, NcChannel, NcChannelPair, NcComponent, NcEgc, 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, @@ -11,7 +11,7 @@ use crate::{ // Alpha ----------------------------------------------------------------------- -/// Extracts the foreground [NcAlphaBits] from an [NcCell] (shifted to LSBs). +/// Extracts the foreground [`NcAlphaBits`] from an [`NcCell`] (shifted to LSBs). /// /// *Method: NcCell.[fg_alpha()][NcCell#method.fg_alpha].* #[inline] @@ -19,7 +19,7 @@ pub fn nccell_fg_alpha(cell: &NcCell) -> NcAlphaBits { crate::ncchannels_fg_alpha(cell.channels) } -/// Extracts the background [NcAlphaBits] from an [NcCell] (shifted to LSBs). +/// Extracts the background [`NcAlphaBits`] from an [`NcCell`] (shifted to LSBs). /// /// *Method: NcCell.[bg_alpha()][NcCell#method.bg_alpha].* #[inline] @@ -27,7 +27,7 @@ pub fn nccell_bg_alpha(cell: &NcCell) -> NcAlphaBits { crate::ncchannels_bg_alpha(cell.channels) } -/// Sets the foreground [NcAlphaBits] of an [NcCell]. +/// Sets the foreground [`NcAlphaBits`] of an [`NcCell`]. /// /// *Method: NcCell.[set_fg_alpha()][NcCell#method.set_fg_alpha].* #[inline] @@ -35,7 +35,7 @@ pub fn nccell_set_fg_alpha(cell: &mut NcCell, alpha: NcAlphaBits) { crate::ncchannels_set_fg_alpha(&mut cell.channels, alpha); } -/// Sets the background [NcAlphaBits] of an [NcCell]. +/// Sets the background [`NcAlphaBits`] of an [`NcCell`]. /// /// *Method: NcCell.[set_bg_alpha()][NcCell#method.set_bg_alpha].* #[inline] @@ -43,57 +43,67 @@ pub fn nccell_set_bg_alpha(cell: &mut NcCell, alpha: NcAlphaBits) { crate::ncchannels_set_bg_alpha(&mut cell.channels, alpha); } -// NcColor --------------------------------------------------------------------- +// NcComponent --------------------------------------------------------------------- -/// Gets the foreground [NcColor] RGB components of an [NcCell], -/// and returns the [NcChannel] (which can have some extra bits set). +/// Gets the foreground [`NcComponent`]s of an [`NcCell`], +/// and returns the [`NcChannel`] (which can have some extra bits set). /// /// *Method: NcCell.[fg_rgb8()][NcCell#method.fg_rgb8].* #[inline] pub fn nccell_fg_rgb8( cell: &NcCell, - red: &mut NcColor, - green: &mut NcColor, - blue: &mut NcColor, + red: &mut NcComponent, + green: &mut NcComponent, + blue: &mut NcComponent, ) -> NcChannel { crate::ncchannels_fg_rgb8(cell.channels, red, green, blue) } -/// Gets the background [NcColor] RGB components of an [NcCell], -/// and returns the [NcChannel] (which can have some extra bits set). +/// Gets the background [`NcComponent`]s of an [`NcCell`], +/// and returns the [`NcChannel`] (which can have some extra bits set). /// /// *Method: NcCell.[bg_rgb8()][NcCell#method.bg_rgb8].* #[inline] pub fn nccell_bg_rgb8( cell: &NcCell, - red: &mut NcColor, - green: &mut NcColor, - blue: &mut NcColor, + red: &mut NcComponent, + green: &mut NcComponent, + blue: &mut NcComponent, ) -> NcChannel { crate::ncchannels_bg_rgb8(cell.channels, red, green, blue) } -/// Sets the foreground [NcColor] RGB components of the [NcCell], +/// Sets the foreground [`NcComponent`]s of the [`NcCell`], /// and marks it as not using the "default color". /// /// *Method: NcCell.[set_fg_rgb8()][NcCell#method.set_fg_rgb8].* #[inline] -pub fn nccell_set_fg_rgb8(cell: &mut NcCell, red: NcColor, green: NcColor, blue: NcColor) { +pub fn nccell_set_fg_rgb8( + cell: &mut NcCell, + red: NcComponent, + green: NcComponent, + blue: NcComponent, +) { crate::ncchannels_set_fg_rgb8(&mut cell.channels, red, green, blue); } -/// Sets the background [NcColor] RGB components of the [NcCell], +/// Sets the background [`NcComponent`]s of the [`NcCell`], /// and marks it as not using the "default color". /// /// *Method: NcCell.[set_bg_rgb8()][NcCell#method.set_bg_rgb8].* #[inline] -pub fn nccell_set_bg_rgb8(cell: &mut NcCell, red: NcColor, green: NcColor, blue: NcColor) { +pub fn nccell_set_bg_rgb8( + cell: &mut NcCell, + red: NcComponent, + green: NcComponent, + blue: NcComponent, +) { crate::ncchannels_set_bg_rgb8(&mut cell.channels, red, green, blue); } // NcRgb ----------------------------------------------------------------------- -/// Gets the foreground [NcRgb] from an [NcCell] (shifted to LSBs). +/// Gets the foreground [`NcRgb`] from an [`NcCell`] (shifted to LSBs). /// /// *Method: NcCell.[fg_rgb()][NcCell#method.fg_rgb].* #[inline] @@ -101,7 +111,7 @@ pub fn nccell_fg_rgb(cell: &NcCell) -> NcRgb { crate::ncchannels_fg_rgb(cell.channels) } -/// Gets the background [NcRgb] from an [NcCell] (shifted to LSBs). +/// Gets the background [`NcRgb`] from an [`NcCell`] (shifted to LSBs). /// /// *Method: NcCell.[bg_rgb()][NcCell#method.bg_rgb].* #[inline] @@ -109,7 +119,7 @@ pub fn nccell_bg_rgb(cell: &NcCell) -> NcRgb { crate::ncchannels_bg_rgb(cell.channels) } -/// Sets the foreground [NcRgb] of an [NcCell], +/// Sets the foreground [`NcRgb`] of an [`NcCell`], /// and marks it as not using the default color. /// /// *Method: NcCell.[set_fg_rgb()][NcCell#method.set_fg_rgb].* @@ -118,7 +128,7 @@ pub fn nccell_set_fg_rgb(cell: &mut NcCell, rgb: NcRgb) { crate::ncchannels_set_fg_rgb(&mut cell.channels, rgb); } -/// Sets the background [NcRgb] of an [NcCell], +/// Sets the background [`NcRgb`] of an [`NcCell`], /// and marks it as not using the default color. /// /// *Method: NcCell.[set_bg_rgb()][NcCell#method.set_bg_rgb].* @@ -129,8 +139,8 @@ pub fn nccell_set_bg_rgb(cell: &mut NcCell, rgb: NcRgb) { // Default --------------------------------------------------------------------- -/// Indicates to use the "default color" for the foreground [NcChannel] -/// of an [NcCell]. +/// Indicates to use the "default color" for the foreground [`NcChannel`] +/// of an [`NcCell`]. /// /// *Method: NcCell.[set_fg_default()][NcCell#method.set_fg_default].* #[inline] @@ -138,8 +148,8 @@ pub fn nccell_set_fg_default(cell: &mut NcCell) { crate::ncchannels_set_fg_default(&mut cell.channels); } -/// Indicates to use the "default color" for the background [NcChannel] -/// of an [NcCell]. +/// Indicates to use the "default color" for the background [`NcChannel`] +/// of an [`NcCell`]. /// /// *Method: NcCell.[set_bg_default()][NcCell#method.set_bg_default].* #[inline] @@ -147,7 +157,7 @@ pub fn nccell_set_bg_default(cell: &mut NcCell) { crate::ncchannels_set_bg_default(&mut cell.channels); } -/// Is the foreground [NcChannel] of this [NcCell] using the +/// Is the foreground [`NcChannel`] of this [`NcCell`] using the /// "default foreground color"? /// /// *Method: NcCell.[fg_default_p()][NcCell#method.fg_default_p].* @@ -156,7 +166,7 @@ pub fn nccell_fg_default_p(cell: &NcCell) -> bool { crate::ncchannels_fg_default_p(cell.channels) } -/// Is the background [NcChannel] of this [NcCell] using the +/// Is the background [`NcChannel`] of this [`NcCell`] using the /// "default background color"? /// /// The "default background color" must generally be used to take advantage of @@ -170,8 +180,8 @@ pub fn nccell_bg_default_p(cell: &NcCell) -> bool { // Palette --------------------------------------------------------------------- -/// Is the foreground [NcChannel] of this [NcCell] using an -/// [NcPaletteIndex] [indexed][NcPaletteIndex] [NcPalette][crate::NcPalette] color? +/// Is the foreground [`NcChannel`] of this [`NcCell`] using an +/// [`NcPaletteIndex`] indexed [`NcPalette`][crate::NcPalette] color? /// /// *Method: NcCell.[fg_palindex_p()][NcCell#method.fg_palindex_p].* #[inline] @@ -179,8 +189,8 @@ pub fn nccell_fg_palindex_p(cell: &NcCell) -> bool { crate::ncchannels_fg_palindex_p(cell.channels) } -/// Is the background [NcChannel] of this [NcCell] using an -/// [NcPaletteIndex] [indexed][NcPaletteIndex] [NcPalette][crate::NcPalette] color? +/// Is the background [`NcChannel`] of this [`NcCell`] using an +/// [`NcPaletteIndex`] indexed [`NcPalette`][crate::NcPalette] color? /// /// *Method: NcCell.[bg_palindex_p()][NcCell#method.bg_palindex_p].* #[inline] @@ -188,7 +198,7 @@ pub fn nccell_bg_palindex_p(cell: &NcCell) -> bool { crate::ncchannels_bg_palindex_p(cell.channels) } -/// Gets the [NcPaletteIndex] of the foreground [NcChannel] of the [NcCell]. +/// Gets the [`NcPaletteIndex`] of the foreground [`NcChannel`] of the [`NcCell`]. /// /// *Method: NcCell.[fg_palindex()][NcCell#method.fg_palindex].* #[inline] @@ -197,7 +207,7 @@ pub const fn nccell_fg_palindex(cell: &NcCell) -> NcPaletteIndex { ((cell.channels & 0xff00000000 as NcChannelPair) >> 32) as NcPaletteIndex } -/// Gets the [NcPaletteIndex] of the background [NcChannel] of the [NcCell]. +/// Gets the [`NcPaletteIndex`] of the background [`NcChannel`] of the [`NcCell`]. /// /// *Method: NcCell.[bg_palindex()][NcCell#method.bg_palindex].* #[inline] @@ -206,7 +216,7 @@ pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex { (cell.channels & 0xff) as NcPaletteIndex } -/// Sets an [NcCell]'s foreground [NcPaletteIndex]. +/// Sets an [`NcCell`]'s foreground [`NcPaletteIndex`]. /// /// Also sets [NCALPHA_FG_PALETTE] and [NCALPHA_OPAQUE], /// and clears out [NCALPHA_FGDEFAULT_MASK]. @@ -224,10 +234,10 @@ pub fn nccell_set_fg_palindex(cell: &mut NcCell, index: NcPaletteIndex) { cell.channels |= (index as NcChannelPair) << 32; } -/// Sets an [NcCell]'s background [NcPaletteIndex]. +/// Sets an [`NcCell`]'s background [`NcPaletteIndex`]. /// -/// Also sets [NCALPHA_BG_PALETTE] and [NCALPHA_OPAQUE], -/// and clears out [NCALPHA_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].* // @@ -243,7 +253,7 @@ pub fn nccell_set_bg_palindex(cell: &mut NcCell, index: NcPaletteIndex) { // Styles ---------------------------------------------------------------------- -/// Extracts the [NcStyle] bits from an [NcCell]. +/// Extracts the [`NcStyle`] bits from an [`NcCell`]. /// /// *Method: NcCell.[cell_styles()][NcCell#method.cell_styles].* #[inline] @@ -251,7 +261,7 @@ pub const fn nccell_styles(cell: &NcCell) -> NcStyle { cell.stylemask } -/// Adds the specified [NcStyle] bits to an [NcCell]'s existing spec., +/// Adds the specified [`NcStyle`] bits to an [`NcCell`]'s existing spec., /// whether they're actively supported or not. /// /// *Method: NcCell.[styles_on()][NcCell#method.styles_on].* @@ -260,7 +270,7 @@ pub fn nccell_on_styles(cell: &mut NcCell, stylebits: NcStyle) { cell.stylemask |= stylebits & NCSTYLE_MASK as u16; } -/// Removes the specified [NcStyle] bits from an [NcCell]'s existing spec. +/// Removes the specified [`NcStyle`] bits from an [`NcCell`]'s existing spec. /// /// *Method: NcCell.[styles_off()][NcCell#method.styles_off].* #[inline] @@ -268,7 +278,7 @@ pub fn nccell_off_styles(cell: &mut NcCell, stylebits: NcStyle) { cell.stylemask &= !(stylebits & NCSTYLE_MASK as u16); } -/// Sets *just* the specified [NcStyle] bits for an [NcCell], +/// Sets *just* the specified [`NcStyle`] bits for an [`NcCell`], /// whether they're actively supported or not. /// /// *Method: NcCell.[styles_set()][NcCell#method.styles_set].* @@ -279,7 +289,7 @@ pub fn nccell_set_styles(cell: &mut NcCell, stylebits: NcStyle) { // Chars ----------------------------------------------------------------------- -/// Does the [NcCell] contain an East Asian Wide codepoint? +/// Does the [`NcCell`] contain an East Asian Wide codepoint? /// /// *Method: NcCell.[double_wide_p()][NcCell#method.double_wide_p].* #[inline] @@ -303,7 +313,7 @@ pub const fn nccell_wide_left_p(cell: &NcCell) -> bool { nccell_double_wide_p(cell) && cell.gcluster != 0 } -// /// Loads a 7-bit [NcEgc] character into the [NcCell]. +// /// Loads a 7-bit [`NcEgc`] character into the [`NcCell`]. // /// // /// *Method: NcCell.[load_char()][NcCell#method.load_char].* // // @@ -344,7 +354,7 @@ pub const fn nccell_wide_left_p(cell: &NcCell) -> bool { // return nccell_load(n, c, gcluster); // } -/// Copies the UTF8-encoded [NcEgc] out of the [NcCell], whether simple or complex. +/// Copies the UTF8-encoded [`NcEgc`] out of the [`NcCell`], whether simple or complex. /// /// The result is not tied to the [NcPlane], /// and persists across erases and destruction. @@ -365,8 +375,8 @@ pub fn nccell_strdup(plane: &NcPlane, cell: &NcCell) -> NcEgc { // Misc. ----------------------------------------------------------------------- -/// Saves the [NcStyle] and the [NcChannelPair], -/// and returns the [NcEgc], of an [NcCell]. +/// Saves the [`NcStyle`] and the [`NcChannelPair`], +/// and returns the [`NcEgc`], of an [`NcCell`]. /// /// *Method: NcCell.[extract()][NcCell#method.extract].* #[inline] @@ -385,7 +395,7 @@ pub fn nccell_extract( nccell_strdup(plane, cell) } -/// Returns true if the two cells are distinct [NcEgc]s, attributes, or channels. +/// Returns true if the two cells are distinct [`NcEgc`]s, attributes, or channels. /// /// The actual egcpool index needn't be the same--indeed, the planes needn't even /// be the same. Only the expanded NcEgc must be equal. The NcEgc must be bit-equal; @@ -409,7 +419,7 @@ pub fn nccellcmp(plane1: &NcPlane, cell1: &NcCell, plane2: &NcPlane, cell2: &NcC } } -/// Initializes (zeroes out) an [NcCell]. +/// Initializes (zeroes out) an [`NcCell`]. /// /// *Method: NcCell.[init()][NcCell#method.init].* #[inline] @@ -417,7 +427,7 @@ pub fn nccell_init(cell: &mut NcCell) { *cell = unsafe { core::mem::zeroed() } } -/// Same as [nccell_load][crate::nccell_load], plus blasts the styling with +/// Same as [`nccell_load`][crate::nccell_load], plus blasts the styling with /// `style` and `channels`. /// /// - Breaks the UTF-8 string in `gcluster` down, setting up the cell `cell`. @@ -438,12 +448,12 @@ pub fn nccell_prime( unsafe { crate::nccell_load(plane, cell, cstring![gcluster]) } } -/// Loads up six cells with the [NcEgc]s necessary to draw a box. +/// Loads up six cells with the [`NcEgc`]s necessary to draw a box. /// -/// Returns [NCRESULT_OK] on success or [NCRESULT_ERR] on error. +/// Returns [`NCRESULT_OK`] on success or [`NCRESULT_ERR`] on error. /// -/// On error, any [NcCell]s this function might have loaded before the error -/// are [nccell_release]d. There must be at least six [NcEgc]s in `gcluster`. +/// On error, any [`NcCell`]s this function might have loaded before the error +/// are [nccell_release]d. There must be at least six [`NcEgc`]s in `gcluster`. /// /// *Method: NcCell.[load_box()][NcCell#method.load_box].* pub fn nccells_load_box( diff --git a/rust/src/channel/methods.rs b/rust/src/channel/methods.rs index 2516a839d..63434e8d9 100644 --- a/rust/src/channel/methods.rs +++ b/rust/src/channel/methods.rs @@ -1,7 +1,7 @@ //! `NcChannel*` methods and associated functions. #![allow(clippy::unnecessary_cast)] -use crate::{NcAlphaBits, NcChannel, NcChannelPair, NcColor, NcPaletteIndex, NcRgb}; +use crate::{NcAlphaBits, NcChannel, NcChannelPair, NcComponent, NcPaletteIndex, NcRgb}; /// Enables the [`NcChannel`] methods. pub trait NcChannelMethods { @@ -10,8 +10,8 @@ pub trait NcChannelMethods { fn with_default() -> Self; fn with_rgb(rgb: NcRgb) -> Self; fn with_rgb_alpha(rgb: NcRgb, alpha: NcAlphaBits) -> Self; - fn with_rgb8(r: NcColor, g: NcColor, b: NcColor) -> Self; - fn with_rgb8_alpha(r: NcColor, g: NcColor, b: NcColor, alpha: NcAlphaBits) -> Self; + fn with_rgb8(r: NcComponent, g: NcComponent, b: NcComponent) -> Self; + fn with_rgb8_alpha(r: NcComponent, g: NcComponent, b: NcComponent, alpha: NcAlphaBits) -> Self; // methods fn fcombine(&self, bchannel: NcChannel) -> NcChannelPair; @@ -22,14 +22,14 @@ pub trait NcChannelMethods { fn set(&mut self, rgb: NcRgb) -> Self; - fn rgb8(&self) -> (NcColor, NcColor, NcColor); - fn set_rgb8(&mut self, r: NcColor, g: NcColor, b: NcColor) -> Self; - fn r(&self) -> NcColor; - fn g(&self) -> NcColor; - fn b(&self) -> NcColor; - fn set_r(&mut self, r: NcColor) -> Self; - fn set_g(&mut self, g: NcColor) -> Self; - fn set_b(&mut self, b: NcColor) -> Self; + fn rgb8(&self) -> (NcComponent, NcComponent, NcComponent); + fn set_rgb8(&mut self, r: NcComponent, g: NcComponent, b: NcComponent) -> Self; + fn r(&self) -> NcComponent; + fn g(&self) -> NcComponent; + fn b(&self) -> NcComponent; + fn set_r(&mut self, r: NcComponent) -> Self; + fn set_g(&mut self, g: NcComponent) -> Self; + fn set_b(&mut self, b: NcComponent) -> Self; fn rgb(&self) -> NcRgb; fn set_rgb(&mut self, rgb: NcRgb) -> Self; @@ -56,25 +56,30 @@ pub trait NcChannelPairMethods { ) -> Self; fn with_rgb_alpha_both(rgb: NcRgb, alpha: NcAlphaBits) -> Self; fn with_rgb8( - fg_r: NcColor, - fg_g: NcColor, - fg_b: NcColor, - bg_r: NcColor, - bg_g: NcColor, - bg_b: NcColor, + fg_r: NcComponent, + fg_g: NcComponent, + fg_b: NcComponent, + bg_r: NcComponent, + bg_g: NcComponent, + bg_b: NcComponent, ) -> Self; - fn with_rgb8_both(r: NcColor, g: NcColor, b: NcColor) -> Self; + fn with_rgb8_both(r: NcComponent, g: NcComponent, b: NcComponent) -> Self; fn with_rgb8_alpha( - fg_r: NcColor, - fg_g: NcColor, - fg_b: NcColor, + fg_r: NcComponent, + fg_g: NcComponent, + fg_b: NcComponent, fg_alpha: NcAlphaBits, - bg_r: NcColor, - bg_g: NcColor, - bg_b: NcColor, + bg_r: NcComponent, + bg_g: NcComponent, + bg_b: NcComponent, bg_alpha: NcAlphaBits, ) -> Self; - fn with_rgb8_alpha_both(r: NcColor, g: NcColor, b: NcColor, alpha: NcAlphaBits) -> Self; + fn with_rgb8_alpha_both( + r: NcComponent, + g: NcComponent, + b: NcComponent, + alpha: NcAlphaBits, + ) -> Self; // methods fn combine(fchannel: NcChannel, bchannel: NcChannel) -> Self; @@ -94,22 +99,22 @@ pub trait NcChannelPairMethods { fn set_fg_rgb(&mut self, alpha: NcAlphaBits) -> Self; fn set_bg_rgb(&mut self, alpha: NcAlphaBits) -> Self; - fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor); - fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor); - fn set_fg_rgb8(&mut self, r: NcColor, g: NcColor, b: NcColor) -> Self; - fn set_bg_rgb8(&mut self, r: NcColor, g: NcColor, b: NcColor) -> Self; - fn fg_r(&self) -> NcColor; - fn fg_g(&self) -> NcColor; - fn fg_b(&self) -> NcColor; - fn bg_r(&self) -> NcColor; - fn bg_g(&self) -> NcColor; - fn bg_b(&self) -> NcColor; - fn fg_set_r(&mut self, r: NcColor) -> Self; - fn fg_set_g(&mut self, g: NcColor) -> Self; - fn fg_set_b(&mut self, b: NcColor) -> Self; - fn bg_set_r(&mut self, r: NcColor) -> Self; - fn bg_set_g(&mut self, g: NcColor) -> Self; - fn bg_set_b(&mut self, b: NcColor) -> Self; + fn fg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent); + fn bg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent); + fn set_fg_rgb8(&mut self, r: NcComponent, g: NcComponent, b: NcComponent) -> Self; + fn set_bg_rgb8(&mut self, r: NcComponent, g: NcComponent, b: NcComponent) -> Self; + fn fg_r(&self) -> NcComponent; + fn fg_g(&self) -> NcComponent; + fn fg_b(&self) -> NcComponent; + fn bg_r(&self) -> NcComponent; + fn bg_g(&self) -> NcComponent; + fn bg_b(&self) -> NcComponent; + fn fg_set_r(&mut self, r: NcComponent) -> Self; + fn fg_set_g(&mut self, g: NcComponent) -> Self; + fn fg_set_b(&mut self, b: NcComponent) -> Self; + fn bg_set_r(&mut self, r: NcComponent) -> Self; + fn bg_set_g(&mut self, g: NcComponent) -> Self; + fn bg_set_b(&mut self, b: NcComponent) -> Self; fn fg_default_p(&self) -> bool; fn bg_default_p(&self) -> bool; @@ -152,13 +157,13 @@ impl NcChannelMethods for NcChannel { Self::new().set(rgb).set_alpha(alpha) } - /// New NcChannel, expects three RGB [`NcColor`] components. - fn with_rgb8(r: NcColor, g: NcColor, b: NcColor) -> Self { + /// New NcChannel, expects three RGB [`NcComponent`] components. + fn with_rgb8(r: NcComponent, g: NcComponent, b: NcComponent) -> Self { Self::new().set_rgb8(r, g, b) } - /// New NcChannel, expects three RGB [`NcColor`] components & [`NcAlphaBits`]. - fn with_rgb8_alpha(r: NcColor, g: NcColor, b: NcColor, alpha: NcAlphaBits) -> Self { + /// New NcChannel, expects three RGB [`NcComponent`] components & [`NcAlphaBits`]. + fn with_rgb8_alpha(r: NcComponent, g: NcComponent, b: NcComponent, alpha: NcAlphaBits) -> Self { Self::new().set_rgb8(r, g, b).set_alpha(alpha) } @@ -212,71 +217,71 @@ impl NcChannelMethods for NcChannel { *self } - // NcColor + // NcComponent - /// Gets the three [`NcColor`]s. + /// Gets the three [`NcComponent`]s. /// /// *C style function: [channel_rgb8()][crate::ncchannel_rgb8].* - fn rgb8(&self) -> (NcColor, NcColor, NcColor) { + fn rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); crate::ncchannel_rgb8(*self, &mut r, &mut g, &mut b); (r, g, b) } - /// Sets the three [`NcColor`]s, and + /// Sets the three [`NcComponent`]s, and /// marks the NcChannel as NOT using the "default color". /// /// *C style function: [channel_set_rgb8()][crate::ncchannel_set_rgb8].* - fn set_rgb8(&mut self, r: NcColor, g: NcColor, b: NcColor) -> Self { + fn set_rgb8(&mut self, r: NcComponent, g: NcComponent, b: NcComponent) -> Self { crate::ncchannel_set_rgb8(self, r, g, b); *self } - /// Gets the red [`NcColor`]. + /// Gets the red [`NcComponent`]. /// /// *C style function: [channel_r()][crate::ncchannel_r].* - fn r(&self) -> NcColor { + fn r(&self) -> NcComponent { crate::ncchannel_r(*self) } - /// Gets the green [`NcColor`]. + /// Gets the green [`NcComponent`]. /// /// *C style function: [channel_g()][crate::ncchannel_g].* - fn g(&self) -> NcColor { + fn g(&self) -> NcComponent { crate::ncchannel_g(*self) } - /// Gets the blue [`NcColor`]. + /// Gets the blue [`NcComponent`]. /// /// *C style function: [channel_b()][crate::ncchannel_b].* - fn b(&self) -> NcColor { + fn b(&self) -> NcComponent { crate::ncchannel_b(*self) } - /// Sets the red [`NcColor`], and returns the new `NcChannel`. + /// Sets the red [`NcComponent`], and returns the new `NcChannel`. /// /// *C style function: [channel_set_r()][crate::ncchannel_set_r].* // // Not in the C API - fn set_r(&mut self, r: NcColor) -> Self { + fn set_r(&mut self, r: NcComponent) -> Self { crate::ncchannel_set_r(self, r) } - /// Sets the green [`NcColor`], and returns the new `NcChannel`. + /// Sets the green [`NcComponent`], and returns the new `NcChannel`. /// /// *C style function: [channel_set_g()][crate::ncchannel_set_g].* // // Not in the C API - fn set_g(&mut self, g: NcColor) -> Self { + fn set_g(&mut self, g: NcComponent) -> Self { crate::ncchannel_set_g(self, g) } - /// Sets the blue [`NcColor`], and returns the new `NcChannel`. + /// Sets the blue [`NcComponent`], and returns the new `NcChannel`. /// /// *C style function: [channel_set_b()][crate::ncchannel_set_b].* // // Not in the C API - fn set_b(&mut self, b: NcColor) -> Self { + fn set_b(&mut self, b: NcComponent) -> Self { crate::ncchannel_set_b(self, b) } @@ -393,14 +398,14 @@ impl NcChannelPairMethods for NcChannelPair { Self::combine(channel, channel) } - /// New NcChannelPair, expects three RGB [`NcColor`] components for each channel. + /// New NcChannelPair, expects three RGB [`NcComponent`] components for each channel. fn with_rgb8( - fg_r: NcColor, - fg_g: NcColor, - fg_b: NcColor, - bg_r: NcColor, - bg_g: NcColor, - bg_b: NcColor, + fg_r: NcComponent, + fg_g: NcComponent, + fg_b: NcComponent, + bg_r: NcComponent, + bg_g: NcComponent, + bg_b: NcComponent, ) -> Self { Self::combine( NcChannel::with_rgb8(fg_r, fg_g, fg_b), @@ -408,23 +413,23 @@ impl NcChannelPairMethods for NcChannelPair { ) } - /// New NcChannelPair, expects three RGB [`NcColor`] components for both + /// New NcChannelPair, expects three RGB [`NcComponent`] components for both /// the foreground and background channels. - fn with_rgb8_both(r: NcColor, g: NcColor, b: NcColor) -> Self { + fn with_rgb8_both(r: NcComponent, g: NcComponent, b: NcComponent) -> 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 [`NcComponent`] components & [`NcAlphaBits`] /// for both foreground and background channels. fn with_rgb8_alpha( - fg_r: NcColor, - fg_g: NcColor, - fg_b: NcColor, + fg_r: NcComponent, + fg_g: NcComponent, + fg_b: NcComponent, fg_alpha: NcAlphaBits, - bg_r: NcColor, - bg_g: NcColor, - bg_b: NcColor, + bg_r: NcComponent, + bg_g: NcComponent, + bg_b: NcComponent, bg_alpha: NcAlphaBits, ) -> Self { Self::combine( @@ -433,8 +438,13 @@ impl NcChannelPairMethods for NcChannelPair { ) } - /// New NcChannel, expects three RGB [`NcColor`] components. - fn with_rgb8_alpha_both(r: NcColor, g: NcColor, b: NcColor, alpha: NcAlphaBits) -> Self { + /// New NcChannel, expects three RGB [`NcComponent`] components. + fn with_rgb8_alpha_both( + r: NcComponent, + g: NcComponent, + b: NcComponent, + alpha: NcAlphaBits, + ) -> Self { let channel = NcChannel::new().set_rgb8(r, g, b).set_alpha(alpha); Self::combine(channel, channel) } @@ -540,128 +550,128 @@ impl NcChannelPairMethods for NcChannelPair { *self } - // NcColor + // NcComponent - /// Gets the three foreground [`NcColor`]s (r, g, b). + /// Gets the three foreground [`NcComponent`]s (r, g, b). /// /// *C style function: [channels_fg_rgb8()][crate::ncchannels_fg_rgb8].* - fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor) { + fn fg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); crate::ncchannels_fg_rgb8(*self, &mut r, &mut g, &mut b); (r, g, b) } - /// Gets the three background [`NcColor`]s (r, g, b). + /// Gets the three background [`NcComponent`]s (r, g, b). /// /// *C style function: [channels_bg_rgb8()][crate::ncchannels_bg_rgb8].* - fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor) { + fn bg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); crate::ncchannels_bg_rgb8(*self, &mut r, &mut g, &mut b); (r, g, b) } - /// Sets the three foreground [`NcColor`]s (r, g, b), and + /// Sets the three foreground [`NcComponent`]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 { + fn set_fg_rgb8(&mut self, r: NcComponent, g: NcComponent, b: NcComponent) -> Self { crate::ncchannels_set_fg_rgb8(self, r, g, b) } - /// Sets the three background [`NcColor`]s (r, g, b), and + /// Sets the three background [`NcComponent`]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 { + fn set_bg_rgb8(&mut self, r: NcComponent, g: NcComponent, b: NcComponent) -> Self { crate::ncchannels_set_bg_rgb8(self, r, g, b) } - /// Gets the foreground red [`NcColor`]. + /// Gets the foreground red [`NcComponent`]. /// /// *(No equivalent C style function)* - fn fg_r(&self) -> NcColor { + fn fg_r(&self) -> NcComponent { crate::ncchannel_r(crate::ncchannels_fchannel(*self)) } - /// Gets the foreground green [`NcColor`]. + /// Gets the foreground green [`NcComponent`]. /// /// *(No equivalent C style function)* - fn fg_g(&self) -> NcColor { + fn fg_g(&self) -> NcComponent { crate::ncchannel_g(crate::ncchannels_fchannel(*self)) } - /// Gets the foreground blue [`NcColor`]. + /// Gets the foreground blue [`NcComponent`]. /// /// *(No equivalent C style function)* - fn fg_b(&self) -> NcColor { + fn fg_b(&self) -> NcComponent { crate::ncchannel_b(crate::ncchannels_fchannel(*self)) } - /// Gets the background red [`NcColor`]. + /// Gets the background red [`NcComponent`]. /// /// *(No equivalent C style function)* - fn bg_r(&self) -> NcColor { + fn bg_r(&self) -> NcComponent { crate::ncchannel_r(crate::ncchannels_bchannel(*self)) } - /// Gets the background green [`NcColor`]. + /// Gets the background green [`NcComponent`]. /// /// *(No equivalent C style function)* - fn bg_g(&self) -> NcColor { + fn bg_g(&self) -> NcComponent { crate::ncchannel_g(crate::ncchannels_bchannel(*self)) } - /// Gets the background blue [`NcColor`]. + /// Gets the background blue [`NcComponent`]. /// /// *(No equivalent C style function)* - fn bg_b(&self) -> NcColor { + fn bg_b(&self) -> NcComponent { crate::ncchannel_b(crate::ncchannels_bchannel(*self)) } - /// Sets the foreground red [`NcColor`], and returns the new `NcChannelPair`. + /// Sets the foreground red [`NcComponent`], and returns the new `NcChannelPair`. /// /// *(No equivalent C style function)* - fn fg_set_r(&mut self, r: NcColor) -> Self { + fn fg_set_r(&mut self, r: NcComponent) -> Self { let (_, g, b) = self.bg_rgb8(); crate::ncchannels_set_fg_rgb8(self, r, g, b) } - /// Sets the foreground green [`NcColor`], and returns the new `NcChannelPair`. + /// Sets the foreground green [`NcComponent`], and returns the new `NcChannelPair`. /// /// *(No equivalent C style function)* - fn fg_set_g(&mut self, g: NcColor) -> Self { + fn fg_set_g(&mut self, g: NcComponent) -> Self { let (r, _, b) = self.bg_rgb8(); crate::ncchannels_set_fg_rgb8(self, r, g, b) } - /// Sets the foreground blue [`NcColor`], and returns the new `NcChannelPair`. + /// Sets the foreground blue [`NcComponent`], and returns the new `NcChannelPair`. /// /// *(No equivalent C style function)* - fn fg_set_b(&mut self, b: NcColor) -> Self { + fn fg_set_b(&mut self, b: NcComponent) -> Self { let (r, g, _) = self.bg_rgb8(); crate::ncchannels_set_fg_rgb8(self, r, g, b) } - /// Sets the background red [`NcColor`], and returns the new `NcChannelPair`. + /// Sets the background red [`NcComponent`], and returns the new `NcChannelPair`. /// /// *(No equivalent C style function)* - fn bg_set_r(&mut self, r: NcColor) -> Self { + fn bg_set_r(&mut self, r: NcComponent) -> Self { let (_, g, b) = self.bg_rgb8(); crate::ncchannels_set_bg_rgb8(self, r, g, b) } - /// Sets the background green [`NcColor`], and returns the new `NcChannelPair`. + /// Sets the background green [`NcComponent`], and returns the new `NcChannelPair`. /// /// *(No equivalent C style function)* - fn bg_set_g(&mut self, g: NcColor) -> Self { + fn bg_set_g(&mut self, g: NcComponent) -> Self { let (r, _, b) = self.bg_rgb8(); crate::ncchannels_set_bg_rgb8(self, r, g, b) } - /// Sets the background blue [`NcColor`], and returns the new `NcChannelPair`. + /// Sets the background blue [`NcComponent`], and returns the new `NcChannelPair`. /// /// *(No equivalent C style function)* - fn bg_set_b(&mut self, b: NcColor) -> Self { + fn bg_set_b(&mut self, b: NcComponent) -> Self { let (r, g, _) = self.bg_rgb8(); crate::ncchannels_set_bg_rgb8(self, r, g, b) } diff --git a/rust/src/channel/mod.rs b/rust/src/channel/mod.rs index 218669877..2ab6f7302 100644 --- a/rust/src/channel/mod.rs +++ b/rust/src/channel/mod.rs @@ -66,7 +66,7 @@ //W channels_set_not_default // not in the original C API #[allow(unused_imports)] // for the doc comments -use crate::NcRgba; +use crate::{NcCell, NcRgba}; #[cfg(test)] mod test; @@ -297,9 +297,9 @@ pub type NcChannelPair = u64; /// See also: [NcRgba] and [NcChannel] types. pub type NcRgb = u32; -// NcColor +// NcComponent // -/// 8 bits representing a R/G/B color or alpha channel +/// 8 bits representing an R/G/B color component or an alpha channel component. /// /// ## Diagram /// @@ -307,4 +307,4 @@ pub type NcRgb = u32; /// CCCCCCCC (1 Byte) /// ``` /// `type in C: no data type` -pub type NcColor = u8; +pub type NcComponent = u8; diff --git a/rust/src/channel/reimplemented.rs b/rust/src/channel/reimplemented.rs index 665fe002d..9a66b9f4a 100644 --- a/rust/src/channel/reimplemented.rs +++ b/rust/src/channel/reimplemented.rs @@ -1,14 +1,14 @@ //! `channel*_*` reimplemented functions. use crate::{ - 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, + NcAlphaBits, NcChannel, NcChannelPair, NcComponent, 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 ----------------------------------------------------------------------- -/// Gets the [NcAlphaBits] from an [NcChannel]. +/// Gets the [`NcAlphaBits`] from an [`NcChannel`]. /// /// *Method: NcChannel.[alpha()][NcChannel#method.alpha]* #[inline] @@ -16,7 +16,7 @@ pub const fn ncchannel_alpha(channel: NcChannel) -> NcAlphaBits { channel & NCCHANNEL_ALPHA_MASK } -/// Sets the [NcAlphaBits] of an [NcChannel]. +/// Sets the [`NcAlphaBits`] of an [`NcChannel`]. /// /// *Method: NcChannel.[set_alpha()][NcChannel#method.set_alpha]* #[inline] @@ -30,7 +30,7 @@ pub fn ncchannel_set_alpha(channel: &mut NcChannel, alpha: NcAlphaBits) { } } -/// Gets the foreground [NcAlphaBits] from an [NcChannelPair], shifted to LSBs. +/// Gets the foreground [`NcAlphaBits`] from an [`NcChannelPair`], shifted to LSBs. /// /// *Method: NcChannelPair.[fg_alpha()][NcChannelPair#method.fg_alpha]* #[inline] @@ -38,7 +38,7 @@ pub const fn ncchannels_fg_alpha(channels: NcChannelPair) -> NcAlphaBits { ncchannel_alpha(ncchannels_fchannel(channels)) } -/// Gets the background [NcAlphaBits] from an [NcChannelPair], shifted to LSBs. +/// Gets the background [`NcAlphaBits`] from an [`NcChannelPair`], shifted to LSBs. /// /// *Method: NcChannelPair.[bg_alpha()][NcChannelPair#method.bg_alpha]* #[inline] @@ -46,7 +46,7 @@ pub const fn ncchannels_bg_alpha(channels: NcChannelPair) -> NcAlphaBits { ncchannel_alpha(ncchannels_bchannel(channels)) } -/// Sets the [NcAlphaBits] of the foreground [NcChannel] of an [NcChannelPair]. +/// Sets the [`NcAlphaBits`] of the foreground [`NcChannel`] of an [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_fg_alpha()][NcChannelPair#method.set_fg_alpha]* #[inline] @@ -56,7 +56,7 @@ pub fn ncchannels_set_fg_alpha(channels: &mut NcChannelPair, alpha: NcAlphaBits) *channels = (channel as NcChannelPair) << 32 | *channels & 0xffffffff_u64; } -/// Sets the [NcAlphaBits] of the background [NcChannel] of an [NcChannelPair]. +/// Sets the [`NcAlphaBits`] of the background [`NcChannel`] of an [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_bg_alpha()][NcChannelPair#method.set_bg_alpha]* #[inline] @@ -73,7 +73,7 @@ pub fn ncchannels_set_bg_alpha(channels: &mut NcChannelPair, alpha: NcAlphaBits) // Channels -------------------------------------------------------------------- -/// Extracts the background [NcChannel] from a [NcChannelPair]. +/// Extracts the background [`NcChannel`] from a [`NcChannelPair`]. /// /// *Method: NcChannelPair.[bchannel()][NcChannelPair#method.bchannel]* #[inline] @@ -81,7 +81,7 @@ pub const fn ncchannels_bchannel(channels: NcChannelPair) -> NcChannel { (channels & 0xffffffff_u64) as NcChannel } -/// Extracts the foreground [NcChannel] from an [NcChannelPair]. +/// Extracts the foreground [`NcChannel`] from an [`NcChannelPair`]. /// /// *Method: NcChannelPair.[fchannel()][NcChannelPair#method.fchannel]* #[inline] @@ -89,7 +89,7 @@ pub const fn ncchannels_fchannel(channels: NcChannelPair) -> NcChannel { ncchannels_bchannel(channels >> 32) } -/// Sets the background [NcChannel] of an [NcChannelPair]. +/// Sets the background [`NcChannel`] of an [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_bchannel()][NcChannelPair#method.set_bchannel]* #[inline] @@ -98,7 +98,7 @@ pub fn ncchannels_set_bchannel(channels: &mut NcChannelPair, bchannel: NcChannel *channels } -/// Sets the foreground [NcChannel] of an [NcChannelPair]. +/// Sets the foreground [`NcChannel`] of an [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_fchannel()][NcChannelPair#method.set_fchannel]* #[inline] @@ -107,7 +107,7 @@ pub fn ncchannels_set_fchannel(channels: &mut NcChannelPair, fchannel: NcChannel *channels } -/// Combines two [NcChannel]s into an [NcChannelPair]. +/// Combines two [`NcChannel`]s into an [`NcChannelPair`]. /// /// *Method: NcChannelPair.[combine()][NcChannelPair#method.combine]* #[inline] @@ -118,74 +118,74 @@ pub fn ncchannels_combine(fchannel: NcChannel, bchannel: NcChannel) -> NcChannel channels } -// NcColor --------------------------------------------------------------------- +// NcComponent --------------------------------------------------------------------- -/// Gets the red [NcColor] from an [NcChannel]. +/// Gets the red [`NcComponent`] from an [`NcChannel`]. /// /// *Method: NcChannel.[r()][NcChannel#method.r]* #[inline] -pub const fn ncchannel_r(channel: NcChannel) -> NcColor { - ((channel & 0xff0000) >> 16) as NcColor +pub const fn ncchannel_r(channel: NcChannel) -> NcComponent { + ((channel & 0xff0000) >> 16) as NcComponent } -/// Gets the green [NcColor] from an [NcChannel]. +/// Gets the green [`NcComponent`] from an [`NcChannel`]. /// /// *Method: NcChannel.[g()][NcChannel#method.g]* #[inline] -pub const fn ncchannel_g(channel: NcChannel) -> NcColor { - ((channel & 0x00ff00) >> 8) as NcColor +pub const fn ncchannel_g(channel: NcChannel) -> NcComponent { + ((channel & 0x00ff00) >> 8) as NcComponent } -/// Gets the blue [NcColor] from an [NcChannel]. +/// Gets the blue [`NcComponent`] from an [`NcChannel`]. /// /// *Method: NcChannel.[b()][NcChannel#method.b]* #[inline] -pub const fn ncchannel_b(channel: NcChannel) -> NcColor { - (channel & 0x0000ff) as NcColor +pub const fn ncchannel_b(channel: NcChannel) -> NcComponent { + (channel & 0x0000ff) as NcComponent } -/// Sets the red [NcColor] of an [NcChannel], and returns it. +/// Sets the red [`NcComponent`] of an [`NcChannel`], and returns it. /// /// *Method: NcChannel.[set_r()][NcChannel#method.set_r]* // // Not in the C API. #[inline] -pub fn ncchannel_set_r(channel: &mut NcChannel, r: NcColor) -> NcChannel { +pub fn ncchannel_set_r(channel: &mut NcChannel, r: NcComponent) -> NcChannel { *channel = (r as NcChannel) << 16 | (*channel & 0xff00) | (*channel & 0xff); *channel } -/// Sets the green [NcColor] of an [NcChannel], and returns it. +/// Sets the green [`NcComponent`] of an [`NcChannel`], and returns it. /// /// *Method: NcChannel.[set_g()][NcChannel#method.set_g]* // // Not in the C API. #[inline] -pub fn ncchannel_set_g(channel: &mut NcChannel, g: NcColor) -> NcChannel { +pub fn ncchannel_set_g(channel: &mut NcChannel, g: NcComponent) -> NcChannel { *channel = (*channel & 0xff0000) | (g as NcChannel) << 8 | (*channel & 0xff); *channel } -/// Sets the blue [NcColor] of an [NcChannel], and returns it. +/// Sets the blue [`NcComponent`] of an [`NcChannel`], and returns it. /// /// *Method: NcChannel.[set_b()][NcChannel#method.set_b]* // // Not in the C API. #[inline] -pub fn ncchannel_set_b(channel: &mut NcChannel, b: NcColor) -> NcChannel { +pub fn ncchannel_set_b(channel: &mut NcChannel, b: NcComponent) -> NcChannel { *channel = (*channel & 0xff0000) | (*channel & 0xff00) | (b as NcChannel); *channel } -/// Gets the three RGB [NcColor]s from an [NcChannel], and returns it. +/// Gets the three RGB [`NcComponent`]s from an [`NcChannel`], and returns it. /// /// *Method: NcChannel.[rgb8()][NcChannel#method.rgb8]* #[inline] pub fn ncchannel_rgb8( channel: NcChannel, - r: &mut NcColor, - g: &mut NcColor, - b: &mut NcColor, + r: &mut NcComponent, + g: &mut NcComponent, + b: &mut NcComponent, ) -> NcChannel { *r = ncchannel_r(channel); *g = ncchannel_g(channel); @@ -193,45 +193,45 @@ pub fn ncchannel_rgb8( channel } -/// Sets the three RGB [NcColor]s an [NcChannel], and marks it as NOT using the +/// Sets the three RGB [`NcComponent`]s an [`NcChannel`], and marks it as NOT using the /// "default color", retaining the other bits unchanged. /// /// *Method: NcChannel.[set_rgb8()][NcChannel#method.set_rgb8]* #[inline] -pub fn ncchannel_set_rgb8(channel: &mut NcChannel, r: NcColor, g: NcColor, b: NcColor) { +pub fn ncchannel_set_rgb8(channel: &mut NcChannel, r: NcComponent, g: NcComponent, b: NcComponent) { let rgb: NcRgb = (r as NcChannel) << 16 | (g as NcChannel) << 8 | (b as NcChannel); *channel = (*channel & !NCALPHA_BG_RGB_MASK) | NCALPHA_BGDEFAULT_MASK | rgb; } -/// Gets the three foreground RGB [NcColor]s from an [NcChannelPair], and -/// returns the foreground [NcChannel] (which can have some extra bits set). +/// Gets the three foreground RGB [`NcComponent`]s from an [`NcChannelPair`], and +/// returns the foreground [`NcChannel`] (which can have some extra bits set). /// /// *Method: NcChannelPair.[fg_rgb8()][NcChannelPair#method.fg_rgb8]* #[inline] pub fn ncchannels_fg_rgb8( channels: NcChannelPair, - r: &mut NcColor, - g: &mut NcColor, - b: &mut NcColor, + r: &mut NcComponent, + g: &mut NcComponent, + b: &mut NcComponent, ) -> NcChannel { ncchannel_rgb8(ncchannels_fchannel(channels), r, g, b) } -/// Gets the three background RGB [NcColor]s from an [NcChannelPair], and -/// returns the background [NcChannel] (which can have some extra bits set). +/// Gets the three background RGB [`NcComponent`]s from an [`NcChannelPair`], and +/// returns the background [`NcChannel`] (which can have some extra bits set). /// /// *Method: NcChannelPair.[bg_rgb8()][NcChannelPair#method.bg_rgb8]* #[inline] pub fn ncchannels_bg_rgb8( channels: NcChannelPair, - r: &mut NcColor, - g: &mut NcColor, - b: &mut NcColor, + r: &mut NcComponent, + g: &mut NcComponent, + b: &mut NcComponent, ) -> NcChannel { ncchannel_rgb8(ncchannels_bchannel(channels), r, g, b) } -/// Sets the three foreground RGB [NcColor]s of an [NcChannelPair], and +/// Sets the three foreground RGB [`NcComponent`]s of an [`NcChannelPair`], and /// marks it as NOT using the "default color", retaining the other bits unchanged. /// /// Unlike the original C API, it also returns the new NcChannelPair. @@ -240,9 +240,9 @@ pub fn ncchannels_bg_rgb8( #[inline] pub fn ncchannels_set_fg_rgb8( channels: &mut NcChannelPair, - r: NcColor, - g: NcColor, - b: NcColor, + r: NcComponent, + g: NcComponent, + b: NcComponent, ) -> NcChannelPair { let mut channel = ncchannels_fchannel(*channels); ncchannel_set_rgb8(&mut channel, r, g, b); @@ -250,7 +250,7 @@ pub fn ncchannels_set_fg_rgb8( *channels } -/// Sets the three background RGB [NcColor]s of an [NcChannelPair], and +/// Sets the three background RGB [`NcComponent`]s of an [`NcChannelPair`], and /// marks it as NOT using the "default color", retaining the other bits unchanged. /// /// Unlike the original C API, it also returns the new NcChannelPair. @@ -259,9 +259,9 @@ pub fn ncchannels_set_fg_rgb8( #[inline] pub fn ncchannels_set_bg_rgb8( channels: &mut NcChannelPair, - r: NcColor, - g: NcColor, - b: NcColor, + r: NcComponent, + g: NcComponent, + b: NcComponent, ) -> NcChannelPair { let mut channel = ncchannels_bchannel(*channels); ncchannel_set_rgb8(&mut channel, r, g, b); @@ -271,7 +271,7 @@ pub fn ncchannels_set_bg_rgb8( // NcRgb ----------------------------------------------------------------------- -/// Gets the foreground [NcRgb] from an [NcChannelPair], shifted to LSBs. +/// Gets the foreground [`NcRgb`] from an [`NcChannelPair`], shifted to LSBs. /// /// *Method: NcChannelPair.[fg_rgb()][NcChannelPair#method.fg_rgb]* #[inline] @@ -279,7 +279,7 @@ pub fn ncchannels_fg_rgb(channels: NcChannelPair) -> NcRgb { ncchannels_fchannel(channels) & NCALPHA_BG_RGB_MASK } -/// Gets the background [NcRgb] from an [NcChannelPair], shifted to LSBs. +/// Gets the background [`NcRgb`] from an [`NcChannelPair`], shifted to LSBs. /// /// *Method: NcChannelPair.[bg_rgb()][NcChannelPair#method.bg_rgb]* #[inline] @@ -287,7 +287,7 @@ pub fn ncchannels_bg_rgb(channels: NcChannelPair) -> NcRgb { ncchannels_bchannel(channels) & NCALPHA_BG_RGB_MASK } -/// Gets the [NcRgb] of an [NcChannel]. +/// Gets the [`NcRgb`] of an [`NcChannel`]. /// /// This function basically removes the 4th byte of the NcChannel. /// @@ -299,7 +299,7 @@ pub const fn ncchannel_rgb(channel: NcChannel) -> NcRgb { channel & NCALPHA_BG_RGB_MASK } -/// Sets the [NcRgb] of an [NcChannel], and marks it as NOT using the +/// Sets the [`NcRgb`] of an [`NcChannel`], and marks it as NOT using the /// "default color", retaining the other bits unchanged. /// /// *Method: NcChannel.[set()][NcChannel#method.set]* @@ -308,7 +308,7 @@ pub fn ncchannel_set(channel: &mut NcChannel, rgb: NcRgb) { *channel = (*channel & !NCALPHA_BG_RGB_MASK) | NCALPHA_BGDEFAULT_MASK | (rgb & 0x00ffffff); } -/// Sets the foreground [NcRgb] of an [NcChannelPair], and marks it as NOT using +/// Sets the foreground [`NcRgb`] of an [`NcChannelPair`], and marks it as NOT using /// the "default color", retaining the other bits unchanged. /// /// *Method: NcChannelPair.[set_fg_rgb()][NcChannelPair#method.set_fg_rgb]* @@ -319,7 +319,7 @@ pub fn ncchannels_set_fg_rgb(channels: &mut NcChannelPair, rgb: NcRgb) { *channels = (channel as u64) << 32 | *channels & 0xffffffff_u64; } -/// Sets the foreground [NcRgb] of an [NcChannelPair], and marks it as NOT using +/// Sets the foreground [`NcRgb`] of an [`NcChannelPair`], and marks it as NOT using /// the "default color", retaining the other bits unchanged. /// /// *Method: NcChannelPair.[set_bg_rgb()][NcChannelPair#method.set_bg_rgb]* @@ -332,7 +332,7 @@ pub fn ncchannels_set_bg_rgb(channels: &mut NcChannelPair, rgb: NcRgb) { // Default --------------------------------------------------------------------- -/// Is this [NcChannel] using the "default color" rather than RGB/palette-indexed? +/// Is this [`NcChannel`] using the "default color" rather than RGB/palette-indexed? /// /// *Method: NcChannel.[default_p()][NcChannel#method.default_p]* #[inline] @@ -340,7 +340,7 @@ pub const fn ncchannel_default_p(channel: NcChannel) -> bool { (channel & NCALPHA_BGDEFAULT_MASK) == 0 } -/// Marks an [NcChannel] as using its "default color", which also marks it opaque. +/// Marks an [`NcChannel`] as using its "default color", which also marks it opaque. /// /// *Method: NcChannel.[set_default()][NcChannel#method.set_default]* #[inline] @@ -349,7 +349,7 @@ pub fn ncchannel_set_default(channel: &mut NcChannel) -> NcChannel { *channel } -/// Marks an [NcChannel] as NOT using its "default color", +/// Marks an [`NcChannel`] as NOT using its "default color", /// retaining the other bits unchanged. /// /// *Method: NcChannel.[set_not_default()][NcChannel#method.set_not_default]* @@ -361,7 +361,7 @@ pub fn ncchannel_set_not_default(channel: &mut NcChannel) -> NcChannel { *channel } -/// Is the foreground of an [NcChannelPair] using the "default foreground color"? +/// Is the foreground of an [`NcChannelPair`] using the "default foreground color"? /// /// *Method: NcChannelPair.[fg_default_p()][NcChannelPair#method.fg_default_p]* #[inline] @@ -380,8 +380,8 @@ pub fn ncchannels_bg_default_p(channels: NcChannelPair) -> bool { ncchannel_default_p(ncchannels_bchannel(channels)) } -/// Marks the foreground of an [NcChannelPair] as using its "default color", -/// which also marks it opaque, and returns the new [NcChannelPair]. +/// Marks the foreground of an [`NcChannelPair`] as using its "default color", +/// which also marks it opaque, and returns the new [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_fg_default()][NcChannelPair#method.set_fg_default]* #[inline] @@ -392,8 +392,8 @@ pub fn ncchannels_set_fg_default(channels: &mut NcChannelPair) -> NcChannelPair *channels } -/// Marks the foreground of an [NcChannelPair] as NOT using its "default color", -/// retaining the other bits unchanged, and returns the new [NcChannelPair]. +/// Marks the foreground of an [`NcChannelPair`] as NOT using its "default color", +/// retaining the other bits unchanged, and returns the new [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_fg_not_default()][NcChannelPair#method.set_fg_not_default]* // @@ -406,8 +406,8 @@ pub fn ncchannels_set_fg_not_default(channels: &mut NcChannelPair) -> NcChannelP *channels } -/// Marks the background of an [NcChannelPair] as using its "default color", -/// which also marks it opaque, and returns the new [NcChannelPair]. +/// Marks the background of an [`NcChannelPair`] as using its "default color", +/// which also marks it opaque, and returns the new [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_bg_default()][NcChannelPair#method.set_bg_default]* #[inline] @@ -418,8 +418,8 @@ pub fn ncchannels_set_bg_default(channels: &mut NcChannelPair) -> NcChannelPair *channels } -/// Marks the background of an [NcChannelPair] as NOT using its "default color", -/// retaining the other bits unchanged, and returns the new [NcChannelPair]. +/// Marks the background of an [`NcChannelPair`] as NOT using its "default color", +/// retaining the other bits unchanged, and returns the new [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_bg_not_default()][NcChannelPair#method.set_bg_not_default]* // @@ -432,8 +432,8 @@ pub fn ncchannels_set_bg_not_default(channels: &mut NcChannelPair) -> NcChannelP *channels } -/// Marks both the foreground and background of an [NcChannelPair] as using their -/// "default color", which also marks them opaque, and returns the new [NcChannelPair]. +/// Marks both the foreground and background of an [`NcChannelPair`] as using their +/// "default color", which also marks them opaque, and returns the new [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_default()][NcChannelPair#method.set_default]* // @@ -443,8 +443,8 @@ pub fn ncchannels_set_default(channels: &mut NcChannelPair) -> NcChannelPair { ncchannels_set_bg_default(&mut ncchannels_set_fg_default(channels)) } -/// Marks both the foreground and background of an [NcChannelPair] as NOT using their -/// "default color", retaining the other bits unchanged, and returns the new [NcChannelPair]. +/// Marks both the foreground and background of an [`NcChannelPair`] as NOT using their +/// "default color", retaining the other bits unchanged, and returns the new [`NcChannelPair`]. /// /// *Method: NcChannelPair.[set_not_default()][NcChannelPair#method.set_not_default]* // @@ -456,7 +456,7 @@ pub fn ncchannels_set_not_default(channels: &mut NcChannelPair) -> NcChannelPair // Palette --------------------------------------------------------------------- -/// Is this [NcChannel] using palette-indexed color rather than RGB? +/// Is this [`NcChannel`] using palette-indexed color rather than RGB? /// /// *Method: NcChannel.[palindex_p()][NcChannel#method.palindex_p]* #[inline] @@ -464,8 +464,8 @@ pub fn ncchannel_palindex_p(channel: NcChannel) -> bool { !(ncchannel_default_p(channel) && (channel & NCALPHA_BG_PALETTE) == 0) } -/// Is the foreground of an [NcChannelPair] using an [indexed][NcPaletteIndex] -/// [NcPalette][crate::NcPalette] color? +/// Is the foreground of an [`NcChannelPair`] using an [indexed][`NcPaletteIndex`] +/// [`NcPalette`][crate::NcPalette] color? /// /// *Method: NcChannelPair.[fg_palindex_p()][NcChannelPair#method.fg_palindex_p]* #[inline] @@ -473,8 +473,8 @@ pub fn ncchannels_fg_palindex_p(channels: NcChannelPair) -> bool { ncchannel_palindex_p(ncchannels_fchannel(channels)) } -/// Is the background of an [NcChannelPair] using an [indexed][NcPaletteIndex] -/// [NcPalette][crate::NcPalette] color? +/// Is the background of an [`NcChannelPair`] using an [indexed][`NcPaletteIndex`] +/// [`NcPalette`][crate::NcPalette] color? /// /// *Method: NcChannelPair.[bg_palindex_p()][NcChannelPair#method.bg_palindex_p]* #[inline] @@ -482,8 +482,8 @@ pub fn ncchannels_bg_palindex_p(channels: NcChannelPair) -> bool { ncchannel_palindex_p(ncchannels_bchannel(channels)) } -/// Sets the foreground of an [NcChannelPair] as using an -/// [indexed][NcPaletteIndex] [NcPalette][crate::NcPalette] color. +/// Sets the foreground of an [`NcChannelPair`] as using an +/// [indexed][`NcPaletteIndex`] [`NcPalette`][crate::NcPalette] color. /// /// *Method: NcChannelPair.[set_fg_palindex()][NcChannelPair#method.set_fg_palindex]* #[inline] @@ -496,8 +496,8 @@ pub fn ncchannels_set_fg_palindex(channels: &mut NcChannelPair, index: NcPalette *channels |= (index as NcChannelPair) << 32; } -/// Sets the background of an [NcChannelPair] as using an -/// [indexed][NcPaletteIndex] [NcPalette][crate::NcPalette] color. +/// Sets the background of an [`NcChannelPair`] as using an +/// [indexed][`NcPaletteIndex`] [`NcPalette`][crate::NcPalette] color. /// /// *Method: NcChannelPair.[set_bg_palindex()][NcChannelPair#method.set_bg_palindex]* #[inline] diff --git a/rust/src/channel/test/reimplemented.rs b/rust/src/channel/test/reimplemented.rs index 9998f83ab..b2ae72b74 100644 --- a/rust/src/channel/test/reimplemented.rs +++ b/rust/src/channel/test/reimplemented.rs @@ -9,7 +9,7 @@ use crate::{ // NcChannel tests ------------------------------------------------------------- -/// retrieves the red NcColor component +/// retrieves the red NcComponent component #[test] #[serial] fn channel_r() { @@ -17,7 +17,7 @@ fn channel_r() { assert_eq!(crate::ncchannel_r(c), 0x11); } -/// retrieves the green NcColor component +/// retrieves the green NcComponent component #[test] #[serial] fn channel_g() { @@ -25,7 +25,7 @@ fn channel_g() { assert_eq!(crate::ncchannel_g(c), 0x22); } -/// retrieves the blue NcColor component +/// retrieves the blue NcComponent component #[test] #[serial] fn channel_b() { @@ -33,7 +33,7 @@ fn channel_b() { assert_eq!(crate::ncchannel_b(c), 0x33); } -/// writes out the three RGB NcColor components +/// writes out the three RGB NcComponent components #[test] #[serial] fn channel_rgb8() { @@ -47,7 +47,7 @@ fn channel_rgb8() { assert_eq!(b, 0x33); } -/// sets the three RGB NcColor components +/// sets the three RGB NcComponent components #[test] #[serial] fn channel_set_rgb8() { diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index df5bd55ea..600411e63 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -4,7 +4,7 @@ use core::ptr::{null, null_mut}; use crate::ffi::sigset_t; use crate::{ - cstring, error, error_ref_mut, rstring, NcAlign, NcBlitter, NcChannelPair, NcColor, NcDim, + cstring, error, error_ref_mut, rstring, NcAlign, NcBlitter, NcChannelPair, NcComponent, NcDim, NcDirect, NcDirectFlags, NcDirectV, NcEgc, NcError, NcInput, NcPaletteIndex, NcResult, NcRgb, NcScale, NcStyle, NcTime, NCRESULT_ERR, }; @@ -197,20 +197,30 @@ impl NcDirect { ] } - /// Sets the foreground [NcColor] components. + /// Sets the foreground [NcComponent] components. /// /// *C style function: [ncdirect_set_fg_rgb8()][crate::ncdirect_set_fg_rgb8].* - pub fn set_fg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) -> NcResult<()> { + pub fn set_fg_rgb8( + &mut self, + red: NcComponent, + green: NcComponent, + blue: NcComponent, + ) -> NcResult<()> { error![ crate::ncdirect_set_fg_rgb8(self, red, green, blue), &format!("NcDirect.set_fg_rgb8({}, {}, {})", red, green, blue) ] } - /// Sets the background [NcColor] components. + /// Sets the background [NcComponent] components. /// /// *C style function: [ncdirect_set_bg_rgb()][crate::ncdirect_set_bg_rgb].* - pub fn set_bg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) -> NcResult<()> { + pub fn set_bg_rgb8( + &mut self, + red: NcComponent, + green: NcComponent, + blue: NcComponent, + ) -> NcResult<()> { error![ crate::ncdirect_set_bg_rgb8(self, red, green, blue), &format!("NcDirect.set_bg_rgb8({}, {}, {})", red, green, blue) diff --git a/rust/src/direct/reimplemented.rs b/rust/src/direct/reimplemented.rs index a2a7ad007..561ebd588 100644 --- a/rust/src/direct/reimplemented.rs +++ b/rust/src/direct/reimplemented.rs @@ -2,7 +2,7 @@ use core::ptr::null; -use crate::{NcColor, NcDirect, NcInput, NcIntResult, NcRgb, NcSignalSet, NcTime}; +use crate::{NcComponent, NcDirect, NcInput, NcIntResult, NcRgb, NcSignalSet, NcTime}; /// 'input' may be NULL if the caller is uninterested in event details. /// Blocks until an event is processed or a signal is received. @@ -34,29 +34,29 @@ pub fn ncdirect_getc_nblock(nc: &mut NcDirect, input: &mut NcInput) -> char { } } -/// Sets the foreground [NcColor] components. +/// Sets the foreground [NcComponent] components. /// /// *Method: NcDirect.[set_fg_rgb8()][NcDirect#method.set_fg_rgb8].* #[inline] pub fn ncdirect_set_fg_rgb8( ncd: &mut NcDirect, - red: NcColor, - green: NcColor, - blue: NcColor, + red: NcComponent, + green: NcComponent, + blue: NcComponent, ) -> NcIntResult { let rgb = (red as NcRgb) << 16 | (green as NcRgb) << 8 | blue as NcRgb; unsafe { crate::ncdirect_set_fg_rgb(ncd, rgb) } } -/// Sets the background [NcColor] components. +/// Sets the background [NcComponent] components. /// /// *Method: NcDirect.[set_bg_rgb8()][NcDirect#method.set_bg_rgb8].* #[inline] pub fn ncdirect_set_bg_rgb8( ncd: &mut NcDirect, - red: NcColor, - green: NcColor, - blue: NcColor, + red: NcComponent, + green: NcComponent, + blue: NcComponent, ) -> NcIntResult { let rgb = (red as NcRgb) << 16 | (green as NcRgb) << 8 | blue as NcRgb; unsafe { crate::ncdirect_set_bg_rgb(ncd, rgb) } diff --git a/rust/src/fd/methods.rs b/rust/src/fd/methods.rs new file mode 100644 index 000000000..c89e674ba --- /dev/null +++ b/rust/src/fd/methods.rs @@ -0,0 +1,366 @@ +//! `NcVisual*` methods and associated functions. + +use core::ptr::null_mut; +use libc::c_void; + +use crate::{ + // cstring, error, error_ref_mut, rstring, NcBlitter, NcDim, NcError, NcIntResult, NcPixel, + // NcPlane, NcResult, NcRgba, NcScale, NcTime, NcVisual, NcVisualOptions, Notcurses, NCBLIT_PIXEL, + // NCRESULT_ERR, +}; + +/// # NcVisualOptions Constructors +impl NcSubprocOptions { + + /// + pub fn new( + curry: *mut c_void, + restart_period: u64, + // flags: u64, + ) -> Self { + Self { + curry:, + // restart this many seconds after an exit (watch) + restart_period, + // bitfield over NCOPTION_SUBPROC_* (none yet) + flags: 0, + } + } +} + +/// # NcSubproc Constructors & Destructors +impl NcSubproc { + /// Opens a visual at `file`, extracts the codec and parameters and + /// decodes the first image to memory. + /// + /// *C style function: [ncvisual_from_file()][crate::ncvisual_from_file].* + pub fn new<'a>(file: &str) -> NcResult<&'a mut NcVisual> { + error_ref_mut![ + unsafe { crate::ncvisual_from_file(cstring![file]) }, + &format!("NcVisual::from_file()") + ] + } + + /// Promotes an NcPlane to an NcVisual. + /// + /// The plane may contain only spaces, half blocks, and full blocks. + /// This will be checked, and any other glyph will result in an error. + /// + /// This function exists so that planes can be subjected to NcVisual transformations. + /// If possible, it's better to create the ncvisual from memory using + /// [from_rgba][NcVisual#method.from_rgba]. + /// + /// *C style function: [ncvisual_from_plane()][crate::ncvisual_from_plane].* + pub fn from_plane<'a>( + plane: &NcPlane, + blitter: NcBlitter, + beg_y: NcDim, + beg_x: NcDim, + len_y: NcDim, + len_x: NcDim, + ) -> NcResult<&'a mut NcVisual> { + error_ref_mut![ + unsafe { + crate::ncvisual_from_plane( + plane, + blitter, + beg_y as i32, + beg_x as i32, + len_y as i32, + len_x as i32, + ) + }, + &format!("NcVisual::from_file()") + ] + } + + /// Prepares an NcVisual, and its underlying NcPlane, based off RGBA content + /// in memory at `rgba`. + /// + /// `rgba` is laid out as `rows` lines, each of which is `rowstride` bytes in length. + /// Each line has `cols` 32-bit 8bpc RGBA pixels followed by possible padding + /// (there will be rowstride - cols * 4 bytes of padding). + /// + /// The total size of `rgba` is thus (rows * rowstride) bytes, of which + /// (rows * cols * 4) bytes are actual non-padding data. + /// + /// *C style function: [ncvisual_from_rgba()][crate::ncvisual_from_rgba].* + pub fn from_rgba<'a>( + rgba: &[u8], + rows: NcDim, + rowstride: NcDim, + cols: NcDim, + ) -> NcResult<&'a mut NcVisual> { + error_ref_mut![ + unsafe { + crate::ncvisual_from_rgba( + rgba.as_ptr() as *const c_void, + rows as i32, + rowstride as i32, + cols as i32, + ) + }, + &format!("NcVisual::from_rgba()") + ] + } + + /// Destroys this NcVisual. + /// + /// Rendered elements will not be disrupted, but the visual can be neither + /// decoded nor rendered any further. + /// + /// *C style function: [ncvisual_destroy()][crate::ncvisual_destroy].* + pub fn destroy(&mut self) { + unsafe { crate::ncvisual_destroy(self) } + } +} + +/// # NcVisual Methods +impl NcVisual { + /// Gets the specified pixel from this NcVisual. + /// + /// *C style function: [ncvisual_at_yx()][crate::ncvisual_at_yx].* + pub fn at_yx(&self, y: NcDim, x: NcDim) -> NcResult { + let mut pixel = 0; + let res = unsafe { crate::ncvisual_at_yx(self, y as i32, x as i32, &mut pixel) }; + error![res, "NcVisual.at_yx()", pixel] + } + + /// Extracts the next frame from the NcVisual. + /// + /// Returns 0 for normal frames, and 1 to indicate EOF. + /// + /// *C style function: [ncvisual_decode()][crate::ncvisual_decode].* + pub fn decode(&mut self) -> NcResult { + let res = unsafe { crate::ncvisual_decode(self) }; + if res == NCRESULT_ERR { + return Err(NcError::with_msg(res, "NcVisual.decode()")); + } else { + Ok(res) + } + } + + /// Extracts the next frame from the NcVisual, ala [decode][NcVisual#method.decode], + /// but if we have reached the end, rewinds to the first frame. + /// + /// *A subsequent [NcVisual.render]() will render the first frame, + /// as if the ncvisual had been closed and reopened.* + /// + /// Returns 0 for normal frames and 1 to indicate EOF. + /// + /// *C style function: [ncvisual_decode_loop()][crate::ncvisual_decode_loop].* + pub fn decode_loop(&mut self) -> NcResult { + let res = unsafe { crate::ncvisual_decode_loop(self) }; + if res == NCRESULT_ERR { + return Err(NcError::with_msg(res, "NcVisual.decode_loop()")); + } else { + Ok(res) + } + } + + /// Inflates each pixel in the image to 'scale'x'scale' pixels. + /// + /// The original color is retained. + pub fn inflate(&mut self, scale: u32) -> NcResult { + let res = unsafe { crate::ncvisual_inflate(self, scale as i32) }; + error![res, &format!["NcVisual.inflate({})", scale], res] + } + + /// Gets the size and ratio of NcVisual pixels to output cells along the + /// `y→to_y` and `x→to_x` axes. + /// + /// Returns a tuple with (y, x, to_y, to_x) + /// + /// An NcVisual of `y` by `x` pixels will require + /// (`y` * `to_y`) by (`x` * `to_x`) cells for full output. + /// + /// Errors on invalid blitter in `options`. Scaling is taken into consideration. + /// + /// *C style function: [ncvisual_blitter_geom()][crate::ncvisual_blitter_geom].* + pub fn geom( + &self, + nc: &Notcurses, + options: &NcVisualOptions, + ) -> NcResult<(NcDim, NcDim, NcDim, NcDim)> { + let mut y = 0; + let mut x = 0; + let mut to_y = 0; + let mut to_x = 0; + + let res = unsafe { + crate::ncvisual_blitter_geom( + nc, + self, + options, + &mut y, + &mut x, + &mut to_y, + &mut to_x, + null_mut(), + ) + }; + error![ + res, + "NcVisual.geom()", + (y as NcDim, x as NcDim, to_y as NcDim, to_x as NcDim) + ]; + } + + /// Gets the default media (not plot) blitter for this environment when using + /// the specified scaling method. + /// + /// Currently, this means: + /// - if lacking UTF-8, NCBLIT_1x1. + /// - otherwise, if not NCSCALE_STRETCH, NCBLIT_2x1. + /// - otherwise, if sextants are not known to be good, NCBLIT_2x2. + /// - otherwise NCBLIT_3x2 NCBLIT_2x2 and NCBLIT_3x2 both distort the original + /// aspect ratio, thus NCBLIT_2x1 is used outside of NCSCALE_STRETCH. + /// + /// *C style function: [ncvisual_media_defblitter()][crate::ncvisual_media_defblitter].* + pub fn media_defblitter(nc: &Notcurses, scale: NcScale) -> NcBlitter { + unsafe { crate::ncvisual_media_defblitter(nc, scale) } + } + + /// Polyfills at the specified location using `rgba`. + /// + /// *C style function: [ncvisual_polyfill_yx()][crate::ncvisual_polyfill_yx].* + pub fn polyfill_yx(&mut self, y: NcDim, x: NcDim, rgba: NcRgba) -> NcResult<()> { + error![ + unsafe { crate::ncvisual_polyfill_yx(self, y as i32, x as i32, rgba) }, + &format!["NcVisual.polyfill_yx({}, {}, {})", y, x, rgba] + ] + } + + /// Renders the decoded frame to the specified [NcPlane]. + /// + /// See [`NcVisualOptions`]. + /// + /// *C style function: [ncvisual_render()][crate::ncvisual_render].* + pub fn render( + &mut self, + nc: &mut Notcurses, + options: &NcVisualOptions, + ) -> NcResult<&mut NcPlane> { + error_ref_mut![ + unsafe { crate::ncvisual_render(nc, self, options) }, + "NcVisual.render()" + ] + } + + /// Resizes the visual to `rows` X `columns` pixels. + /// + /// This is a lossy transformation, unless the size is unchanged. + /// + /// *C style function: [ncvisual_resize()][crate::ncvisual_resize].* + pub fn resize(&mut self, rows: NcDim, cols: NcDim) -> NcResult<()> { + error![ + unsafe { crate::ncvisual_resize(self, rows as i32, cols as i32) }, + &format!["NcVisual.resize({}, {})", rows, cols] + ] + } + + /// Rotates the visual `rads` radians. + /// + /// Only M_PI/2 and -M_PI/2 are supported at the moment, + /// but this will change. (FIXME) + /// + /// *C style function: [ncvisual_rotate()][crate::ncvisual_rotate].* + pub fn rotate(&mut self, rads: f64) -> NcResult<()> { + error![ + unsafe { crate::ncvisual_rotate(self, rads) }, + &format!["NcVisual.rotate({})", rads] + ] + } + + /// Sets the specified pixel. + /// + /// *C style function: [ncvisual_set_yx()][crate::ncvisual_set_yx].* + pub fn set_yx(&mut self, y: NcDim, x: NcDim, pixel: NcPixel) -> NcResult<()> { + error![ + unsafe { crate::ncvisual_set_yx(self, y as i32, x as i32, pixel) }, + &format!["NcVisual.set_yx({}, {}, {})", y, x, pixel] + ] + } + + /// Displays frames. + /// + /// *Provide as an argument to ncvisual_stream().* + /// + /// If you'd like subtitles to be decoded, provide an ncplane as the curry. + /// If the curry is NULL, subtitles will not be displayed. + /// + /// *C style function: [ncvisual_simple_streamer()][crate::ncvisual_simple_streamer].* + pub fn simple_streamer( + &mut self, + options: &mut NcVisualOptions, + time: &NcTime, + curry: Option<&mut NcPlane>, + ) -> NcResult<()> { + if let Some(plane) = curry { + error![ + unsafe { + crate::ncvisual_simple_streamer( + self, + options, + time, + plane as *mut _ as *mut libc::c_void, + ) + }, + &format![ + "NcVisual.simple_streamer({:?}, {:?}, ncplane)", + options, time + ] + ] + } else { + error![ + unsafe { crate::ncvisual_simple_streamer(self, options, time, null_mut()) }, + &format!["NcVisual.simple_streamer({:?}, {:?}, null)", options, time] + ] + } + } + + // // TODO + // + // /// Streams the entirety of the media, according to its own timing. + // /// + // /// Blocking, obviously. + // /// + // /// If `streamer` is provided it will be called for each frame, and its return + // /// value handled as outlined for streamcb. + // /// If streamer() returns non-zero, the stream is aborted, and that value is + // /// returned. By convention, return a positive number to indicate intentional + // /// abort from within streamer(). + // /// + // /// `timescale` allows the frame duration time to be scaled. + // /// For a visual naturally running at 30FPS, a 'timescale' of 0.1 will result + // /// in 300 FPS, and a `timescale` of 10 will result in 3 FPS. + // /// It is an error to supply `timescale` less than or equal to 0. + // /// + // /// *C style function: [ncvisual_streamer()][crate::ncvisual_streamer].* + // // + // // TODO: add streamcb + // // INFO: QUESTION: is curry also optional like in simple_streamer? + // // + // pub fn simple_streamer( + // &mut self, + // nc: &mut Notcurses, + // timescale: f32, + // //streamer: Option + // options: &NcVisualOptions, + // curry: Option<&mut NcPlane>, + // ) -> NcResult<()> { + // } + + /// If a subtitle ought be displayed at this time, returns a heap-allocated + /// copy of the UTF8 text. + /// + /// *C style function: [ncvisual_subtitle()][crate::ncvisual_subtitle].* + pub fn subtitle(&self) -> NcResult<&str> { + let res = unsafe { crate::ncvisual_subtitle(self) }; + if res != null_mut() { + return Ok(rstring![res]); + } else { + Err(NcError::with_msg(NCRESULT_ERR, "NcVisual.subtitle()")) + } + } +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 089ea0d29..d2c445f24 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -41,7 +41,7 @@ //! //! For the types that don't allocate, most are based on primitives like `i32`, //! `u32`, `u64`… without a name in the C library. In Rust they are type aliased -//! (e.g.: [`NcChannel`], [`NcChannelPair`], [`NcRgb`], [`NcColor`]…), to +//! (e.g.: [`NcChannel`], [`NcChannelPair`], [`NcRgb`], [`NcComponent`]…), to //! leverage type checking, and they implement methods through [traits](#traits) //! (e.g. [`NcChannelMethods`] must be in scope to use the `NcChannel` methods. //! diff --git a/rust/src/palette/methods.rs b/rust/src/palette/methods.rs index 16ce6350c..7d2e678ab 100644 --- a/rust/src/palette/methods.rs +++ b/rust/src/palette/methods.rs @@ -1,16 +1,16 @@ //! `NcPalette` methods and associated functions. -use crate::{error, Nc, NcChannel, NcColor, NcPalette, NcPaletteIndex, NcResult, NcRgb}; +use crate::{error, Nc, NcChannel, NcComponent, NcPalette, NcPaletteIndex, NcResult, NcRgb}; impl NcPalette { - /// New NcPalette. + /// New `NcPalette`. /// /// *C style function: [ncpalette_new()][crate::ncpalette_new].* pub fn new<'a>(nc: &mut Nc) -> &'a mut Self { unsafe { &mut *crate::ncpalette_new(nc) } } - /// Frees this NcPalette. + /// Frees this `NcPalette`. /// /// *C style function: [ncpalette_free()][crate::ncpalette_free].* pub fn free(&mut self) { @@ -26,16 +26,16 @@ impl NcPalette { error![unsafe { crate::ncpalette_use(nc, self) }] } - /// Returns the [NcColor] RGB components from the [NcChannel] in this NcPalette. + /// Returns the [`NcComponent`]s from the [`NcChannel`] in this `NcPalette`. /// /// *C style function: [ncpalette_get_rgb()][crate::ncpalette_get_rgb8].* - pub fn get_rgb8(&self, index: NcPaletteIndex) -> (NcColor, NcColor, NcColor) { + pub fn get_rgb8(&self, index: NcPaletteIndex) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); crate::ncchannel_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 + /// Extracts the [`NcComponent`]s from an [`NcChannel`] entry inside /// this NcPalette, and returns the NcChannel. /// /// *C style function: [ncpalette_get_rgb()][crate::ncpalette_get_rgb8].* @@ -44,7 +44,7 @@ impl NcPalette { crate::ncchannel_rgb8(self.chans[index as usize], &mut r, &mut g, &mut b) } - /// Sets the [NcRgb] value of the [NcChannel][crate::NcChannel] entry + /// Sets the [`NcRgb`] value of the [`NcChannel`][crate::NcChannel] entry /// inside this NcPalette. /// /// *C style function: [ncpalette_set()][crate::ncpalette_set].* diff --git a/rust/src/palette/reimplemented.rs b/rust/src/palette/reimplemented.rs index 48b58d374..e2bdfb135 100644 --- a/rust/src/palette/reimplemented.rs +++ b/rust/src/palette/reimplemented.rs @@ -1,9 +1,9 @@ //! `ncpalette_*` reimplemented functions. -use crate::{NcChannel, NcColor, NcPalette, NcPaletteIndex, NcRgb}; +use crate::{NcChannel, NcComponent, NcPalette, NcPaletteIndex, NcRgb}; -/// Extracts the [NcColor] RGB components from an [NcChannel] entry inside -/// an [NcPalette], and returns the NcChannel. +/// Extracts the RGB [`NcComponent`]s 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].* @@ -11,14 +11,14 @@ use crate::{NcChannel, NcColor, NcPalette, NcPaletteIndex, NcRgb}; pub fn ncpalette_get_rgb8( palette: &NcPalette, index: NcPaletteIndex, - red: &mut NcColor, - green: &mut NcColor, - blue: &mut NcColor, + red: &mut NcComponent, + green: &mut NcComponent, + blue: &mut NcComponent, ) -> NcChannel { crate::ncchannel_rgb8(palette.chans[index as usize], red, green, blue) } -/// Sets the [NcRgb] value of the [NcChannel] entry inside an [NcPalette]. +/// Sets the [`NcRgb`] value of the [`NcChannel`] entry inside an [`NcPalette`]. /// /// *Method: NcPalette.[set()][NcPalette#method.set].* #[inline] @@ -26,16 +26,17 @@ pub fn ncpalette_set(palette: &mut NcPalette, index: NcPaletteIndex, rgb: NcRgb) crate::ncchannel_set(&mut palette.chans[index as usize], rgb); } -/// Sets the [NcColor] components of the [NcChannel] entry inside an [NcPalette]. +/// Sets the RGB [`NcComponent`]s of the [`NcChannel`] entry inside an +/// [`NcPalette`]. /// /// *Method: NcPalette.[set_rgb()][NcPalette#method.set_rgb].* #[inline] pub fn ncpalette_set_rgb8( palette: &mut NcPalette, index: NcPaletteIndex, - red: NcColor, - green: NcColor, - blue: NcColor, + red: NcComponent, + green: NcComponent, + blue: NcComponent, ) { crate::ncchannel_set_rgb8(&mut palette.chans[index as usize], red, green, blue) } diff --git a/rust/src/pixel.rs b/rust/src/pixel.rs index fbc89104a..430090b6b 100644 --- a/rust/src/pixel.rs +++ b/rust/src/pixel.rs @@ -2,7 +2,7 @@ //! ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render //! them down to terminal graphics in ncvisual_render()). // -// - NOTE: The pixel color & alpha components are u8 instead of u32. +// - NOTE: The pixel color & alpha [`NcComponent`]s are u8 instead of u32. // Because of type enforcing, some runtime checks are now unnecessary. // // - NOTE: None of the functions can't fail anymore and don't have to return an error. @@ -24,7 +24,7 @@ //W+ ncpixel_set_r //W+ ncpixel_set_rgb8 -use crate::NcColor; +use crate::NcComponent; // NcPixel (RGBA) /// An ABGR pixel. @@ -54,64 +54,69 @@ use crate::NcColor; /// pub type NcPixel = u32; -/// Constructs a libav-compatible ABGR pixel from [NcColor] RGB components. +/// Constructs a libav-compatible ABGR pixel from RGB [`NcComponent`]s. #[inline] #[allow(clippy::unnecessary_cast)] -pub const fn ncpixel(red: NcColor, green: NcColor, blue: NcColor) -> NcPixel { +pub const fn ncpixel(red: NcComponent, green: NcComponent, blue: NcComponent) -> NcPixel { 0xff000000 as NcPixel | red as NcPixel | (blue as NcPixel) << 8 | (green as NcPixel) << 16 } -/// Extracts the 8-bit alpha component from an ABGR pixel. +/// Extracts the 8-bit alpha [`NcComponent`] from an ABGR pixel. #[inline] -pub const fn ncpixel_a(pixel: NcPixel) -> NcColor { - ((pixel.to_le() & 0xff000000) >> 24) as NcColor +pub const fn ncpixel_a(pixel: NcPixel) -> NcComponent { + ((pixel.to_le() & 0xff000000) >> 24) as NcComponent } -/// Extracts the 8 bit blue component from an ABGR pixel. +/// Extracts the 8 bit blue [`NcComponent`] from an ABGR pixel. #[inline] -pub const fn ncpixel_b(pixel: NcPixel) -> NcColor { - ((pixel.to_le() & 0x00ff0000) >> 16) as NcColor +pub const fn ncpixel_b(pixel: NcPixel) -> NcComponent { + ((pixel.to_le() & 0x00ff0000) >> 16) as NcComponent } -/// Extracts the 8 bit green component from an ABGR pixel. +/// Extracts the 8 bit green [`NcComponent`] from an ABGR pixel. #[inline] -pub const fn ncpixel_g(pixel: NcPixel) -> NcColor { - ((pixel.to_le() & 0x0000ff00) >> 8) as NcColor +pub const fn ncpixel_g(pixel: NcPixel) -> NcComponent { + ((pixel.to_le() & 0x0000ff00) >> 8) as NcComponent } -/// Extracts the 8 bit red component from an ABGR pixel. +/// Extracts the 8 bit red [`NcComponent`] from an ABGR pixel. #[inline] -pub const fn ncpixel_r(pixel: NcPixel) -> NcColor { - (pixel.to_le() & 0x000000ff) as NcColor +pub const fn ncpixel_r(pixel: NcPixel) -> NcComponent { + (pixel.to_le() & 0x000000ff) as NcComponent } -/// Sets the 8-bit alpha component of an ABGR pixel. +/// Sets the 8-bit alpha [`NcComponent`] of an ABGR pixel. #[inline] -pub fn ncpixel_set_a(pixel: &mut NcPixel, alpha: NcColor) { +pub fn ncpixel_set_a(pixel: &mut NcPixel, alpha: NcComponent) { *pixel = (((*pixel).to_le() & 0x00ffffff) | ((alpha as NcPixel) << 24)).to_le(); } -/// Sets the 8-bit blue component of an ABGR pixel. +/// Sets the 8-bit blue [`NcComponent`] of an ABGR pixel. #[inline] -pub fn ncpixel_set_b(pixel: &mut NcPixel, blue: NcColor) { +pub fn ncpixel_set_b(pixel: &mut NcPixel, blue: NcComponent) { *pixel = (((*pixel).to_le() & 0xffff00ff) | ((blue as NcPixel) << 8)).to_le(); } -/// Sets the 8-bit green component of an ABGR pixel. +/// Sets the 8-bit green [`NcComponent`] of an ABGR pixel. #[inline] -pub fn ncpixel_set_g(pixel: &mut NcPixel, green: NcColor) { +pub fn ncpixel_set_g(pixel: &mut NcPixel, green: NcComponent) { *pixel = (((*pixel).to_le() & 0xff00ffff) | ((green as NcPixel) << 16)).to_le(); } -/// Sets the 8-bit red component of an ABGR pixel. +/// Sets the 8-bit red [`NcComponent`] of an ABGR pixel. #[inline] -pub fn ncpixel_set_r(pixel: &mut NcPixel, red: NcColor) { +pub fn ncpixel_set_r(pixel: &mut NcPixel, red: NcComponent) { *pixel = (((*pixel).to_le() & 0xffffff00) | red as NcPixel).to_le(); } -/// Sets the [NcColor] RGB components of an ABGR pixel. +/// Sets the RGB [`NcComponent`]s of an ABGR pixel. #[inline] -pub fn ncpixel_set_rgb8(pixel: &mut NcPixel, red: NcColor, green: NcColor, blue: NcColor) { +pub fn ncpixel_set_rgb8( + pixel: &mut NcPixel, + red: NcComponent, + green: NcComponent, + blue: NcComponent, +) { ncpixel_set_r(pixel, red); ncpixel_set_g(pixel, green); ncpixel_set_b(pixel, blue); @@ -122,66 +127,66 @@ pub fn ncpixel_set_rgb8(pixel: &mut NcPixel, red: NcColor, green: NcColor, blue: // NOTE: waiting for: https://github.com/rust-lang/rust/issues/56546 // to move doc comments to the trait and appear unhidden at the implementation. pub trait NcPixelMethods { - fn new(r: NcColor, g: NcColor, b: NcColor) -> Self; - fn a(self) -> NcColor; - fn b(self) -> NcColor; - fn g(self) -> NcColor; - fn r(self) -> NcColor; - fn set_a(&mut self, green: NcColor); - fn set_b(&mut self, blue: NcColor); - fn set_g(&mut self, green: NcColor); - fn set_r(&mut self, red: NcColor); - fn set_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor); + fn new(r: NcComponent, g: NcComponent, b: NcComponent) -> Self; + fn a(self) -> NcComponent; + fn b(self) -> NcComponent; + fn g(self) -> NcComponent; + fn r(self) -> NcComponent; + fn set_a(&mut self, green: NcComponent); + fn set_b(&mut self, blue: NcComponent); + fn set_g(&mut self, green: NcComponent); + fn set_r(&mut self, red: NcComponent); + fn set_rgb8(&mut self, red: NcComponent, green: NcComponent, blue: NcComponent); } impl NcPixelMethods for NcPixel { - /// Constructs a libav-compatible ABGR pixel from [NcColor] RGB components. - fn new(red: NcColor, green: NcColor, blue: NcColor) -> Self { + /// Constructs a libav-compatible ABGR pixel from RGB [`NcComponent`]s. + fn new(red: NcComponent, green: NcComponent, blue: NcComponent) -> Self { ncpixel(red, green, blue) } - /// Extracts the 8-bit alpha component from an ABGR pixel. - fn a(self) -> NcColor { + /// Extracts the 8-bit alpha [`NcComponent`] from an ABGR pixel. + fn a(self) -> NcComponent { ncpixel_a(self) } - /// Extracts the 8 bit blue component from an ABGR pixel. - fn b(self) -> NcColor { + /// Extracts the 8 bit blue [`NcComponent`] from an ABGR pixel. + fn b(self) -> NcComponent { ncpixel_b(self) } - /// Extracts the 8 bit green component from an ABGR pixel. - fn g(self) -> NcColor { + /// Extracts the 8 bit green [`NcComponent`] from an ABGR pixel. + fn g(self) -> NcComponent { ncpixel_g(self) } - /// Extracts the 8 bit red component from an ABGR pixel. - fn r(self) -> NcColor { + /// Extracts the 8 bit red [`NcComponent`] from an ABGR pixel. + fn r(self) -> NcComponent { ncpixel_r(self) } - /// Sets the 8-bit alpha component of an ABGR pixel. - fn set_a(&mut self, alpha: NcColor) { + /// Sets the 8-bit alpha [`NcComponent`] of an ABGR pixel. + fn set_a(&mut self, alpha: NcComponent) { ncpixel_set_a(self, alpha) } - /// Sets the 8-bit green component of an ABGR pixel. - fn set_g(&mut self, green: NcColor) { + /// Sets the 8-bit green [`NcComponent`] of an ABGR pixel. + fn set_g(&mut self, green: NcComponent) { ncpixel_set_b(self, green) } - /// Sets the 8-bit blue component of an ABGR pixel. - fn set_b(&mut self, blue: NcColor) { + /// Sets the 8-bit blue [`NcComponent`] of an ABGR pixel. + fn set_b(&mut self, blue: NcComponent) { ncpixel_set_b(self, blue) } - /// Sets the 8-bit red component of an ABGR pixel. - fn set_r(&mut self, red: NcColor) { + /// Sets the 8-bit red [`NcComponent`] of an ABGR pixel. + fn set_r(&mut self, red: NcComponent) { ncpixel_set_r(self, red) } - /// Sets the [NcColor] RGB components of an ABGR pixel. - fn set_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) { + /// Sets the RGB [`NcComponent`]s of an ABGR pixel. + fn set_rgb8(&mut self, red: NcComponent, green: NcComponent, blue: NcComponent) { ncpixel_set_rgb8(self, red, green, blue); } } diff --git a/rust/src/plane/methods.rs b/rust/src/plane/methods.rs index 848280ee9..401c85716 100644 --- a/rust/src/plane/methods.rs +++ b/rust/src/plane/methods.rs @@ -6,7 +6,7 @@ use core::{ use crate::{ cstring, error, error_ref, error_ref_mut, rstring, Nc, NcAlign, NcAlphaBits, NcBlitter, - NcBoxMask, NcCell, NcChannel, NcChannelPair, NcColor, NcDim, NcEgc, NcError, NcFadeCb, + NcBoxMask, NcCell, NcChannel, NcChannelPair, NcComponent, NcDim, NcEgc, NcError, NcFadeCb, NcOffset, NcPaletteIndex, NcPixelGeometry, NcPlane, NcPlaneOptions, NcResizeCb, NcResult, NcRgb, NcStyle, NcTime, NCRESULT_ERR, }; @@ -159,7 +159,7 @@ impl NcPlane { // ----------------------------------------------------------------------------- /// ## NcPlane methods: `NcAlphaBits` impl NcPlane { - /// Gets the foreground [NcAlphaBits] from this NcPlane, shifted to LSBs. + /// Gets the foreground [`NcAlphaBits`] from this NcPlane, shifted to LSBs. /// /// *C style function: [ncplane_fg_alpha()][crate::ncplane_fg_alpha].* #[inline] @@ -167,7 +167,7 @@ impl NcPlane { crate::ncchannels_fg_alpha(crate::ncplane_channels(self)) } - /// Gets the background [NcAlphaBits] for this NcPlane, shifted to LSBs. + /// Gets the background [`NcAlphaBits`] for this NcPlane, shifted to LSBs. /// /// *C style function: [ncplane_bg_alpha()][crate::ncplane_bg_alpha].* #[inline] @@ -175,7 +175,7 @@ impl NcPlane { crate::ncchannels_bg_alpha(crate::ncplane_channels(self)) } - /// Sets the foreground [NcAlphaBits] from this NcPlane. + /// Sets the foreground [`NcAlphaBits`] from this NcPlane. /// /// *C style function: [ncplane_set_fg_alpha()][crate::ncplane_set_fg_alpha].* pub fn set_fg_alpha(&mut self, alpha: NcAlphaBits) -> NcResult<()> { @@ -185,7 +185,7 @@ impl NcPlane { ] } - /// Sets the background [NcAlphaBits] for this NcPlane. + /// Sets the background [`NcAlphaBits`] for this NcPlane. /// /// *C style function: [ncplane_set_bg_alpha()][crate::ncplane_set_bg_alpha].* pub fn set_bg_alpha(&mut self, alpha: NcAlphaBits) -> NcResult<()> { @@ -199,14 +199,14 @@ impl NcPlane { // ----------------------------------------------------------------------------- /// ## NcPlane methods: `NcChannel` impl NcPlane { - /// Gets the current [NcChannelPair] from this NcPlane. + /// Gets the current [`NcChannelPair`] from this NcPlane. /// /// *C style function: [ncplane_channels()][crate::ncplane_channels].* pub fn channels(&self) -> NcChannelPair { crate::ncplane_channels(self) } - /// Gets the foreground [NcChannel] from an [NcPlane]. + /// Gets the foreground [`NcChannel`] from an [NcPlane]. /// /// *C style function: [ncplane_fchannel()][crate::ncplane_fchannel].* #[inline] @@ -214,7 +214,7 @@ impl NcPlane { crate::ncchannels_fchannel(crate::ncplane_channels(self)) } - /// Gets the background [NcChannel] from an [NcPlane]. + /// Gets the background [`NcChannel`] from an [NcPlane]. /// /// *C style function: [ncplane_bchannel()][crate::ncplane_bchannel].* #[inline] @@ -222,30 +222,30 @@ impl NcPlane { crate::ncchannels_bchannel(crate::ncplane_channels(self)) } - /// Sets the current [NcChannelPair] for this NcPlane. + /// Sets the current [`NcChannelPair`] for this NcPlane. /// /// *C style function: [ncplane_set_channels()][crate::ncplane_set_channels].* pub fn set_channels(&mut self, channels: NcChannelPair) { crate::ncplane_set_channels(self, channels); } - /// Sets the current foreground [NcChannel] for this NcPlane. - /// Returns the updated [NcChannelPair]. + /// Sets the current foreground [`NcChannel`] for this NcPlane. + /// Returns the updated [`NcChannelPair`]. /// /// *C style function: [ncplane_set_fchannel()][crate::ncplane_set_fchannel].* pub fn set_fchannel(&mut self, channel: NcChannel) -> NcChannelPair { crate::ncplane_set_fchannel(self, channel) } - /// Sets the current background [NcChannel] for this NcPlane. - /// Returns the updated [NcChannelPair]. + /// Sets the current background [`NcChannel`] for this NcPlane. + /// Returns the updated [`NcChannelPair`]. /// /// *C style function: [ncplane_set_bchannel()][crate::ncplane_set_bchannel].* pub fn set_bchannel(&mut self, channel: NcChannel) -> NcChannelPair { crate::ncplane_set_bchannel(self, channel) } - /// Sets the given [NcChannelPair]s throughout the specified region, + /// Sets the given [`NcChannelPair`]s throughout the specified region, /// keeping content and attributes unchanged. /// /// Returns the number of cells set. @@ -274,29 +274,29 @@ impl NcPlane { } // ----------------------------------------------------------------------------- -/// ## NcPlane methods: `NcColor`, `NcRgb` & default color +/// ## NcPlane methods: `NcComponent`, `NcRgb` & default color impl NcPlane { - /// Gets the foreground [NcColor] RGB components from this NcPlane. + /// Gets the foreground RGB [`NcComponent`]s from this `NcPlane`. /// /// *C style function: [ncplane_fg_rgb8()][crate::ncplane_fg_rgb8].* #[inline] - pub fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor) { + pub fn fg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); let _ = crate::ncchannels_fg_rgb8(crate::ncplane_channels(self), &mut r, &mut g, &mut b); (r, g, b) } - /// Gets the background [NcColor] RGB components from this NcPlane. + /// Gets the background RGB [`NcComponent`]s from this `NcPlane`. /// /// *C style function: [ncplane_bg_rgb8()][crate::ncplane_bg_rgb8].* #[inline] - pub fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor) { + pub fn bg_rgb8(&self) -> (NcComponent, NcComponent, NcComponent) { let (mut r, mut g, mut b) = (0, 0, 0); let _ = crate::ncchannels_bg_rgb8(crate::ncplane_channels(self), &mut r, &mut g, &mut b); (r, g, b) } - /// Sets the foreground [NcColor] RGB components for this NcPlane. + /// Sets the foreground RGB [`NcComponent`]s for this `NcPlane`. /// /// If the terminal does not support directly-specified 3x8b cells /// (24-bit "TrueColor", indicated by the "RGB" terminfo capability), @@ -306,14 +306,14 @@ impl NcPlane { /// time using "color pairs"; notcurses will manage color pairs transparently. /// /// *C style function: [ncplane_set_fg_rgb8()][crate::ncplane_set_fg_rgb8].* - pub fn set_fg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) { + pub fn set_fg_rgb8(&mut self, red: NcComponent, green: NcComponent, blue: NcComponent) { unsafe { // Can't fail because of type enforcing. let _ = crate::ncplane_set_fg_rgb8(self, red as i32, green as i32, blue as i32); } } - /// Sets the background [NcColor] RGB components for this NcPlane. + /// Sets the background RGB [`NcComponent`]s for this NcPlane. /// /// If the terminal does not support directly-specified 3x8b cells /// (24-bit "TrueColor", indicated by the "RGB" terminfo capability), @@ -323,14 +323,14 @@ impl NcPlane { /// time using "color pairs"; notcurses will manage color pairs transparently. /// /// *C style function: [ncplane_set_bg_rgb8()][crate::ncplane_set_bg_rgb8].* - pub fn set_bg_rgb8(&mut self, red: NcColor, green: NcColor, blue: NcColor) { + pub fn set_bg_rgb8(&mut self, red: NcComponent, green: NcComponent, blue: NcComponent) { unsafe { // Can't fail because of type enforcing. let _ = crate::ncplane_set_bg_rgb8(self, red as i32, green as i32, blue as i32); } } - /// Gets the foreground [NcRgb] from this NcPlane, shifted to LSBs. + /// Gets the foreground [`NcRgb`] from this `NcPlane`, shifted to LSBs. /// /// *C style function: [ncplane_fg_rgb()][crate::ncplane_fg_rgb].* #[inline] @@ -338,7 +338,7 @@ impl NcPlane { crate::ncchannels_fg_rgb(crate::ncplane_channels(self)) } - /// Gets the background [NcRgb] from this NcPlane, shifted to LSBs. + /// Gets the background [`NcRgb`] from this `NcPlane`, shifted to LSBs. /// /// *C style function: [ncplane_bg_rgb()][crate::ncplane_bg_rgb].* #[inline] @@ -346,7 +346,7 @@ impl NcPlane { crate::ncchannels_bg_rgb(crate::ncplane_channels(self)) } - /// Sets the foreground [NcRgb] for this NcPlane. + /// Sets the foreground [`NcRgb`] for this `NcPlane`. /// /// *C style function: [ncplane_set_fg_rgb()][crate::ncplane_set_fg_rgb].* #[inline] @@ -356,7 +356,7 @@ impl NcPlane { } } - /// Sets the background [NcRgb] for this NcPlane. + /// Sets the background [`NcRgb`] for this `NcPlane`. /// /// *C style function: [ncplane_set_bg_rgb()][crate::ncplane_set_bg_rgb].* #[inline] @@ -404,7 +404,7 @@ impl NcPlane { /// Marks the foreground as NOT using the default color. /// - /// Returns the new [NcChannelPair]. + /// Returns the new [`NcChannelPair`]. /// /// *C style function: [ncplane_set_fg_not_default()][crate::ncplane_set_fg_not_default].* // @@ -416,7 +416,7 @@ impl NcPlane { /// Marks the background as NOT using the default color. /// - /// Returns the new [NcChannelPair]. + /// Returns the new [`NcChannelPair`]. /// /// *C style function: [ncplane_set_bg_not_default()][crate::ncplane_set_bg_not_default].* // @@ -428,7 +428,7 @@ impl NcPlane { /// Marks both the foreground and background as using the default color. /// - /// Returns the new [NcChannelPair]. + /// Returns the new [`NcChannelPair`]. /// /// *C style function: [ncplane_set_default()][crate::ncplane_set_default].* // @@ -440,7 +440,7 @@ impl NcPlane { /// Marks both the foreground and background as NOT using the default color. /// - /// Returns the new [NcChannelPair]. + /// Returns the new [`NcChannelPair`]. /// /// *C style function: [ncplane_set_not_default()][crate::ncplane_set_not_default].* // @@ -532,8 +532,8 @@ impl NcPlane { // ----------------------------------------------------------------------------- /// ## NcPlane methods: `NcCell` & `NcEgc` impl NcPlane { - /// Retrieves the current contents of the [NcCell] under the cursor, - /// returning the [NcEgc] and writing out the [NcStyle] and the [NcChannelPair]. + /// Retrieves the current contents of the [`NcCell`] under the cursor, + /// returning the [`NcEgc`] and writing out the [`NcStyle`] and the [`NcChannelPair`]. /// /// This NcEgc must be freed by the caller. /// @@ -554,8 +554,8 @@ impl NcPlane { Ok(egc) } - /// Retrieves the current contents of the [NcCell] under the cursor - /// into `cell`. Returns the number of bytes in the [NcEgc]. + /// Retrieves the current contents of the [`NcCell`] under the cursor + /// into `cell`. Returns the number of bytes in the [`NcEgc`]. /// /// This NcCell is invalidated if the associated NcPlane is destroyed. /// @@ -570,8 +570,8 @@ impl NcPlane { ] } - /// Retrieves the current contents of the specified [NcCell], returning the - /// [NcEgc] and writing out the [NcStyle] and the [NcChannelPair]. + /// Retrieves the current contents of the specified [`NcCell`], returning the + /// [`NcEgc`] and writing out the [`NcStyle`] and the [`NcChannelPair`]. /// /// This NcEgc must be freed by the caller. /// @@ -597,8 +597,8 @@ impl NcPlane { Ok(egc) } - /// Retrieves the current contents of the specified [NcCell] into `cell`. - /// Returns the number of bytes in the [NcEgc]. + /// Retrieves the current contents of the specified [`NcCell`] into `cell`. + /// Returns the number of bytes in the [`NcEgc`]. /// /// This NcCell is invalidated if the associated plane is destroyed. /// @@ -613,9 +613,9 @@ impl NcPlane { ] } - /// Extracts this NcPlane's base [NcCell]. + /// Extracts this `NcPlane`'s base [`NcCell`]. /// - /// The reference is invalidated if this NcPlane is destroyed. + /// The reference is invalidated if this `NcPlane` is destroyed. /// /// *C style function: [ncplane_base()][crate::ncplane_base].* pub fn base(&mut self) -> NcResult { @@ -624,14 +624,14 @@ impl NcPlane { error![res, "NcPlane.base()", cell] } - /// Sets this NcPlane's base [NcCell] from its components. + /// Sets this `NcPlane`'s base [`NcCell`] from its components. /// /// Returns the number of bytes copied out of `egc` if succesful. /// - /// It will be used for purposes of rendering anywhere that the NcPlane's + /// It will be used for purposes of rendering anywhere that the `NcPlane`'s /// gcluster is 0. /// - /// Erasing the NcPlane does not reset the base cell. + /// Note that erasing the `NcPlane` does not reset the base cell. /// /// *C style function: [ncplane_set_base()][crate::ncplane_set_base].* // call stack: @@ -659,12 +659,12 @@ impl NcPlane { ] } - /// Sets this NcPlane's base NcCell. + /// Sets this `NcPlane`'s base [`NcCell`]. /// - /// It will be used for purposes of rendering anywhere that the NcPlane's + /// It will be used for purposes of rendering anywhere that the `NcPlane`'s /// gcluster is 0. /// - /// Erasing the NcPlane does not reset the base cell. + /// Note that erasing the `NcPlane` does not reset the base cell. /// /// *C style function: [ncplane_set_base_cell()][crate::ncplane_set_base_cell].* pub fn set_base_cell(&mut self, cell: &NcCell) -> NcResult<()> { @@ -674,8 +674,8 @@ impl NcPlane { ] } - /// Creates a flat string from the NcEgc's of the selected region of the - /// NcPlane. + /// Creates a flat string from the `NcEgc`'s of the selected region of the + /// `NcPlane`. /// /// Starts at the plane's `beg_y` * `beg_x` coordinates (which must lie on /// the plane), continuing for `len_y` x `len_x` cells. @@ -710,11 +710,11 @@ impl NcPlane { .to_string() } - /// Erases every NcCell in this NcPlane, resetting all attributes to normal, - /// all colors to the default color, and all cells to undrawn. + /// Erases every [`NcCell`] in this `NcPlane`, resetting all attributes to + /// normal, all colors to the default color, and all cells to undrawn. /// - /// All cells associated with this NcPlane are invalidated, and must not be - /// used after the call, excluding the base cell. The cursor is homed. + /// All cells associated with this `NcPlane` are invalidated, and must not + /// be used after the call, excluding the base cell. The cursor is homed. /// /// *C style function: [ncplane_erase()][crate::ncplane_erase].* pub fn erase(&mut self) { @@ -723,11 +723,13 @@ impl NcPlane { } } - /// Replaces the NcCell at the specified coordinates with the provided NcCell, - /// advancing the cursor by its width (but not past the end of the plane). + /// Replaces the `NcCell` at the **specified** coordinates with the provided + /// `NcCell`, advancing the cursor by its width (but not past the end of + /// the plane). /// - /// The new NcCell must already be associated with the Plane. - /// On success, returns the number of columns the cursor was advanced. + /// The new `NcCell` must already be associated with the `NcPlane`. + /// + /// Returns the number of columns the cursor was advanced. /// /// *C style function: [ncplane_putc_yx()][crate::ncplane_putc_yx].* pub fn putc_yx(&mut self, y: NcDim, x: NcDim, cell: &NcCell) -> NcResult { @@ -739,11 +741,13 @@ impl NcPlane { ] } - /// Replaces the NcCell at the current coordinates with the provided NcCell, - /// advancing the cursor by its width (but not past the end of the plane). + /// Replaces the [`NcCell`] at the **current** coordinates with the provided + /// `NcCell`, advancing the cursor by its width (but not past the end of + /// the plane). /// - /// The new NcCell must already be associated with the Plane. - /// On success, returns the number of columns the cursor was advanced. + /// The new `NcCell` must already be associated with the `NcPlane`. + /// + /// Returns the number of columns the cursor was advanced. /// /// *C style function: [ncplane_putc()][crate::ncplane_putc].* pub fn putc(&mut self, cell: &NcCell) -> NcResult { @@ -751,9 +755,10 @@ impl NcPlane { error![res, &format!("NcPlane.putc({:?})", cell), res as NcDim] } - /// Calls [putchar_yx][NcPlane#method.putchar_yx] at the current cursor location. + /// Calls [`putchar_yx`][NcPlane#method.putchar_yx] at the current cursor + /// location. /// - /// On success, returns the number of columns the cursor was advanced. + /// Returns the number of columns the cursor was advanced. /// /// *C style function: [ncplane_putchar()][crate::ncplane_putchar].* pub fn putchar(&mut self, ch: char) -> NcResult { @@ -762,14 +767,14 @@ impl NcPlane { } // TODO: call put_egc - // /// Replaces the [NcEgc][crate::NcEgc] to the current location, but retain + // /// Replaces the [`NcEgc`][crate::NcEgc] to the current location, but retain // /// the styling. The current styling of the plane will not be changed. // pub fn putchar_stained(&mut self, y: NcDim, x: NcDim, ch: char) -> // NcResult { // error![crate::ncplane_putchar_stained(self, ch)] // } - /// Replaces the [NcEgc][crate::NcEgc], but retain the styling. + /// Replaces the [`NcEgc`][crate::NcEgc], but retain the styling. /// The current styling of the plane will not be changed. /// /// On success, returns the number of columns the cursor was advanced. @@ -784,7 +789,7 @@ impl NcPlane { ] } - /// Writes a series of [NcEgc][crate::NcEgc]s to the current location, + /// Writes a series of [`NcEgc`][crate::NcEgc]s to the current location, /// using the current style. /// /// Advances the cursor by some positive number of columns @@ -801,11 +806,11 @@ impl NcPlane { error![res, &format!("NcPlane.putstr({:?})", string), res as NcDim] } - /// Same as [putstr][NcPlane#method.putstr], but it also tries to move the + /// Same as [`putstr`][NcPlane#method.putstr], but it also tries to move the /// cursor to the beginning of the next row. /// - /// Advances the cursor by some positive number of columns (though not beyond - /// the end of the plane); this number is returned on success. + /// Advances the cursor by some positive number of columns (though not + /// beyond the end of the plane); this number is returned on success. /// /// On error, a non-positive number is returned, indicating the number of /// columns which were written before the error. @@ -818,7 +823,8 @@ impl NcPlane { Ok(cols) } - /// Same as [putstr_yx()][NcPlane#method.putstr_yx] but [NcAlign]ed on x. + /// Same as [`putstr_yx()`][NcPlane#method.putstr_yx] + /// but [`NcAlign`]ed on x. /// /// *C style function: [ncplane_putstr_aligned()][crate::ncplane_putstr_aligned].* pub fn putstr_aligned(&mut self, y: NcDim, align: NcAlign, string: &str) -> NcResult { @@ -830,12 +836,13 @@ impl NcPlane { ] } - /// Writes a series of [NcEgc][crate::NcEgc]s to the current location, but - /// retain the styling. + /// Writes a series of [`NcEgc`][crate::NcEgc]s to the current location, but + /// retains the styling. + /// /// The current styling of the plane will not be changed. /// - /// Advances the cursor by some positive number of columns (though not beyond - /// the end of the plane); this number is returned on success. + /// Advances the cursor by some positive number of columns (though not + /// beyond the end of the plane); this number is returned on success. /// /// On error, a non-positive number is returned, indicating the number of /// columns which were written before the error. @@ -850,7 +857,7 @@ impl NcPlane { ] } - /// Write a string, which is a series of [NcEgc][crate::NcEgc]s, to the + /// Write a string, which is a series of [`NcEgc`][crate::NcEgc]s, to the /// current location, using the current style. /// /// They will be interpreted as a series of columns. @@ -901,7 +908,7 @@ impl NcPlane { unsafe { crate::ncplane_abs_x(self) as NcDim } } - /// Duplicates this NcPlane. + /// Duplicates this `NcPlane`. /// /// The new NcPlane will have the same geometry, the same rendering state, /// and all the same duplicated content. @@ -917,14 +924,14 @@ impl NcPlane { unsafe { &mut *crate::ncplane_dup(self, null_mut()) } } - /// Returns the topmost NcPlane of the current pile. + /// Returns the topmost `NcPlane` of the current pile. /// /// *C style function: [ncpile_top()][crate::ncpile_top].* pub fn top(&mut self) -> &mut NcPlane { unsafe { &mut *crate::ncpile_top(self) } } - /// Returns the bottommost NcPlane of the current pile. + /// Returns the bottommost `NcPlane` of the current pile. /// /// *C style function: [ncpile_bottom()][crate::ncpile_bottom].* pub fn bottom<'a>(&mut self) -> &'a mut NcPlane { diff --git a/rust/src/plane/mod.rs b/rust/src/plane/mod.rs index 077b97f7b..dc86759c3 100644 --- a/rust/src/plane/mod.rs +++ b/rust/src/plane/mod.rs @@ -260,7 +260,7 @@ pub use reimplemented::*; /// Methods: /// - [`NcAlphaBits`](#ncplane-methods-ncalphabits) /// - [`NcChannel` & `NcChannelPair`](#ncplane-methods-ncchannel) -/// - [`NcColor`, `NcRgb` & default color](#ncplane-methods-nccolor-ncrgb--default-color) +/// - [`NcComponent`, `NcRgb` & default color](#ncplane-methods-nccomponent-ncrgb--default-color) /// - [`NcStyle` & `NcPaletteIndex`](#ncplane-methods-ncstylemask--paletteindex) /// - [`NcCell` & `NcEgc`](#ncplane-methods-nccell--ncegc) /// - [cursor](#ncplane-methods-cursor) diff --git a/rust/src/plane/reimplemented.rs b/rust/src/plane/reimplemented.rs index e7d35d7be..8ca8ef349 100644 --- a/rust/src/plane/reimplemented.rs +++ b/rust/src/plane/reimplemented.rs @@ -4,7 +4,7 @@ use core::ptr::null_mut; use crate::{ cstring, nccell_release, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel, NcChannelPair, - NcColor, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyle, NCRESULT_ERR, NCRESULT_OK, + NcComponent, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyle, NCRESULT_ERR, NCRESULT_OK, }; // Alpha ----------------------------------------------------------------------- @@ -77,32 +77,32 @@ pub fn ncplane_set_channels(plane: &mut NcPlane, channels: NcChannelPair) { unsafe { crate::ffi::ncplane_set_channels(plane, channels) }; } -// NcColor --------------------------------------------------------------------- +// NcComponent --------------------------------------------------------------------- -/// Gets the foreground [NcColor] RGB components from an [NcPlane]. +/// Gets the foreground RGB [NcComponent]s from an [NcPlane]. /// and returns the background [NcChannel]. /// /// *Method: NcPlane.[fg_rgb8()][NcPlane#method.fg_rgb8].* #[inline] pub fn ncplane_fg_rgb8( plane: &NcPlane, - red: &mut NcColor, - green: &mut NcColor, - blue: &mut NcColor, + red: &mut NcComponent, + green: &mut NcComponent, + blue: &mut NcComponent, ) -> NcChannel { crate::ncchannels_fg_rgb8(ncplane_channels(plane), red, green, blue) } -/// Gets the background [NcColor] RGB components from an [NcPlane], +/// Gets the background RGB [NcComponent]s from an [NcPlane], /// and returns the background [NcChannel]. /// /// *Method: NcPlane.[bg_rgb8()][NcPlane#method.bg_rgb8].* #[inline] pub fn ncplane_bg_rgb8( plane: &NcPlane, - red: &mut NcColor, - green: &mut NcColor, - blue: &mut NcColor, + red: &mut NcComponent, + green: &mut NcComponent, + blue: &mut NcComponent, ) -> NcChannel { crate::ncchannels_bg_rgb8(ncplane_channels(plane), red, green, blue) }