Add epi::App::initial_window_size to control initial native window size
This commit is contained in:
parent
049a7b0382
commit
02a65132e4
4 changed files with 22 additions and 3 deletions
|
@ -57,6 +57,7 @@ impl epi::RepaintSignal for GliumRepaintSignal {
|
||||||
|
|
||||||
fn create_display(
|
fn create_display(
|
||||||
title: &str,
|
title: &str,
|
||||||
|
initial_size_points: Option<Vec2>,
|
||||||
window_settings: Option<WindowSettings>,
|
window_settings: Option<WindowSettings>,
|
||||||
is_resizable: bool,
|
is_resizable: bool,
|
||||||
event_loop: &glutin::event_loop::EventLoop<RequestRepaintEvent>,
|
event_loop: &glutin::event_loop::EventLoop<RequestRepaintEvent>,
|
||||||
|
@ -69,6 +70,11 @@ fn create_display(
|
||||||
|
|
||||||
if let Some(window_settings) = &window_settings {
|
if let Some(window_settings) = &window_settings {
|
||||||
window_builder = window_settings.initialize_size(window_builder);
|
window_builder = window_settings.initialize_size(window_builder);
|
||||||
|
} else if let Some(initial_size_points) = initial_size_points {
|
||||||
|
window_builder = window_builder.with_inner_size(glutin::dpi::LogicalSize {
|
||||||
|
width: initial_size_points.x as f64,
|
||||||
|
height: initial_size_points.y as f64,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let context_builder = glutin::ContextBuilder::new()
|
let context_builder = glutin::ContextBuilder::new()
|
||||||
|
@ -135,7 +141,13 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {
|
||||||
|
|
||||||
let window_settings = deserialize_window_settings(&storage);
|
let window_settings = deserialize_window_settings(&storage);
|
||||||
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
||||||
let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop);
|
let display = create_display(
|
||||||
|
app.name(),
|
||||||
|
app.initial_window_size(),
|
||||||
|
window_settings,
|
||||||
|
app.is_resizable(),
|
||||||
|
&event_loop,
|
||||||
|
);
|
||||||
|
|
||||||
let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(std::sync::Mutex::new(
|
let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(std::sync::Mutex::new(
|
||||||
event_loop.create_proxy(),
|
event_loop.create_proxy(),
|
||||||
|
|
|
@ -38,6 +38,7 @@ impl epi::Storage for FileStorage {
|
||||||
|
|
||||||
fn flush(&mut self) {
|
fn flush(&mut self) {
|
||||||
if self.dirty {
|
if self.dirty {
|
||||||
|
// eprintln!("Persisted to {}", self.path.display());
|
||||||
serde_json::to_writer(std::fs::File::create(&self.path).unwrap(), &self.kv).unwrap();
|
serde_json::to_writer(std::fs::File::create(&self.path).unwrap(), &self.kv).unwrap();
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
}
|
}
|
||||||
|
@ -46,11 +47,11 @@ impl epi::Storage for FileStorage {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn read_json<T>(memory_json_path: impl AsRef<Path>) -> Option<T>
|
pub fn read_json<T>(json_path: impl AsRef<Path>) -> Option<T>
|
||||||
where
|
where
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
match std::fs::File::open(memory_json_path) {
|
match std::fs::File::open(json_path) {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let reader = std::io::BufReader::new(file);
|
let reader = std::io::BufReader::new(file);
|
||||||
match serde_json::from_reader(reader) {
|
match serde_json::from_reader(reader) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
* You can control the initial size of the native window with `App::initial_window_size`.
|
||||||
* You can control the maximum egui web canvas size with `App::max_size_points`.
|
* You can control the maximum egui web canvas size with `App::max_size_points`.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,11 @@ pub trait App {
|
||||||
/// The name of your App.
|
/// The name of your App.
|
||||||
fn name(&self) -> &str;
|
fn name(&self) -> &str;
|
||||||
|
|
||||||
|
/// The initial size of the native window in points (logical pixels).
|
||||||
|
fn initial_window_size(&self) -> Option<egui::Vec2> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Time between automatic calls to `save()`
|
/// Time between automatic calls to `save()`
|
||||||
fn auto_save_interval(&self) -> std::time::Duration {
|
fn auto_save_interval(&self) -> std::time::Duration {
|
||||||
std::time::Duration::from_secs(30)
|
std::time::Duration::from_secs(30)
|
||||||
|
|
Loading…
Reference in a new issue