1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Add WidgetText::size (#8377)

## Summary

- Add `WidgetText::size` for sizing plain, rich, and layout-job text
uniformly.
- Preserve already-laid-out galleys.

## Test

- `cargo clippy -p egui --all-features --all-targets`
- `cargo test -p egui --all-features`

* [x] I have followed the instructions in the PR template
This commit is contained in:
Emil Ernerfeldt
2026-08-02 12:25:32 -07:00
committed by GitHub
parent 7fd54ef741
commit 7f30623cff

View File

@@ -558,6 +558,25 @@ impl Default for WidgetText {
}
impl WidgetText {
/// Override the font size.
///
/// For [`Self::Galley`], this does nothing because it has already been laid out.
#[must_use]
pub fn size(self, size: f32) -> Self {
match self {
Self::Text(text) => RichText::new(text).size(size).into(),
Self::RichText(text) => Self::RichText(Arc::new(Arc::unwrap_or_clone(text).size(size))),
Self::LayoutJob(job) => {
let mut job = Arc::unwrap_or_clone(job);
for section in &mut job.sections {
section.format.font_id.size = size;
}
Self::LayoutJob(Arc::new(job))
}
Self::Galley(galley) => Self::Galley(galley),
}
}
#[inline]
pub fn is_empty(&self) -> bool {
match self {