Label does not respect `LayoutJob` alignment when using `add_sized`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
**Describe the bug**
What I'm trying to accomplish is aligning some text left, and some text right within a container.
The method I'm using is:
* Container with `Layout::right_to_left`.
* Adding the right-most label first.
* Adding the left-most label second using `add_sized` and the available size.
This almost works, but the text inside the left-most label is centered instead of left-aligned.
**To Reproduce**
```rust
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let left = egui::text::LayoutJob::default();
egui::RichText::new("left").color(egui::Color32::WHITE).append_to(
&mut left,
&text_style,
egui::FontSelection::default(),
egui::Align::Min,
);
let right = egui::text::LayoutJob::default();
egui::RichText::new("right").color(egui::Color32::WHITE).append_to(
&mut right,
&text_style,
egui::FontSelection::default(),
egui::Align::Min,
);
ui.add(egui::Label::new(right));
ui.add_sized(ui.available_size(), egui::Label::new(left));
});
```
**Expected behavior**
Text within the `Label` is left aligned since it is specified in `RichText` (`egui::Align::Min`).
Maybe there is some other way to achieve what I'm trying to do?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Rust reproduction using Label, LayoutJob, add_sized, and Layout::right_to_left. Investigate how the label's available size is combined with the alignment specified in RichText. Done means the left label's text is left-aligned while the right label remains right-aligned in the shown layout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100