mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Round font row heights
This commit is contained in:
@@ -470,7 +470,7 @@ impl<'open> Window<'open> {
|
||||
let (title_bar_height, title_content_spacing) = if with_title_bar {
|
||||
let style = ctx.style();
|
||||
let spacing = window_margin.top + window_margin.bottom;
|
||||
let height = ctx.fonts(|f| title.font_height(f, &style)) + spacing;
|
||||
let height = ctx.fonts(|f| title.font_height(f, &style)).round() + spacing;
|
||||
window_frame.rounding.ne = window_frame.rounding.ne.clamp(0.0, height / 2.0);
|
||||
window_frame.rounding.nw = window_frame.rounding.nw.clamp(0.0, height / 2.0);
|
||||
(height, spacing)
|
||||
|
||||
@@ -708,6 +708,7 @@ impl Ui {
|
||||
/// The height of text of this text style
|
||||
pub fn text_style_height(&self, style: &TextStyle) -> f32 {
|
||||
self.fonts(|f| f.row_height(&style.resolve(self.style())))
|
||||
.round()
|
||||
}
|
||||
|
||||
/// Screen-space rectangle for clipping what we paint in this ui.
|
||||
|
||||
@@ -269,7 +269,7 @@ impl RichText {
|
||||
if let Some(family) = &self.family {
|
||||
font_id.family = family.clone();
|
||||
}
|
||||
fonts.row_height(&font_id)
|
||||
fonts.row_height(&font_id).round()
|
||||
}
|
||||
|
||||
/// Append to an existing [`LayoutJob`]
|
||||
|
||||
@@ -204,7 +204,9 @@ impl Widget for Button<'_> {
|
||||
}
|
||||
|
||||
let space_available_for_image = if let Some(text) = &text {
|
||||
let font_height = ui.fonts(|fonts| text.font_height(fonts, ui.style()));
|
||||
let font_height = ui
|
||||
.fonts(|fonts| text.font_height(fonts, ui.style()))
|
||||
.round();
|
||||
Vec2::splat(font_height) // Reasonable?
|
||||
} else {
|
||||
ui.available_size() - 2.0 * button_padding
|
||||
|
||||
@@ -487,7 +487,7 @@ impl<'t> TextEdit<'t> {
|
||||
let prev_text = text.as_str().to_owned();
|
||||
|
||||
let font_id = font_selection.resolve(ui.style());
|
||||
let row_height = ui.fonts(|f| f.row_height(&font_id));
|
||||
let row_height = ui.fonts(|f| f.row_height(&font_id)).round();
|
||||
const MIN_WIDTH: f32 = 24.0; // Never make a [`TextEdit`] more narrow than this.
|
||||
let available_width = (ui.available_width() - margin.sum().x).at_least(MIN_WIDTH);
|
||||
let desired_width = desired_width.unwrap_or_else(|| ui.spacing().text_edit_width);
|
||||
|
||||
@@ -191,7 +191,7 @@ fn huge_content_painter(ui: &mut egui::Ui) {
|
||||
ui.add_space(4.0);
|
||||
|
||||
let font_id = TextStyle::Body.resolve(ui.style());
|
||||
let row_height = ui.fonts(|f| f.row_height(&font_id)) + ui.spacing().item_spacing.y;
|
||||
let row_height = ui.fonts(|f| f.row_height(&font_id)).round() + ui.spacing().item_spacing.y;
|
||||
let num_rows = 10_000;
|
||||
|
||||
ScrollArea::vertical()
|
||||
|
||||
@@ -162,7 +162,7 @@ fn bullet_point(ui: &mut Ui, width: f32) -> Response {
|
||||
|
||||
fn numbered_point(ui: &mut Ui, width: f32, number: &str) -> Response {
|
||||
let font_id = TextStyle::Body.resolve(ui.style());
|
||||
let row_height = ui.fonts(|f| f.row_height(&font_id));
|
||||
let row_height = ui.fonts(|f| f.row_height(&font_id)).round();
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(width, row_height), Sense::hover());
|
||||
let text = format!("{number}.");
|
||||
let text_color = ui.visuals().strong_text_color();
|
||||
|
||||
Reference in New Issue
Block a user