1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-28 07:23:13 -04:00

Move WindowSettings from egui_glium to egui-winit

This commit is contained in:
Emil Ernerfeldt
2021-09-30 19:18:51 +02:00
parent 7df2408482
commit e2bdd40985
7 changed files with 17 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
use crate::{window_settings::WindowSettings, *};
use crate::*;
use egui::Color32;
use egui_winit::WindowSettings;
#[cfg(target_os = "windows")]
use glium::glutin::platform::windows::WindowBuilderExtWindows;
use std::time::Instant;
@@ -309,7 +310,7 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> !
epi::set_value(
storage.as_mut(),
WINDOW_KEY,
&WindowSettings::from_display(&display),
&WindowSettings::from_display(display.gl_window().window()),
);
}
if app.persist_egui_memory() {
@@ -350,7 +351,7 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> !
epi::set_value(
storage.as_mut(),
WINDOW_KEY,
&WindowSettings::from_display(&display),
&WindowSettings::from_display(display.gl_window().window()),
);
}
if app.persist_egui_memory() {

View File

@@ -80,7 +80,6 @@ mod backend;
mod painter;
#[cfg(feature = "persistence")]
pub mod persistence;
pub mod window_settings;
pub use backend::*;
pub use painter::Painter;

View File

@@ -1,68 +0,0 @@
use egui_winit::winit;
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct WindowSettings {
/// outer position of window in physical pixels
pos: Option<egui::Pos2>,
/// Inner size of window in logical pixels
inner_size_points: Option<egui::Vec2>,
}
impl WindowSettings {
#[cfg(feature = "persistence")]
pub fn from_ron_file(settings_ron_path: impl AsRef<std::path::Path>) -> Option<WindowSettings> {
crate::persistence::read_ron(settings_ron_path)
}
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 {
pos: display
.gl_window()
.window()
.outer_position()
.ok()
.map(|p| egui::pos2(p.x as f32, p.y as f32)),
inner_size_points: Some(egui::vec2(
inner_size_points.width as f32,
inner_size_points.height as f32,
)),
}
}
pub fn initialize_window(
&self,
mut window: winit::window::WindowBuilder,
) -> winit::window::WindowBuilder {
if !cfg!(target_os = "windows") {
// If the app last ran on two monitors and only one is now connected, then
// the given position is invalid.
// If this happens on Mac, the window is clamped into valid area.
// If this happens on Windows, the window is hidden and impossible to bring to get at.
// So we don't restore window positions on Windows.
if let Some(pos) = self.pos {
window = window.with_position(winit::dpi::PhysicalPosition {
x: pos.x as f64,
y: pos.y as f64,
});
}
}
if let Some(inner_size_points) = self.inner_size_points {
window.with_inner_size(winit::dpi::LogicalSize {
width: inner_size_points.x as f64,
height: inner_size_points.y as f64,
})
} else {
window
}
}
}