Help with alignment in eframe/egui
⚓ Rust 📅 2025-09-07 👤 surdeus 👁️ 10The following trivial problem nearly drove me crazy and occupied me for hours: I'm using eFrame and eGUI to design a GUI. Various buttons, etc., are supposed to be arranged in a row at the top of the window. However, the second requirement is causing a problem: this row should be horizontally centered. In HTML, I would put everything in a row in a div and center the div, but that just doesn't work. I've tried numerous times, but nothing has really worked. Either the objects (labels for testing purposes) aren't in a row or they aren't horizontally centered at the top.
So the following code is not working (just one example):
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.with_layout(
egui::Layout::top_down(egui::Align::Center),
|ui| {
ui.horizontal(|ui| {
ui.label("Test1");
ui.label("Test2");
ui.label("Test3");
});
},
);
});
}
Please help!
3 posts - 3 participants
🏷️ Rust_feed