Answer#
egui lays out in points. The number of physical pixels per point comes from the monitor's scale factor, and egui exposes it as pixels_per_point. egui also has a separate zoom factor that multiplies it, which is the right tool for an "enlarge the interface" setting.
use eframe::egui;
struct App;
impl eframe::App for App {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
let ppp = ui.ctx().pixels_per_point(); // physical pixels per egui point on this monitor
egui::CentralPanel::default().show(ui, |ui| {
ui.label(format!("pixels_per_point = {ppp}"));
ui.label(format!("zoom factor = {}", ui.ctx().zoom_factor()));
if ui.button("Zoom in").clicked() {
let z = ui.ctx().zoom_factor();
ui.ctx().set_zoom_factor(z * 1.1); // the user's own scaling, on top of the monitor's
}
});
}
}
fn main() -> eframe::Result {
eframe::run_native("Scale", eframe::NativeOptions::default(), Box::new(|_cc| Ok(Box::new(App))))
}This compiled with cargo check using eframe 0.35.0. It was not run, so no values are shown; they depend on your screen.
Practical notes:
- Do not set
pixels_per_pointyourself to follow the monitor: egui and eframe take it from the window and update it when the window moves to another screen. Use the zoom factor for the user's preference. - Save the zoom factor with the other settings (see the settings threads) and apply it at startup.
- Drawing your own textures or images: compute their pixel size as
size_in_points * pixels_per_pointso they stay sharp on scaled screens. - Sizes in your code are points.
ui.add_space(8.0)is eight points on every screen.
Common mistakes#
- Multiplying every size by the scale yourself. egui already does it; you would scale twice.
- Setting a zoom on every frame instead of when the user asks.
Related questions#
Is this the same as the Windows scale setting?#
The monitor's scale comes from the operating system and is what pixels_per_point starts from. See the threads on logical and physical pixels and on blurry windows.
Sources#
- egui Context::pixels_per_point and set_zoom_factor: https://docs.rs/egui/0.35.0/egui/struct.Context.html (read 2026-12-05)