diff --git a/egui/src/experimental/easy_mark_viewer.rs b/egui/src/experimental/easy_mark_viewer.rs index dbc6c3561..d222a641b 100644 --- a/egui/src/experimental/easy_mark_viewer.rs +++ b/egui/src/experimental/easy_mark_viewer.rs @@ -8,7 +8,9 @@ pub fn easy_mark(ui: &mut Ui, easy_mark: &str) { pub fn easy_mark_it<'em>(ui: &mut Ui, items: impl Iterator>) { ui.horizontal_wrapped(|ui| { - ui.spacing_mut().item_spacing = Vec2::ZERO; + ui.spacing_mut().item_spacing = Vec2::new(0.0, 0.0); + ui.set_row_height(ui.fonts()[TextStyle::Body].row_height()); + for item in items { item_ui(ui, item); } @@ -24,6 +26,7 @@ pub fn item_ui(ui: &mut Ui, item: easy_mark::Item<'_>) { // ui.label("\n"); // too much spacing (paragraph spacing) ui.allocate_exact_size(vec2(0.0, row_height), Sense::hover()); // make sure we take up some height ui.end_row(); + ui.set_row_height(row_height); } easy_mark::Item::Text(style, text) => { diff --git a/egui/src/layout.rs b/egui/src/layout.rs index b6a276c48..73ae69e7f 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -698,6 +698,13 @@ impl Layout { } } } + + /// Set row height in horizontal wrapping layout. + pub(crate) fn set_row_height(&mut self, region: &mut Region, height: f32) { + if self.main_wrap && self.is_horizontal() { + region.cursor.max.y = region.cursor.min.y + height; + } + } } // ---------------------------------------------------------------------------- diff --git a/egui/src/placer.rs b/egui/src/placer.rs index 2500572d1..f9dd424d2 100644 --- a/egui/src/placer.rs +++ b/egui/src/placer.rs @@ -177,6 +177,11 @@ impl Placer { self.layout.end_row(&mut self.region, item_spacing) } } + + /// Set row height in horizontal wrapping layout. + pub(crate) fn set_row_height(&mut self, height: f32) { + self.layout.set_row_height(&mut self.region, height); + } } impl Placer { diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 96afd6601..3914df3ed 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -1386,6 +1386,11 @@ impl Ui { .end_row(self.spacing().item_spacing, &self.painter().clone()); } + /// Set row height in horizontal wrapping layout. + pub fn set_row_height(&mut self, height: f32) { + self.placer.set_row_height(height); + } + /// Temporarily split split an Ui into several columns. /// /// ``` diff --git a/egui_demo_lib/src/apps/http_app.rs b/egui_demo_lib/src/apps/http_app.rs index 208c9702d..455da8af8 100644 --- a/egui_demo_lib/src/apps/http_app.rs +++ b/egui_demo_lib/src/apps/http_app.rs @@ -238,8 +238,10 @@ impl ColoredText { pub fn ui(&self, ui: &mut egui::Ui) { for line in &self.0 { - ui.horizontal_wrapped_for_text(egui::TextStyle::Monospace, |ui| { - ui.spacing_mut().item_spacing.x = 0.0; + ui.horizontal_wrapped(|ui| { + ui.spacing_mut().item_spacing = egui::Vec2::ZERO; + ui.set_row_height(ui.fonts()[egui::TextStyle::Body].row_height()); + for (style, range) in line { let fg = style.foreground; let text_color = egui::Color32::from_rgb(fg.r, fg.g, fg.b);