rust: several fixes; add example for issue #1509

- fix method name: NcPlane.at_yx_cell().
- tell bidngen derive more traits when it can
- update .gitignore so it doesn't ignore rust/build
pull/1516/head
joseLuís 3 years ago
parent 7d51756a12
commit 429ca673d3

1
rust/.gitignore vendored

@ -0,0 +1 @@
examples/*.c

@ -42,6 +42,13 @@ fn main() {
.no_copy("ncuplot")
.no_copy("ncvisual")
.no_copy("notcurses")
// try to derive more traits
.derive_default(true)
.derive_hash(true)
.derive_partialord(true)
.derive_ord(true)
.derive_partialeq(true)
.derive_eq(true)
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks));

@ -0,0 +1,65 @@
//! https://github.com/dankamongmen/notcurses/issues/1509
//! strange color behaviour when moving planes
//
// TODO
// -
//
use std::collections::BTreeMap;
use libnotcurses_sys::*;
fn main() {
let mut map = BTreeMap::<String, NcCell>::new();
let _res = notcurses(&mut map);
for (k, v) in map {
//println!("{}: {:016X}", k, v.channels);
//println!("{}: {:064b}", k, v.channels);
println!("{}: {:?}", k, v);
}
}
fn notcurses(map: &mut BTreeMap<String, NcCell>) -> NcResult<()> {
let mut nc = FullMode::new()?;
let stdplane = nc.stdplane();
map.insert("stdp_base0".into(), stdplane.base()?);
let mut channels = NcChannelPair::with_rgb8(0, 0, 0, 0, 0x88, 0);
stdplane.set_base(" ", 0, channels)?;
map.insert("stdp_base1".into(), stdplane.base()?);
// create one 1x1 blue plane on the top left corner
let blue = NcPlane::new_bound(stdplane, 0, 0, 1, 1)?;
map.insert("blue_base0".into(), blue.base()?);
blue.set_base(" ", 0, channels.set_bg_rgb8(0, 0, 0x88))?;
map.insert("blue_base1".into(), blue.base()?);
rsleep![&mut nc, 0, 500];
// create another 1x1 red plane, on top
let red = NcPlane::new_bound(stdplane, 0, 0, 1, 1)?;
map.insert(" red_base0".into(), red.base()?);
red.set_base(" ", 0, channels.set_bg_rgb8(0x88, 0, 0))?;
map.insert(" red_base1".into(), red.base()?);
rsleep![&mut nc, 0, 500];
// move the red plane to the bottom
// BUG: the underlying blue plane renders black
red.move_yx(1, 0)?;
map.insert("blue_base2".into(), blue.base()?);
map.insert(" red_base2".into(), red.base()?);
map.insert("stdp_base2".into(), stdplane.base()?);
rsleep![&mut nc, 1];
// move the blue plane to the right
// BUG: the underlying green stdplane plane renders black
blue.move_yx(0, 1)?;
map.insert("stdp_base3".into(), stdplane.base()?); // CHECK
map.insert(" red_base3".into(), red.base()?);
map.insert("blue_base3".into(), blue.base()?);
rsleep![&mut nc, 1];
Ok(())
}

@ -575,7 +575,7 @@ impl NcPlane {
///
/// *C style function: [ncplane_at_yx_cell()][crate::ncplane_at_yx_cell].*
#[inline]
pub fn ncplane_at_yx_cell(&mut self, y: NcDim, x: NcDim, cell: &mut NcCell) -> NcResult<u32> {
pub fn at_yx_cell(&mut self, y: NcDim, x: NcDim, cell: &mut NcCell) -> NcResult<u32> {
let bytes = unsafe { crate::ncplane_at_yx_cell(self, y as i32, x as i32, cell) };
error![
bytes,
@ -584,7 +584,7 @@ impl NcPlane {
]
}
/// Extracts this NcPlane's base [NcCell] into `cell`.
/// Extracts this NcPlane's base [NcCell].
///
/// The reference is invalidated if this NcPlane is destroyed.
///

Loading…
Cancel
Save