Skip to content

Commit

Permalink
Add WidgetText::into_galley_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 22, 2024
1 parent ae55f2e commit eb1b266
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions crates/egui/src/widget_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,39 @@ impl WidgetText {
fallback_font: impl Into<FontSelection>,
) -> Arc<Galley> {
let wrap = wrap.unwrap_or_else(|| ui.wrap_text());
let valign = ui.layout().vertical_align();
let style = ui.style();

self.into_galley_impl(
ui.ctx(),
style,
wrap,
available_width,
fallback_font.into(),
valign,
)
}

pub fn into_galley_impl(
self,
ctx: &crate::Context,
style: &Style,
wrap: bool,
available_width: f32,
fallback_font: FontSelection,
default_valign: Align,
) -> Arc<Galley> {
let wrap_width = if wrap { available_width } else { f32::INFINITY };

match self {
Self::RichText(text) => {
let valign = ui.layout().vertical_align();
let mut layout_job = text.into_layout_job(ui.style(), fallback_font.into(), valign);
let mut layout_job = text.into_layout_job(style, fallback_font, default_valign);
layout_job.wrap.max_width = wrap_width;
ui.fonts(|f| f.layout_job(layout_job))
ctx.fonts(|f| f.layout_job(layout_job))
}
Self::LayoutJob(mut job) => {
job.wrap.max_width = wrap_width;
ui.fonts(|f| f.layout_job(job))
ctx.fonts(|f| f.layout_job(job))
}
Self::Galley(galley) => galley,
}
Expand Down

0 comments on commit eb1b266

Please sign in to comment.