mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Respect LayoutJob::round_output_size_to_nearest_ui_point
This commit is contained in:
@@ -841,6 +841,13 @@ impl GalleyCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if merged_galley.job.round_output_size_to_nearest_ui_point {
|
||||||
|
super::round_output_size_to_nearest_ui_point(
|
||||||
|
&mut merged_galley.rect,
|
||||||
|
&merged_galley.job,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
merged_galley
|
merged_galley
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ pub use {
|
|||||||
FontData, FontDefinitions, FontFamily, FontId, FontInsert, FontPriority, FontTweak, Fonts,
|
FontData, FontDefinitions, FontFamily, FontId, FontInsert, FontPriority, FontTweak, Fonts,
|
||||||
FontsImpl, InsertFontFamily,
|
FontsImpl, InsertFontFamily,
|
||||||
},
|
},
|
||||||
text_layout::layout,
|
text_layout::*,
|
||||||
text_layout_types::*,
|
text_layout_types::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -679,20 +679,7 @@ fn galley_from_rows(
|
|||||||
let mut rect = Rect::from_min_max(pos2(min_x, 0.0), pos2(max_x, cursor_y));
|
let mut rect = Rect::from_min_max(pos2(min_x, 0.0), pos2(max_x, cursor_y));
|
||||||
|
|
||||||
if job.round_output_size_to_nearest_ui_point {
|
if job.round_output_size_to_nearest_ui_point {
|
||||||
let did_exceed_wrap_width_by_a_lot = rect.width() > job.wrap.max_width + 1.0;
|
round_output_size_to_nearest_ui_point(&mut rect, &job);
|
||||||
|
|
||||||
// We round the size to whole ui points here (not pixels!) so that the egui layout code
|
|
||||||
// can have the advantage of working in integer units, avoiding rounding errors.
|
|
||||||
rect.min = rect.min.round();
|
|
||||||
rect.max = rect.max.round();
|
|
||||||
|
|
||||||
if did_exceed_wrap_width_by_a_lot {
|
|
||||||
// If the user picked a too aggressive wrap width (e.g. more narrow than any individual glyph),
|
|
||||||
// we should let the user know by reporting that our width is wider than the wrap width.
|
|
||||||
} else {
|
|
||||||
// Make sure we don't report being wider than the wrap width the user picked:
|
|
||||||
rect.max.x = rect.max.x.at_most(rect.min.x + job.wrap.max_width).floor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Galley {
|
Galley {
|
||||||
@@ -707,6 +694,23 @@ fn galley_from_rows(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn round_output_size_to_nearest_ui_point(rect: &mut Rect, job: &LayoutJob) {
|
||||||
|
let did_exceed_wrap_width_by_a_lot = rect.width() > job.wrap.max_width + 1.0;
|
||||||
|
|
||||||
|
// We round the size to whole ui points here (not pixels!) so that the egui layout code
|
||||||
|
// can have the advantage of working in integer units, avoiding rounding errors.
|
||||||
|
rect.min = rect.min.round();
|
||||||
|
rect.max = rect.max.round();
|
||||||
|
|
||||||
|
if did_exceed_wrap_width_by_a_lot {
|
||||||
|
// If the user picked a too aggressive wrap width (e.g. more narrow than any individual glyph),
|
||||||
|
// we should let the user know by reporting that our width is wider than the wrap width.
|
||||||
|
} else {
|
||||||
|
// Make sure we don't report being wider than the wrap width the user picked:
|
||||||
|
rect.max.x = rect.max.x.at_most(rect.min.x + job.wrap.max_width).floor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct FormatSummary {
|
struct FormatSummary {
|
||||||
any_background: bool,
|
any_background: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user