-
-
Save pa-0/33c3a968785eca0afa37a29b92bd2be8 to your computer and use it in GitHub Desktop.
A popup hack allowing to use dynamic strings, basically by creating a hidden Choice widget then getting the MenuItem using the `MenuExt::at(0)` method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use fltk::{prelude::*, *}; | |
| fn main() { | |
| let mut choice = menu::Choice::default(); | |
| choice.add_choice("File/New"); | |
| choice.add_choice(&format!("{}\t", "Edit/Cut")); | |
| choice.add_choice("File/Open"); | |
| choice.add_choice(&format!("Edit/{}", "Copy")); | |
| choice.add_choice("Other|Option"); | |
| let app = app::App::default(); | |
| let mut win = window::Window::default() | |
| .with_size(400, 300) | |
| .with_label("Right Click!"); | |
| win.end(); | |
| win.show(); | |
| win.handle(move |_, ev| match ev { | |
| enums::Event::Push => { | |
| if app::event_mouse_button() == app::MouseButton::Right { | |
| let coords = app::event_coords(); | |
| let items = choice.at(0).unwrap(); | |
| match items.popup(coords.0, coords.1) { | |
| None => println!("No value was chosen!"), | |
| Some(val) => println!("{}", val.label().unwrap()), | |
| } | |
| true | |
| } else { | |
| false | |
| } | |
| } | |
| _ => false, | |
| }); | |
| app.run().unwrap(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment