Skip to content

Commit

Permalink
Refactored code for dpi calculation so that default just works. Fixed…
Browse files Browse the repository at this point in the history
… clippy complaint.
  • Loading branch information
ArjunNair committed Oct 22, 2023
1 parent bae898e commit 44bf8c5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::Checkbox;
use egui_backend::egui::FullOutput;
use egui_backend::sdl2::video::GLProfile;
use egui_backend::{egui, gl, sdl2};
use egui_backend::egui::FullOutput;
use egui_backend::{sdl2::event::Event, DpiScaling, ShaderVersion};
use std::time::Instant;
// Alias the backend to something less mouthful
Expand Down Expand Up @@ -40,7 +40,7 @@ fn main() {
// On linux use GLES SL 100+, like so:
// let shader_ver = ShaderVersion::Adaptive;
let (mut painter, mut egui_state) =
egui_backend::with_sdl2(&window, shader_ver, DpiScaling::Custom(2.0));
egui_backend::with_sdl2(&window, shader_ver, DpiScaling::Default);
let egui_ctx = egui::Context::default();
let mut event_pump = sdl_context.event_pump().unwrap();

Expand All @@ -65,7 +65,7 @@ fn main() {
.gl_set_swap_interval(SwapInterval::Immediate)
.unwrap()
}

unsafe {
// Clear the screen to green
gl::ClearColor(0.3, 0.6, 0.3, 1.0);
Expand Down
4 changes: 2 additions & 2 deletions examples/demo_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() {

// Init egui stuff
let (mut painter, mut egui_state) =
egui_backend::with_sdl2(&window, ShaderVersion::Default, DpiScaling::Custom(1.25));
egui_backend::with_sdl2(&window, ShaderVersion::Default, DpiScaling::Default);
let mut demo_windows = egui_demo_lib::DemoWindows::default();
let egui_ctx = egui::Context::default();
let mut event_pump = sdl_context.event_pump().unwrap();
Expand All @@ -81,7 +81,7 @@ fn main() {
});

demo_windows.ui(&egui_ctx);

let FullOutput {
platform_output,
repaint_after,
Expand Down
19 changes: 13 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ pub fn with_sdl2(
shader_ver: ShaderVersion,
scale: DpiScaling,
) -> (Painter, EguiStateHandler) {
let display_dpi = window
.subsystem()
.display_dpi(0)
.unwrap_or((96.0, 96.0, 96.0));
let standard_dpi = 96.0;
let display_dpi =
window
.subsystem()
.display_dpi(0)
.unwrap_or((standard_dpi, standard_dpi, standard_dpi));
let dpi_scale = standard_dpi / display_dpi.0;
let normalized_scale = 1.0 / dpi_scale;
let default_scale = dpi_scale * normalized_scale;
println!("Display DPI detected: {:?}", display_dpi);
let scale = match scale {
DpiScaling::Default => 96.0 / display_dpi.0,
DpiScaling::Custom(custom) => (96.0 / display_dpi.0) * custom,
DpiScaling::Default => default_scale,
DpiScaling::Custom(custom) => default_scale * custom,
};
println!("Scaling display to {}", scale);
let painter = painter::Painter::new(window, scale, shader_ver);
EguiStateHandler::new(painter)
}
Expand Down
5 changes: 3 additions & 2 deletions src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,9 @@ impl Painter {
{
match primitive {
Primitive::Mesh(mesh) => {
if let Some(Texture { gl_id, .. }) = self.textures.get(&mesh.texture_id) {
if let Some(texture_gl_id) = gl_id {
if let Some(Texture {gl_id: Some(texture_gl_id), .. }) = self.textures.get(&mesh.texture_id) {
//if let Some(texture_gl_id) = gl_id
{
gl::BindTexture(gl::TEXTURE_2D, *texture_gl_id);

let clip_min_x = pixels_per_point * clip_rect.min.x;
Expand Down

0 comments on commit 44bf8c5

Please sign in to comment.