1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Make all lines and rectangles crisp (#5518)

* Merge this first: https://github.com/emilk/egui/pull/5517

This aligns all rectangles and (horizontal or vertical) line segments to
the physical pixel grid in the `epaint::Tessellator`, making these
shapes appear crisp everywhere.

* Closes https://github.com/emilk/egui/issues/5164
* Closes https://github.com/emilk/egui/issues/3667

This undoes a lot of the explicit, egui-side aligning added in:
* https://github.com/emilk/egui/pull/4943

The new approach has several benefits over the old one:

* It is done automatically by epaint, so it is applied to everything (no
longer opt-in)
* It is applied after any layer transforms (so it always works)
* It makes line segments crisper on high-DPI screens
* All filled rectangles now has sides that end on pixel boundaries
This commit is contained in:
Emil Ernerfeldt
2024-12-26 21:02:27 +01:00
committed by GitHub
parent dfcc679d5a
commit d20f93e9bf
55 changed files with 314 additions and 251 deletions

View File

@@ -1,9 +1,9 @@
use std::collections::HashMap;
use egui::{
epaint, lerp, pos2, vec2, widgets::color_picker::show_color, Align2, Color32, FontId, Image,
Mesh, Pos2, Rect, Response, Rgba, RichText, Sense, Shape, Stroke, TextureHandle,
TextureOptions, Ui, Vec2,
emath::GuiRounding, epaint, lerp, pos2, vec2, widgets::color_picker::show_color, Align2,
Color32, FontId, Image, Mesh, Pos2, Rect, Response, Rgba, RichText, Sense, Shape, Stroke,
TextureHandle, TextureOptions, Ui, Vec2,
};
const GRADIENT_SIZE: Vec2 = vec2(256.0, 18.0);
@@ -270,6 +270,7 @@ impl ColorTest {
fn vertex_gradient(ui: &mut Ui, bg_fill: Color32, gradient: &Gradient) -> Response {
let (rect, response) = ui.allocate_at_least(GRADIENT_SIZE, Sense::hover());
let rect = rect.round_to_pixels(ui.pixels_per_point());
if bg_fill != Default::default() {
let mut mesh = Mesh::default();
mesh.add_colored_rect(rect, bg_fill);