diff --git a/rust/examples/full-capabilities.rs b/rust/examples/full-capabilities.rs index ffa05cbbe..f7b90bb07 100644 --- a/rust/examples/full-capabilities.rs +++ b/rust/examples/full-capabilities.rs @@ -8,14 +8,16 @@ fn main() -> NcResult<()> { println!( "Can display UTF-8: {0} -Can display sextant characters: {1} -Can open images: {2} -Can open videos: {3} -Supports Pixels: {4:?} -Supports True Color: {5} -Palette size: {6:?} +Can display braille characters: {1} +Can display sextant characters: {2} +Can open images: {3} +Can open videos: {4} +Supports Pixels: {5:?} +Supports True Color: {6} +Palette size: {7:?} ", nc.canutf8(), + nc.canbraille(), nc.cansextant(), nc.canopen_images(), nc.canopen_videos(), @@ -27,6 +29,6 @@ Palette size: {6:?} let pixelgeom = nc.stdplane().pixelgeom(); println!("{:#?}", pixelgeom); - rsleep![&mut nc, 1]; + nc.render()?; Ok(()) } diff --git a/rust/src/plane/mod.rs b/rust/src/plane/mod.rs index c045da88a..13a6369be 100644 --- a/rust/src/plane/mod.rs +++ b/rust/src/plane/mod.rs @@ -183,8 +183,6 @@ mod reimplemented; pub(crate) use helpers::*; pub use reimplemented::*; -use crate::NcDim; - // NcPlane /// Fundamental drawing surface. /// @@ -272,72 +270,3 @@ pub type NcFdPlane = crate::bindings::ffi::ncfdplane; /// /// `type in C: ncplane_options (struct)` pub type NcFdPlaneOptions = crate::bindings::ffi::ncfdplane_options; - -/// Blitter Mode (`NCBLIT_*`) -/// -/// We never blit full blocks, but instead spaces (more efficient) with the -/// background set to the desired foreground. -/// -/// ## Modes -/// -/// - [`NCBLIT_1x1`] -/// - [`NCBLIT_2x1`] -/// - [`NCBLIT_2x2`] -/// - [`NCBLIT_3x2`] -/// - [`NCBLIT_4x1`] -/// - [`NCBLIT_8x1`] -/// - [`NCBLIT_BRAILLE`] -/// - [`NCBLIT_DEFAULT`] -/// - [`NCBLIT_PIXEL`] -/// -pub type NcBlitter = crate::bindings::ffi::ncblitter_e; - -/// [`NcBlitter`] mode using: space, compatible with ASCII -pub const NCBLIT_1x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_1x1; - -/// [`NcBlitter`] mode using: halves + 1x1 (space) -/// ▄▀ -pub const NCBLIT_2x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_2x1; - -/// [`NcBlitter`] mode using: quadrants + 2x1 -/// ▗▐ ▖▀▟▌▙ -pub const NCBLIT_2x2: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_2x2; - -/// [`NcBlitter`] mode using: sextants -/// 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬉🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝🬞🬟🬠🬡🬢🬣🬤🬥🬦🬧🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻 -pub const NCBLIT_3x2: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_3x2; - -/// [`NcBlitter`] mode using: four vertical levels -/// █▆▄▂ -pub const NCBLIT_4x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_4x1; - -/// [`NcBlitter`] mode using: eight vertical levels -/// █▇▆▅▄▃▂▁ -pub const NCBLIT_8x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_8x1; - -/// [`NcBlitter`] mode using: 4 rows, 2 cols (braille) -/// ⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿ -pub const NCBLIT_BRAILLE: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_BRAILLE; - -/// [`NcBlitter`] mode where the blitter is automatically chosen -pub const NCBLIT_DEFAULT: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_DEFAULT; - -/// Sixel/Pixel mode -/// -/// See [Sixel in Wikipedia](https://en.wikipedia.org/wiki/Sixel). -pub const NCBLIT_PIXEL: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_PIXEL; - -/// Contains the pixel geometry information as returned by the -/// NcPlane.[pixelgeom()][NcPlane#method.pixelgeom] method. -/// -/// If bitmaps are not supported, the fields `max_bitmap_*` will be 0. -#[derive(Clone, Debug)] -pub struct NcPixelGeometry { - /// Geometry of the display region - pub display_y: NcDim, - pub display_x: NcDim, - pub cell_y: NcDim, - pub cell_x: NcDim, - pub max_bitmap_y: NcDim, - pub max_bitmap_x: NcDim, -} diff --git a/rust/src/visual/mod.rs b/rust/src/visual/mod.rs index 241847822..02ac3840e 100644 --- a/rust/src/visual/mod.rs +++ b/rust/src/visual/mod.rs @@ -24,7 +24,7 @@ //W ncvisual_subtitle #[allow(unused_imports)] // for the doc comments -use crate::{NcChannel, NcRgb}; +use crate::{NcChannel, NcDim, NcRgb}; mod methods; @@ -110,7 +110,7 @@ pub const NCVISUAL_OPTION_ADDALPHA: u32 = crate::bindings::ffi::NCVISUAL_OPTION_ /// Uses [`NCCELL_ALPHA_BLEND`][crate::NCCELL_ALPHA_BLEND] with visual. pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::ffi::NCVISUAL_OPTION_BLEND; -/// Fails rather than degrade. +/// Fails rather than gracefully degrade. See [NcBlitter]. pub const NCVISUAL_OPTION_NODEGRADE: u32 = crate::bindings::ffi::NCVISUAL_OPTION_NODEGRADE; /// Y is an alignment, not absolute. @@ -118,3 +118,83 @@ pub const NCVISUAL_OPTION_VERALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTIO /// X is an alignment, not absolute. pub const NCVISUAL_OPTION_HORALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTION_HORALIGNED; + +/// Blitter Mode (`NCBLIT_*`) +/// +/// We never blit full blocks, but instead spaces (more efficient) with the +/// background set to the desired foreground. +/// +/// ## Modes +/// +/// - [`NCBLIT_1x1`] +/// - [`NCBLIT_2x1`] +/// - [`NCBLIT_2x2`] +/// - [`NCBLIT_3x2`] +/// - [`NCBLIT_4x1`] +/// - [`NCBLIT_8x1`] +/// - [`NCBLIT_BRAILLE`] +/// - [`NCBLIT_DEFAULT`] +/// - [`NCBLIT_PIXEL`] +/// +/// There is a mechanism of graceful degradation, that works as follows: +/// - without braille support, NCBLIT_BRAILLE decays to NCBLIT_3x2 +/// - without bitmap support, NCBLIT_PIXEL decays to NCBLIT_3x2 +/// - without sextant support, NCBLIT_3x2 decays to NCBLIT_2x2 +/// - without quadrant support, NCBLIT_2x2 decays to NCBLIT_2x1 +/// - the only viable blitters in ASCII are NCBLIT_1x1 and NCBLIT_PIXEL +/// +/// If you don't want this behaviour you have to use [NCVISUAL_OPTION_NODEGRADE] +/// +pub type NcBlitter = crate::bindings::ffi::ncblitter_e; + +/// [`NcBlitter`] mode using: space, compatible with ASCII +pub const NCBLIT_1x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_1x1; + +/// [`NcBlitter`] mode using: halves + 1x1 (space) +/// ▄▀ +pub const NCBLIT_2x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_2x1; + +/// [`NcBlitter`] mode using: quadrants + 2x1 +/// ▗▐ ▖▀▟▌▙ +pub const NCBLIT_2x2: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_2x2; + +/// [`NcBlitter`] mode using: sextants +/// 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬉🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝🬞🬟🬠🬡🬢🬣🬤🬥🬦🬧🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻 +pub const NCBLIT_3x2: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_3x2; + +/// [`NcBlitter`] mode using: four vertical levels +/// █▆▄▂ +pub const NCBLIT_4x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_4x1; + +/// [`NcBlitter`] mode using: eight vertical levels +/// █▇▆▅▄▃▂▁ +pub const NCBLIT_8x1: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_8x1; + +/// [`NcBlitter`] mode using: 4 rows, 2 cols (braille) +/// ⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿ +pub const NCBLIT_BRAILLE: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_BRAILLE; + +/// [`NcBlitter`] mode where the blitter is automatically chosen +pub const NCBLIT_DEFAULT: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_DEFAULT; + +/// Sixel/Pixel mode +/// +/// NCBLIT_PIXEL +/// +/// See [Sixel in Wikipedia](https://en.wikipedia.org/wiki/Sixel). +pub const NCBLIT_PIXEL: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_PIXEL; + +/// Contains the pixel geometry information as returned by the +/// NcPlane.[pixelgeom()][crate::NcPlane#method.pixelgeom] method. +/// +/// If bitmaps are not supported, the fields `max_bitmap_*` will be 0. +#[derive(Clone, Debug)] +pub struct NcPixelGeometry { + /// Geometry of the display region + pub display_y: NcDim, + pub display_x: NcDim, + pub cell_y: NcDim, + pub cell_x: NcDim, + pub max_bitmap_y: NcDim, + pub max_bitmap_x: NcDim, +}