2020-12-27 18:00:32 +00:00
|
|
|
//! based on the proof of concept at ../../src/poc/menu.c
|
|
|
|
|
2021-04-07 09:47:05 +00:00
|
|
|
// FIXME: has bugs, doesn't work well
|
2021-04-07 18:32:46 +00:00
|
|
|
// probably related to the arrays or the strings...
|
2021-04-07 09:47:05 +00:00
|
|
|
|
2020-12-27 18:00:32 +00:00
|
|
|
use libnotcurses_sys::*;
|
|
|
|
|
|
|
|
fn main() -> NcResult<()> {
|
2021-04-17 20:13:43 +00:00
|
|
|
let mut nc = Nc::new()?;
|
2020-12-27 18:00:32 +00:00
|
|
|
nc.mouse_enable()?;
|
|
|
|
|
|
|
|
let mut demo_items = [
|
|
|
|
NcMenuItem::new("Restart", NcInput::with_ctrl('r')),
|
|
|
|
NcMenuItem::new("Disabled", NcInput::with_ctrl('d')),
|
|
|
|
];
|
|
|
|
let mut file_items = [
|
|
|
|
NcMenuItem::new("New", NcInput::with_ctrl('n')),
|
|
|
|
NcMenuItem::new("Open", NcInput::with_ctrl('o')),
|
|
|
|
NcMenuItem::new("Close", NcInput::with_ctrl('c')),
|
|
|
|
NcMenuItem::new_empty(),
|
|
|
|
NcMenuItem::new("Quit", NcInput::with_ctrl('q')),
|
|
|
|
];
|
|
|
|
|
2020-12-30 17:40:54 +00:00
|
|
|
let mut help_items = [NcMenuItem::new("About", NcInput::with_ctrl('a'))];
|
2020-12-27 18:00:32 +00:00
|
|
|
|
|
|
|
let mut sections = [
|
|
|
|
NcMenuSection::new("Schwarzgerät", &mut demo_items, NcInput::with_alt('ä')),
|
|
|
|
NcMenuSection::new("File", &mut file_items, NcInput::with_alt('f')),
|
2020-12-30 23:11:49 +00:00
|
|
|
NcMenuSection::new_separator(),
|
2021-01-01 13:17:01 +00:00
|
|
|
// DEBUG: remove alt modifier for now.
|
|
|
|
NcMenuSection::new("Help", &mut help_items, NcInput::new('h')),
|
2020-12-27 18:00:32 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
let mut mopts = NcMenuOptions::new(&mut sections);
|
|
|
|
mopts.header_channels_mut().set_fg_rgb(0x00ff00);
|
|
|
|
mopts.header_channels_mut().set_bg_rgb(0x440000);
|
|
|
|
mopts.section_channels_mut().set_fg_rgb(0xb0d700);
|
|
|
|
mopts.section_channels_mut().set_bg_rgb(0x002000);
|
|
|
|
|
2021-01-03 01:40:28 +00:00
|
|
|
let stdplane = nc.stdplane();
|
2021-01-01 13:17:01 +00:00
|
|
|
let (dim_y, _dim_x) = stdplane.dim_yx();
|
|
|
|
|
|
|
|
let menu_top = NcMenu::new(stdplane, mopts)?;
|
2020-12-30 23:11:49 +00:00
|
|
|
menu_top.item_set_status("Schwarzgerät", "Disabled", false)?;
|
|
|
|
menu_top.item_set_status("Schwarzgerät", "Restart", false)?;
|
2020-12-27 18:00:32 +00:00
|
|
|
|
2021-04-07 18:32:46 +00:00
|
|
|
stdplane.set_base("x", 0, NcChannelPair::with_rgb(0x88aa00, 0x000088))?;
|
2020-12-27 18:00:32 +00:00
|
|
|
|
2020-12-30 17:40:54 +00:00
|
|
|
nc.render()?;
|
|
|
|
|
2021-01-01 13:17:01 +00:00
|
|
|
stdplane.set_fg_rgb(0x00dddd);
|
|
|
|
stdplane.putstr_aligned(
|
2020-12-30 17:40:54 +00:00
|
|
|
dim_y - 1,
|
|
|
|
NCALIGN_RIGHT,
|
|
|
|
" -=+ menu poc. press q to exit +=-",
|
|
|
|
)?;
|
2021-01-01 13:17:01 +00:00
|
|
|
|
2021-01-02 18:45:15 +00:00
|
|
|
run_menu(&mut nc, menu_top)?;
|
2020-12-30 23:11:49 +00:00
|
|
|
|
2021-01-01 13:17:01 +00:00
|
|
|
stdplane.erase(); // is this needed?
|
|
|
|
|
|
|
|
// BUG FIXME: this doesn't show over the menu (at row 0)
|
|
|
|
stdplane.putstr_aligned(0, NCALIGN_RIGHT, " -=+ menu poc. press q to exit +=-")?;
|
|
|
|
stdplane.putstr_aligned(1, NCALIGN_CENTER, " -=+ menu poc. press q to exit +=-")?;
|
|
|
|
stdplane.putstr_aligned(2, NCALIGN_LEFT, " -=+ menu poc. press q to exit +=-")?;
|
2020-12-30 17:40:54 +00:00
|
|
|
|
2020-12-30 23:11:49 +00:00
|
|
|
mopts.flags |= NCMENU_OPTION_BOTTOM;
|
2021-01-01 13:17:01 +00:00
|
|
|
let menu_bottom = NcMenu::new(stdplane, mopts)?;
|
|
|
|
|
2021-01-02 18:45:15 +00:00
|
|
|
run_menu(&mut nc, menu_bottom)?;
|
2020-12-27 18:00:32 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-04-17 20:13:43 +00:00
|
|
|
fn run_menu(nc: &mut Nc, menu: &mut NcMenu) -> NcResult<()> {
|
2020-12-30 23:11:49 +00:00
|
|
|
// yellow rectangle
|
|
|
|
let planeopts = NcPlaneOptions::new_aligned(10, NCALIGN_CENTER, 3, 40);
|
2021-01-03 01:40:28 +00:00
|
|
|
let stdplane = nc.stdplane();
|
2020-12-30 23:11:49 +00:00
|
|
|
let selplane = NcPlane::with_options_bound(stdplane, planeopts)?;
|
|
|
|
selplane.set_fg_rgb(0);
|
|
|
|
selplane.set_bg_rgb(0xdddddd);
|
|
|
|
let mut channels = 0;
|
|
|
|
channels.set_fg_rgb(0x000088);
|
|
|
|
channels.set_bg_rgb(0x88aa00);
|
2021-01-01 13:17:01 +00:00
|
|
|
selplane.set_base(" ", 0, channels)?;
|
2020-12-30 23:11:49 +00:00
|
|
|
|
2021-01-01 12:59:30 +00:00
|
|
|
let mut ni = NcInput::new_empty();
|
2020-12-30 23:11:49 +00:00
|
|
|
let mut keypress: char;
|
2021-01-01 13:17:01 +00:00
|
|
|
nc.render()?;
|
2020-12-30 23:11:49 +00:00
|
|
|
|
|
|
|
loop {
|
2021-01-01 13:17:01 +00:00
|
|
|
stdplane.erase();
|
|
|
|
selplane.erase();
|
|
|
|
|
2020-12-30 23:11:49 +00:00
|
|
|
keypress = nc.getc_blocking(Some(&mut ni))?;
|
|
|
|
|
2021-01-01 13:17:01 +00:00
|
|
|
// DEBUG
|
|
|
|
stdplane.putstr_yx(2, 0, &format!["{:?}", ni])?;
|
|
|
|
nc.render()?;
|
|
|
|
|
|
|
|
// BUG FIXME: always returns false:
|
2020-12-30 23:11:49 +00:00
|
|
|
if !menu.offer_input(ni) {
|
2021-01-01 13:17:01 +00:00
|
|
|
match keypress {
|
|
|
|
'q' => {
|
2020-12-30 23:11:49 +00:00
|
|
|
menu.destroy()?;
|
|
|
|
selplane.destroy()?;
|
|
|
|
return Ok(());
|
2021-01-02 18:45:15 +00:00
|
|
|
}
|
2021-01-01 13:17:01 +00:00
|
|
|
NCKEY_ENTER => {
|
|
|
|
if let Some(selection) = menu.selected(Some(&mut ni)) {
|
|
|
|
match selection.as_ref() {
|
|
|
|
"Quit" => {
|
|
|
|
menu.destroy()?;
|
|
|
|
selplane.destroy()?;
|
|
|
|
return Ok(());
|
|
|
|
}
|
2021-01-02 18:45:15 +00:00
|
|
|
_ => (),
|
2021-01-01 13:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-30 23:11:49 +00:00
|
|
|
}
|
2021-01-02 18:45:15 +00:00
|
|
|
_ => (),
|
2020-12-30 23:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-01 12:59:30 +00:00
|
|
|
|
|
|
|
let mut selni = NcInput::new_empty();
|
2021-01-01 13:17:01 +00:00
|
|
|
if let Some(selitem) = menu.selected(Some(&mut selni)) {
|
|
|
|
selplane.putstr_aligned(1, NCALIGN_CENTER, &selitem)?;
|
|
|
|
} else {
|
|
|
|
// DEBUG
|
|
|
|
selplane.putstr_aligned(1, NCALIGN_CENTER, "nothing opened")?;
|
|
|
|
}
|
2020-12-30 23:11:49 +00:00
|
|
|
nc.render()?;
|
|
|
|
}
|
|
|
|
}
|