I have created my first egui app. The update loop looks like
impl eframe::App for App {
fn update(&mut self, ctx: &Context, _frame: &mut Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.with_layout(Layout::top_down(Align::Center), |ui| {
ui.add(Label::new("bacon"));
let clicked = ui.add(Button::new("foo")).clicked();
if clicked {
println!("foo")
}
let clicked = ui.add(FurnaceGraph::default()).clicked();
if clicked {
println!("clicked");
}
})
});
}
and the ui for FurnaceGraph looks like
impl Widget for FurnaceGraph {
fn ui(mut self, ui: &mut Ui) -> Response {
let (_id, rect) = ui.allocate_space(Vec2::new(self.width as f32, self.height as f32));
let response = ui.allocate_response(rect.size(), Sense::click());
// println!("enabled? {}", ui.is_enabled());
let texture = self.get_texture(ui);
let texture_size = texture.size_vec2();
let img = Image::new(texture, texture_size);
img.paint_at(ui, Rect::from_min_max(rect.min, rect.min + img.size()));
response
}
}
I think I am asking to Sense::click()s when I allocate_response, but it never prints "clicked" when I click on the graph. I do get "foo" when I click on the foo button.
What do I have to tweak to not miss clicks?