egui icon indicating copy to clipboard operation
egui copied to clipboard

Can't center inside of a grid both vertically and horizontally.

Open robertpauson opened this issue 3 years ago • 2 comments

I'm totally not sure whether that's a bug, or anything, but I've read through the docs couple of times, and for example this code that seems to overdo it but convey what I want:

ui.with_layout(Layout::left_to_right(Align::Center).with_main_align(Align::Center).with_cross_align(Align::Center), |ui| {
    ui.label(format!("{:?}", v));
});

Results in vertical alignment to center, and main alignment to left.

The only code I've found through trial and error that is capable of centering it horizontally is this:

ui.with_layout(Layout::top_down(Align::Center).with_cross_align(Align::Center), |ui| {
    ui.label(format!("{:?}", v));
});

But of course, then it's vertically aligned on the very ceiling of the cell.

The crux of the problem is that this

ui.with_layout(Layout::left_to_right(Align::Center).with_main_align(Align::Center), |ui| {
    ui.label(format!("{:?}", v));
});

centers vertically, not horizontally, inside Grid. (which seems to be default centering inside Grid along vertical axis)

robertpauson avatar Nov 06 '22 12:11 robertpauson

It looks like alignment is a TODO for grid:

https://github.com/emilk/egui/blob/cd0f66b9ae661be737ce57f26fb305cf124f6b73/crates/egui/src/grid.rs#L175-L179

I'd like to be able to right align the first column.

image

ctaggart avatar Jan 16 '23 23:01 ctaggart

Any update on this? I would like to align content in grid cells to the top.

Danvil avatar May 19 '25 22:05 Danvil