Skip to content

Commit

Permalink
Make pixel fonts always pixel perfect
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 30, 2023
1 parent 555daba commit 3e9ba5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions assets/config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
border_width: VMin(1.0),
text_color: Rgba(red: 0.149, green: 0.149, blue: 0.149, alpha: 1.000),
hyperlink_text_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
font_size: Vw(1.8),
font_size: Vw(2.0),

title_background_color: Rgba(red: 0.549, green: 0.647, blue: 0.796, alpha: 1.000),
title_font_size: Vw(4.5),
Expand Down Expand Up @@ -170,7 +170,7 @@
border_width: VMin(0.9),
text_color: Rgba(red: 0.737, green: 0.737, blue: 0.737, alpha: 1.000),
hyperlink_text_color: Rgba(red: 0.435, green: 0.624, blue: 1.000, alpha: 1.000),
font_size: Vw(2.0),
font_size: Vw(2.3),

title_text_color: Rgba(red: 0.737, green: 0.737, blue: 0.737, alpha: 1.000),
title_font_size: Vw(5.0),
Expand Down
2 changes: 2 additions & 0 deletions src/ui/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ pub fn scale_font_size(
};
let viewport_size = Vec2::new(window.resolution.width(), window.resolution.height());

const STEP: f32 = 8.0;
for (mut font_size, node, mut text) in &mut font_size_query {
let Ok(resolved) = font_size.size.resolve(node.size().x, viewport_size) else {
continue;
};
let resolved = (resolved / STEP).floor().max(1.0) * STEP;
if font_size.cache == resolved {
continue;
}
Expand Down

0 comments on commit 3e9ba5e

Please sign in to comment.