[epaint] Add more text wrapping options (#1291)

This commit is contained in:
awaken1ng
2022-04-03 20:28:47 +02:00
committed by GitHub
parent d09fa63d9c
commit 901b7c7994
11 changed files with 256 additions and 57 deletions
+2 -2
View File
@@ -563,14 +563,14 @@ impl WidgetText {
Self::RichText(text) => {
let valign = ui.layout().vertical_align();
let mut text_job = text.into_text_job(ui.style(), fallback_font.into(), valign);
text_job.job.wrap_width = wrap_width;
text_job.job.wrap.max_width = wrap_width;
WidgetTextGalley {
galley: ui.fonts().layout_job(text_job.job),
galley_has_color: text_job.job_has_color,
}
}
Self::LayoutJob(mut job) => {
job.wrap_width = wrap_width;
job.wrap.max_width = wrap_width;
WidgetTextGalley {
galley: ui.fonts().layout_job(job),
galley_has_color: true,
+3 -3
View File
@@ -103,7 +103,7 @@ impl Label {
let first_row_indentation = available_width - ui.available_size_before_wrap().x;
egui_assert!(first_row_indentation.is_finite());
text_job.job.wrap_width = available_width;
text_job.job.wrap.max_width = available_width;
text_job.job.first_row_min_height = cursor.height();
text_job.job.halign = Align::Min;
text_job.job.justify = false;
@@ -129,9 +129,9 @@ impl Label {
(pos, text_galley, response)
} else {
if should_wrap {
text_job.job.wrap_width = available_width;
text_job.job.wrap.max_width = available_width;
} else {
text_job.job.wrap_width = f32::INFINITY;
text_job.job.wrap.max_width = f32::INFINITY;
};
if ui.is_grid() {
+1 -1
View File
@@ -182,7 +182,7 @@ impl<'t> TextEdit<'t> {
/// # fn my_memoized_highlighter(s: &str) -> egui::text::LayoutJob { Default::default() }
/// let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
/// let mut layout_job: egui::text::LayoutJob = my_memoized_highlighter(string);
/// layout_job.wrap_width = wrap_width;
/// layout_job.wrap.max_width = wrap_width;
/// ui.fonts().layout_job(layout_job)
/// };
/// ui.add(egui::TextEdit::multiline(&mut my_code).layouter(&mut layouter));