emilk / emilk/egui

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

Open
#2,247 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 12h
Merged PRs (30d)
67

Description

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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.