popup_browser/
popup_browser.rs

1// Example showing a browser widget with right click popup menu
2
3use fltk::{prelude::*, *};
4
5fn main() {
6    let app = app::App::default().with_scheme(app::Scheme::Gtk);
7    app::background(211, 211, 211);
8
9    let mut win = window::Window::default().with_size(900, 300);
10    let mut b = browser::HoldBrowser::default()
11        .with_size(900 - 10, 300 - 10)
12        .center_of(&win);
13    let widths = &[50, 50, 50, 70, 70, 40, 40, 70, 70, 50];
14
15    b.set_column_widths(widths);
16    b.set_column_char('\t');
17    b.add("USER\tPID\t%CPU\t%MEM\tVSZ\tRSS\tTTY\tSTAT\tSTART\tTIME\tCOMMAND");
18    b.add("root\t2888\t0.0\t0.0\t1352\t0\ttty3\tSW\tAug15\t0:00\t@b@f/sbin/mingetty tty3");
19    b.add("erco\t2889\t0.0\t13.0\t221352\t0\ttty3\tR\tAug15\t1:34\t@b@f/usr/local/bin/render a35 0004");
20    b.add("uucp\t2892\t0.0\t0.0\t1352\t0\tttyS0\tSW\tAug15\t0:00\t@b@f/sbin/agetty -h 19200 ttyS0 vt100");
21    b.add("root\t13115\t0.0\t0.0\t1352\t0\ttty2\tSW\tAug30\t0:00\t@b@f/sbin/mingetty tty2");
22    b.add(
23        "root\t13464\t0.0\t0.0\t1352\t0\ttty1\tSW\tAug30\t0:00\t@b@f/sbin/mingetty tty1 --noclear",
24    );
25
26    let menu = menu::MenuItem::new(&["1st menu item\t", "2nd menu item\t", "3rd menu item\t"]);
27    b.select(2);
28
29    b.set_callback(move |_| {
30        if app::event_mouse_button() == app::MouseButton::Right {
31            // or app::event_button() == 3
32            let coords = app::event_coords();
33            match menu.popup(coords.0, coords.1) {
34                None => println!("No value was chosen!"),
35                Some(val) => println!("{}", val.label().unwrap()),
36            }
37        }
38    });
39
40    win.make_resizable(true);
41    win.end();
42    win.show();
43    app.run().unwrap();
44}