From 861e3e98034039f8c643e1f9125b72ad99560754 Mon Sep 17 00:00:00 2001 From: Bu5hm4nn <“bu5hm4nn@users.noreply.github.com”> Date: Tue, 7 Mar 2023 22:41:42 -0600 Subject: [PATCH] Fix issue #2578 - `row_start_x` tracks a virtual position in the source paragraph (the one that is too long) for which length has already been processed. When creating an empty row, this position should not be updated as no glyphs were consumed from the source paragraph. - added example that would demonstrate the problem if the line was included, and that is fixed with this commit --- crates/epaint/src/text/text_layout.rs | 1 - examples/wrapping-layout/Cargo.toml | 12 +++++++++ examples/wrapping-layout/src/main.rs | 35 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 examples/wrapping-layout/Cargo.toml create mode 100644 examples/wrapping-layout/src/main.rs diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index bbf677d1795..728afdb6c33 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -216,7 +216,6 @@ fn line_break( rect: rect_from_x_range(first_row_indentation..=first_row_indentation), ends_with_newline: false, }); - row_start_x += first_row_indentation; first_row_indentation = 0.0; } else if let Some(last_kept_index) = row_break_candidates.get(job.wrap.break_anywhere) { diff --git a/examples/wrapping-layout/Cargo.toml b/examples/wrapping-layout/Cargo.toml new file mode 100644 index 00000000000..072000d8989 --- /dev/null +++ b/examples/wrapping-layout/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "wrapping-layout" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +eframe = { path = "../../crates/eframe", features = [ + "__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO +] } +tracing-subscriber = "0.3" diff --git a/examples/wrapping-layout/src/main.rs b/examples/wrapping-layout/src/main.rs new file mode 100644 index 00000000000..c63cd41123f --- /dev/null +++ b/examples/wrapping-layout/src/main.rs @@ -0,0 +1,35 @@ +use eframe::{ + egui::{self, TextFormat}, + epaint::text::LayoutJob, +}; + +fn main() -> Result<(), eframe::Error> { + let native_options = eframe::NativeOptions::default(); + eframe::run_native( + "My egui App", + native_options, + Box::new(|cc| Box::new(MyEguiApp::new(cc))), + ) +} + +#[derive(Default)] +struct MyEguiApp {} + +impl MyEguiApp { + fn new(_cc: &eframe::CreationContext<'_>) -> Self { + Self::default() + } +} + +impl eframe::App for MyEguiApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| { + ui.horizontal_wrapped(|ui| { + ui.hyperlink_to("@npub1vdaeclr2mnntmyw...", "whocares"); + let text = " lnbc10u1p3lz4dppp5dsj2mh5kgqfqqxwhkrkw60stn8aph4gm2h2053xvwvvlvjm3q9eqdpqxycrqvpqd3hhgar9wfujqarfvd4k2arncqzpgxqzz6sp5vfenc5l4uafsky0w069zs329edf608ggpjjveguwxfl3xlswg5vq9qyyssqj46d5x3gsnljffm79eqwszk4mk47lkxywdp8mxum7un3qm0ztwj9jf46cm4lw2un9hk4gttgtjdrk29h27xu4e3ume20sqsna8q7xwspqqkwq7"; + let job = LayoutJob::single_section(text.to_owned(), TextFormat::default()); + ui.label(job); + }); + }); + } +}