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

1
Cargo.lock generated
View file

@ -844,6 +844,7 @@ dependencies = [
"copypasta", "copypasta",
"egui", "egui",
"epi", "epi",
"serde",
"tts", "tts",
"webbrowser", "webbrowser",
"winit", "winit",

View file

@ -26,6 +26,7 @@ epi = { version = "0.14.0", path = "../epi" }
winit = "0.25" winit = "0.25"
copypasta = { version = "0.7", optional = true } copypasta = { version = "0.7", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
webbrowser = { version = "0.5", optional = true } webbrowser = { version = "0.5", optional = true }
# feature screen_reader # feature screen_reader
@ -43,3 +44,5 @@ links = ["webbrowser"]
# experimental support for a screen reader # experimental support for a screen reader
screen_reader = ["tts"] screen_reader = ["tts"]
serialize = ["egui/serialize", "serde"]

View file

@ -76,6 +76,9 @@ pub use winit;
pub mod clipboard; pub mod clipboard;
pub mod screen_reader; pub mod screen_reader;
mod window_settings;
pub use window_settings::WindowSettings;
pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 { pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 {
window.scale_factor() as f32 window.scale_factor() as f32

View file

@ -1,7 +1,6 @@
use egui_winit::winit; /// Can be used to store window settings (position and size).
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
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>,
@ -10,23 +9,11 @@ pub struct WindowSettings {
} }
impl WindowSettings { impl WindowSettings {
#[cfg(feature = "persistence")] pub fn from_display(window: &winit::window::Window) -> Self {
pub fn from_ron_file(settings_ron_path: impl AsRef<std::path::Path>) -> Option<WindowSettings> { let inner_size_points = window.inner_size().to_logical::<f32>(window.scale_factor());
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 { Self {
pos: display pos: window
.gl_window()
.window()
.outer_position() .outer_position()
.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)),

View file

@ -54,6 +54,7 @@ links = ["egui-winit/links"]
persistence = [ persistence = [
"directories-next", "directories-next",
"egui-winit/serialize",
"egui/persistence", "egui/persistence",
"epi/persistence", "epi/persistence",
"ron", "ron",

View file

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

View file

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