From 932f4c1b7c83dd4db0e2770c2f6269cee0152822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Sat, 10 Apr 2021 15:54:38 +0200 Subject: [PATCH] [rust] simplify issue-1509 example --- rust/examples/issue-1509.rs | 56 ++++++++----------------------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/rust/examples/issue-1509.rs b/rust/examples/issue-1509.rs index 2be2c7bea..434e55e8d 100644 --- a/rust/examples/issue-1509.rs +++ b/rust/examples/issue-1509.rs @@ -9,56 +9,22 @@ use std::collections::BTreeMap; use libnotcurses_sys::*; -fn main() { - let mut map = BTreeMap::::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) -> NcResult<()> { +fn main() -> NcResult<()> { let mut nc = FullMode::new()?; - let stdplane = nc.stdplane(); - map.insert("stdp_base0".into(), stdplane.base()?); + // get the stdplane and color it green + let green = nc.stdplane(); + let mut channels = NcChannelPair::with_rgb8(0xFF, 0, 0, 0, 0x88, 0); + green.set_base("-", 0, channels)?; - 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()?); + // create one 1x1 blue plane at 1,1 + let blue = NcPlane::new_bound(green, 1, 1, 1, 1)?; + blue.set_base("B", 0, channels.set_bg_rgb8(0, 0, 0x88))?; 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()?); + // move it to 4,4 + // BUG: here it shows something is wrong + blue.move_yx(4, 4)?; rsleep![&mut nc, 1]; Ok(())