diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index faa65b49e..953cd4b9a 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -419,6 +419,9 @@ pub struct Spacing { /// Default width of a [`crate::TextEdit`]. pub text_edit_width: f32, + /// Additional vertical spacing between lines of text. + pub extra_text_line_spacing: f32, + /// Checkboxes, radio button and collapsing headers have an icon at the start. /// This is the width/height of the outer part of this icon (e.g. the BOX of the checkbox). pub icon_width: f32, @@ -1458,6 +1461,7 @@ impl Default for Spacing { slider_rail_height: 8.0, combo_width: 100.0, text_edit_width: 280.0, + extra_text_line_spacing: 0.0, icon_width: 14.0, icon_width_inner: 8.0, icon_spacing: 4.0, @@ -1948,6 +1952,7 @@ impl Spacing { slider_rail_height, combo_width, text_edit_width, + extra_text_line_spacing, icon_width, icon_width_inner, icon_spacing, @@ -2014,6 +2019,10 @@ impl Spacing { ui.add(DragValue::new(text_edit_width).range(0.0..=1000.0)); ui.end_row(); + ui.label("Extra text line spacing"); + ui.add(DragValue::new(extra_text_line_spacing).range(0.0..=20.0)); + ui.end_row(); + ui.label("Tooltip wrap width"); ui.add(DragValue::new(tooltip_width).range(0.0..=1000.0)); ui.end_row(); diff --git a/crates/egui/src/widget_text.rs b/crates/egui/src/widget_text.rs index 37018c0b2..c8e803cbc 100644 --- a/crates/egui/src/widget_text.rs +++ b/crates/egui/src/widget_text.rs @@ -769,14 +769,19 @@ impl WidgetText { .visuals .override_text_color .unwrap_or(crate::Color32::PLACEHOLDER); + + // We want the style overrides to take precedence over the fallback font + let font_id = FontSelection::default().resolve_with_fallback(style, fallback_font); + let line_height = ctx + .fonts_mut(|f| f.row_height(&font_id) + style.spacing.extra_text_line_spacing); + let mut layout_job = LayoutJob::simple_format( text, TextFormat { - // We want the style overrides to take precedence over the fallback font - font_id: FontSelection::default() - .resolve_with_fallback(style, fallback_font), + font_id, color, valign: default_valign, + line_height: Some(line_height), ..Default::default() }, ); diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index aa4f18d8a..96bd3ca01 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -471,6 +471,8 @@ impl TextEdit<'_> { let font_id = font_selection.resolve(ui.style()); let row_height = ui.fonts_mut(|f| f.row_height(&font_id)); + let line_height = row_height + ui.spacing().extra_text_line_spacing; + const MIN_WIDTH: f32 = 24.0; // Never make a [`TextEdit`] more narrow than this. let available_width = ui.available_width().at_least(MIN_WIDTH); let desired_width = desired_width @@ -489,12 +491,17 @@ impl TextEdit<'_> { layout_job.halign = align.x(); // We want to keep the trailing whitespace, since hiding it feels really weird when typing layout_job.keep_trailing_whitespace = true; + + for section in &mut layout_job.sections { + section.format.line_height = Some(line_height); + } + ui.fonts_mut(|f| f.layout_job(layout_job)) }; let layouter = layouter.unwrap_or(&mut default_layouter); - let min_inner_height = (desired_height_rows.at_least(1) as f32) * row_height; + let min_inner_height = (desired_height_rows.at_least(1) as f32) * line_height; let id = id.unwrap_or_else(|| { if let Some(id_salt) = id_salt {