Last active
August 25, 2025 21:00
-
-
Save MoAlyousef/bb61e352ed24a3900a582f3987dd538d 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