I am trying to change the string inside an egui label using a function. I made a reference to the content of the label and passed it along to the function but it doesn't change what is displayed in the application.
let mut label_text = "Change this".to_string();
egui::CentralPanel::default().show(ctx, |ui| {
ui.add(egui::Label::new(&label_text));
if ui.add(egui::Button::new("Press me")).clicked() {
do_stuff(&mut label_text, &ctx);
}
});
and the function do_stuff:
fn do_stuff(labeltext: &mut String, ctx: &egui::Context){
labeltext.clear();
labeltext.push_str("Changed");
ctx.request_repaint();
}
I am using the following dependencies in my toml:
eframe = "0.21.3"
egui = "0.21.0"
Also on the same topic how can I get a reference id for an egui widget so I can call that id from whatever function later on? From what I saw most widgets don't have an id or unique_id attribute anymore. Sorry if it's a noob question I am just starting out with Rust and Egui/Eframe, and it is all very confusing to me as in C++ every element of an UI would have an id which you could reference anywhere assign it to a handle and then change anything about that element.