mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -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 (title_bar_height, title_content_spacing) = if with_title_bar {
|
||||||
let style = ctx.style();
|
let style = ctx.style();
|
||||||
let spacing = window_margin.top + window_margin.bottom;
|
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.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);
|
window_frame.rounding.nw = window_frame.rounding.nw.clamp(0.0, height / 2.0);
|
||||||
(height, spacing)
|
(height, spacing)
|
||||||
|
|||||||
@@ -708,6 +708,7 @@ impl Ui {
|
|||||||
/// The height of text of this text style
|
/// The height of text of this text style
|
||||||
pub fn text_style_height(&self, style: &TextStyle) -> f32 {
|
pub fn text_style_height(&self, style: &TextStyle) -> f32 {
|
||||||
self.fonts(|f| f.row_height(&style.resolve(self.style())))
|
self.fonts(|f| f.row_height(&style.resolve(self.style())))
|
||||||
|
.round()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Screen-space rectangle for clipping what we paint in this ui.
|
/// Screen-space rectangle for clipping what we paint in this ui.
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ impl RichText {
|
|||||||
if let Some(family) = &self.family {
|
if let Some(family) = &self.family {
|
||||||
font_id.family = family.clone();
|
font_id.family = family.clone();
|
||||||
}
|
}
|
||||||
fonts.row_height(&font_id)
|
fonts.row_height(&font_id).round()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append to an existing [`LayoutJob`]
|
/// Append to an existing [`LayoutJob`]
|
||||||
|
|||||||
@@ -204,7 +204,9 @@ impl Widget for Button<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let space_available_for_image = if let Some(text) = &text {
|
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?
|
Vec2::splat(font_height) // Reasonable?
|
||||||
} else {
|
} else {
|
||||||
ui.available_size() - 2.0 * button_padding
|
ui.available_size() - 2.0 * button_padding
|
||||||
|
|||||||
@@ -487,7 +487,7 @@ impl<'t> TextEdit<'t> {
|
|||||||
let prev_text = text.as_str().to_owned();
|
let prev_text = text.as_str().to_owned();
|
||||||
|
|
||||||
let font_id = font_selection.resolve(ui.style());
|
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.
|
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 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);
|
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);
|
ui.add_space(4.0);
|
||||||
|
|
||||||
let font_id = TextStyle::Body.resolve(ui.style());
|
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;
|
let num_rows = 10_000;
|
||||||
|
|
||||||
ScrollArea::vertical()
|
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 {
|
fn numbered_point(ui: &mut Ui, width: f32, number: &str) -> Response {
|
||||||
let font_id = TextStyle::Body.resolve(ui.style());
|
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 (rect, response) = ui.allocate_exact_size(vec2(width, row_height), Sense::hover());
|
||||||
let text = format!("{number}.");
|
let text = format!("{number}.");
|
||||||
let text_color = ui.visuals().strong_text_color();
|
let text_color = ui.visuals().strong_text_color();
|
||||||
|
|||||||
Reference in New Issue
Block a user