[egui_glium]: Store window size in points instead of physical pixels
This commit is contained in:
parent
484e218e54
commit
f1b4353039
2 changed files with 21 additions and 9 deletions
|
@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
* `egui_glium::run`: the parameter `app` now has signature `Box<dyn App>` (you need to add `Box::new(app)` to your code).
|
* `egui_glium::run`: the parameter `app` now has signature `Box<dyn App>` (you need to add `Box::new(app)` to your code).
|
||||||
|
|
||||||
|
### Fixed 🐛
|
||||||
|
|
||||||
|
* Serialize window size in logical points instead of physical pixels
|
||||||
|
|
||||||
|
|
||||||
## 0.5.0 - 2020-12-13
|
## 0.5.0 - 2020-12-13
|
||||||
|
|
||||||
|
|
|
@ -91,11 +91,12 @@ pub fn write_memory(
|
||||||
use glium::glutin;
|
use glium::glutin;
|
||||||
|
|
||||||
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct WindowSettings {
|
pub struct WindowSettings {
|
||||||
/// outer position of window in physical pixels
|
/// outer position of window in physical pixels
|
||||||
pos: Option<egui::Pos2>,
|
pos: Option<egui::Pos2>,
|
||||||
/// inner size of window in physical pixels
|
/// Inner size of window in logical pixels
|
||||||
size: Option<egui::Vec2>,
|
inner_size_points: Option<egui::Vec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowSettings {
|
impl WindowSettings {
|
||||||
|
@ -106,6 +107,13 @@ impl WindowSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_display(display: &glium::Display) -> Self {
|
pub fn from_display(display: &glium::Display) -> Self {
|
||||||
|
let scale_factor = display.gl_window().window().scale_factor();
|
||||||
|
let inner_size_points = display
|
||||||
|
.gl_window()
|
||||||
|
.window()
|
||||||
|
.inner_size()
|
||||||
|
.to_logical::<f32>(scale_factor);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
pos: display
|
pos: display
|
||||||
.gl_window()
|
.gl_window()
|
||||||
|
@ -114,9 +122,9 @@ impl WindowSettings {
|
||||||
.ok()
|
.ok()
|
||||||
.map(|p| egui::pos2(p.x as f32, p.y as f32)),
|
.map(|p| egui::pos2(p.x as f32, p.y as f32)),
|
||||||
|
|
||||||
size: Some(egui::vec2(
|
inner_size_points: Some(egui::vec2(
|
||||||
display.gl_window().window().inner_size().width as f32,
|
inner_size_points.width as f32,
|
||||||
display.gl_window().window().inner_size().height as f32,
|
inner_size_points.height as f32,
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,10 +133,10 @@ impl WindowSettings {
|
||||||
&self,
|
&self,
|
||||||
window: glutin::window::WindowBuilder,
|
window: glutin::window::WindowBuilder,
|
||||||
) -> glutin::window::WindowBuilder {
|
) -> glutin::window::WindowBuilder {
|
||||||
if let Some(size) = self.size {
|
if let Some(inner_size_points) = self.inner_size_points {
|
||||||
window.with_inner_size(glutin::dpi::PhysicalSize {
|
window.with_inner_size(glutin::dpi::LogicalSize {
|
||||||
width: size.x as f64,
|
width: inner_size_points.x as f64,
|
||||||
height: size.y as f64,
|
height: inner_size_points.y as f64,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
window
|
window
|
||||||
|
|
Loading…
Reference in a new issue