gui: fonts, navbar height
This commit is contained in:
parent
08838b830a
commit
77079e51ce
8 changed files with 847 additions and 613 deletions
997
Cargo.lock
generated
997
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
29
Cargo.toml
29
Cargo.toml
|
@ -13,14 +13,14 @@ build = "src/build/build.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
#android-activity = { version = "0.4", features = ["game-activity"] }
|
#android-activity = { version = "0.4", features = ["game-activity"] }
|
||||||
grin_api = "5.1.2"
|
#grin_api = "5.1.2"
|
||||||
grin_chain = "5.1.2"
|
#grin_chain = "5.1.2"
|
||||||
grin_config = "5.1.2"
|
grin_config = "5.1.2"
|
||||||
grin_core = "5.1.2"
|
grin_core = "5.1.2"
|
||||||
grin_keychain = "5.1.2"
|
#grin_keychain = "5.1.2"
|
||||||
grin_p2p = "5.1.2"
|
#grin_p2p = "5.1.2"
|
||||||
grin_servers = "5.1.2"
|
grin_servers = "5.1.2"
|
||||||
grin_store = "5.1.2"
|
#grin_store = "5.1.2"
|
||||||
grin_util = "5.1.2"
|
grin_util = "5.1.2"
|
||||||
openssl-sys = { version = "0.9.82", features = ["vendored"] }
|
openssl-sys = { version = "0.9.82", features = ["vendored"] }
|
||||||
#grin_wallet_api = "5.1.0"
|
#grin_wallet_api = "5.1.0"
|
||||||
|
@ -29,31 +29,30 @@ openssl-sys = { version = "0.9.82", features = ["vendored"] }
|
||||||
#grin_wallet_config = "5.1.0"
|
#grin_wallet_config = "5.1.0"
|
||||||
#grin_wallet_util = "5.1.0"
|
#grin_wallet_util = "5.1.0"
|
||||||
|
|
||||||
egui = "0.21.0"
|
egui = "0.20.1"
|
||||||
egui-winit = { version = "0.21.1", features = ['default', 'bytemuck', 'android-game-activity'] }
|
|
||||||
wgpu = "0.15.1"
|
|
||||||
egui_wgpu_backend = "0.22.0"
|
|
||||||
epi = "0.17.0"
|
|
||||||
egui_winit_platform = "0.18.0"
|
|
||||||
pollster = "0.3.0"
|
pollster = "0.3.0"
|
||||||
egui_demo_lib = "0.21.0"
|
tracing-subscriber = "0.3"
|
||||||
|
egui_demo_lib = "0.20.0"
|
||||||
|
|
||||||
|
eframe = { version = "0.20.1", features = [ "wgpu" ] }
|
||||||
|
|
||||||
## grin_servers
|
## grin_servers
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
egui-winit = { path = '../egui/crates/egui-winit' }
|
winit = { git = "https://github.com/rib/winit", branch = "android-activity" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
built = { version = "0.6.0", features = ["git2"]}
|
built = { version = "0.6.0", features = ["git2"]}
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
winit = { version = "0.28.3" }
|
winit = { version = "0.27.2" }
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
android_logger = "0.13.1"
|
android_logger = "0.13.1"
|
||||||
winit = { version = "0.28.3", features = [ "android-game-activity" ] }
|
jni = "0.21.1"
|
||||||
|
winit = { version = "0.27.2", features = [ "android-game-activity" ] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name="grin_android"
|
name="grin_android"
|
||||||
|
|
|
@ -22,7 +22,10 @@ public class MainActivity extends GameActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
int navBarHeight = Utils.getNavigationBarHeight(getApplicationContext());
|
int navBarHeight = Utils.getNavigationBarHeight(getApplicationContext());
|
||||||
// int statusBarHeight = Utils.getStatusBarHeight(getApplicationContext());
|
|
||||||
findViewById(android.R.id.content).setPadding(0, 0, 0, navBarHeight);
|
findViewById(android.R.id.content).setPadding(0, 0, 0, navBarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getStatusBarHeight() {
|
||||||
|
return Utils.getStatusBarHeight(getApplicationContext());
|
||||||
|
}
|
||||||
}
|
}
|
25
src/grim.rs
25
src/grim.rs
|
@ -17,7 +17,8 @@ use log::LevelFilter::{Debug, Info, Trace, Warn};
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
use winit::platform::android::activity::AndroidApp;
|
use winit::platform::android::activity::AndroidApp;
|
||||||
|
|
||||||
use crate::gui::renderer::Event;
|
use eframe::{AppCreator, CreationContext, NativeOptions, Renderer};
|
||||||
|
use crate::gui::{MainApp};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
|
@ -32,10 +33,15 @@ fn android_main(app: AndroidApp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||||
let event_loop = winit::event_loop::EventLoopBuilder::<Event>::with_user_event()
|
let mut options = NativeOptions::default();
|
||||||
.with_android_app(app)
|
options.event_loop_builder = Some(Box::new(move |builder| {
|
||||||
.build();
|
builder.with_android_app(app);
|
||||||
crate::gui::start(event_loop);
|
}));
|
||||||
|
|
||||||
|
use crate::gui::AndroidUi;
|
||||||
|
start(options, Box::new(|_cc| Box::new(MainApp::new(_cc)
|
||||||
|
.with_status_bar_height(24.0)
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -47,8 +53,13 @@ fn main() {
|
||||||
.parse_default_env()
|
.parse_default_env()
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
let event_loop = winit::event_loop::EventLoopBuilder::<Event>::with_user_event().build();
|
let options = NativeOptions::default();
|
||||||
crate::gui::start(event_loop);
|
start(options, Box::new(|_cc| Box::new(MainApp::new(_cc))));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start(mut options: NativeOptions, app_creator: AppCreator) {
|
||||||
|
options.renderer = Renderer::Wgpu;
|
||||||
|
eframe::run_native("Grim", options, app_creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
mod built_info {
|
mod built_info {
|
||||||
|
|
66
src/gui/app.rs
Normal file
66
src/gui/app.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright 2023 The Grim Developers
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use egui::FontTweak;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct MainApp {
|
||||||
|
root: egui_demo_lib::DemoWindows,
|
||||||
|
status_bar_height: Option<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MainApp {
|
||||||
|
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
|
setup_fonts(&cc.egui_ctx);
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
impl crate::gui::AndroidUi for MainApp {
|
||||||
|
fn with_status_bar_height(mut self, value: f32) -> Self {
|
||||||
|
self.status_bar_height = Some(value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl eframe::App for MainApp {
|
||||||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
egui::TopBottomPanel::top("top_padding_panel")
|
||||||
|
.resizable(false)
|
||||||
|
.exact_height(self.status_bar_height.unwrap_or(0.0))
|
||||||
|
.show(ctx, |ui| {});
|
||||||
|
self.root.ui(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_fonts(ctx: &egui::Context) {
|
||||||
|
let mut fonts = egui::FontDefinitions::default();
|
||||||
|
fonts.font_data.insert(
|
||||||
|
"jura".to_owned(),
|
||||||
|
egui::FontData::from_static(include_bytes!(
|
||||||
|
"../../fonts/jura.ttf"
|
||||||
|
)).tweak(FontTweak {
|
||||||
|
scale: 1.0,
|
||||||
|
y_offset_factor: -0.25,
|
||||||
|
y_offset: 0.0
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.entry(egui::FontFamily::Proportional)
|
||||||
|
.or_default()
|
||||||
|
.insert(0, "jura".to_owned());
|
||||||
|
ctx.set_fonts(fonts);
|
||||||
|
}
|
|
@ -12,6 +12,12 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
pub mod renderer;
|
mod app;
|
||||||
|
pub mod root;
|
||||||
|
|
||||||
pub use self::renderer::start;
|
pub use app::MainApp;
|
||||||
|
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
pub trait AndroidUi {
|
||||||
|
fn with_status_bar_height(self, value: f32) -> Self;
|
||||||
|
}
|
|
@ -1,328 +0,0 @@
|
||||||
// Copyright 2023 The Grin Developers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
use std::iter;
|
|
||||||
use std::time::Instant;
|
|
||||||
use egui::FontDefinitions;
|
|
||||||
use egui_wgpu_backend::{RenderPass, ScreenDescriptor};
|
|
||||||
use egui_winit_platform::{Platform, PlatformDescriptor};
|
|
||||||
use log::{debug, error, trace, warn};
|
|
||||||
use wgpu::{CompositeAlphaMode, InstanceDescriptor};
|
|
||||||
use winit::event::Event::*;
|
|
||||||
use winit::event::StartCause;
|
|
||||||
use winit::event_loop::EventLoop;
|
|
||||||
use winit::event_loop::ControlFlow;
|
|
||||||
use winit::platform::run_return::EventLoopExtRunReturn;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum Event {
|
|
||||||
RequestRedraw,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start(mut event_loop: EventLoop<Event>) {
|
|
||||||
let window = winit::window::WindowBuilder::new()
|
|
||||||
.with_transparent(false)
|
|
||||||
.with_title("Grim")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap_or_else(|e| {
|
|
||||||
panic!(
|
|
||||||
"Failed to init window at {} line {} with error\n{:?}",
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
e
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let instance_descriptor = InstanceDescriptor::default();
|
|
||||||
|
|
||||||
let mut instance = wgpu::Instance::new(instance_descriptor);
|
|
||||||
|
|
||||||
let mut size = window.inner_size();
|
|
||||||
let outer_size = window.outer_size();
|
|
||||||
|
|
||||||
warn!("outer_size = {:?}", outer_size);
|
|
||||||
warn!("size = {:?}", size);
|
|
||||||
|
|
||||||
let mut platform = Platform::new(PlatformDescriptor {
|
|
||||||
physical_width: size.width as u32,
|
|
||||||
physical_height: size.height as u32,
|
|
||||||
scale_factor: window.scale_factor(),
|
|
||||||
font_definitions: FontDefinitions::default(),
|
|
||||||
style: Default::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
let mut platform = {
|
|
||||||
event_loop.run_return(|main_event, tgt, control_flow| {
|
|
||||||
control_flow.set_poll();
|
|
||||||
warn!(
|
|
||||||
"Got event: {:?} at {} line {}",
|
|
||||||
&main_event,
|
|
||||||
file!(),
|
|
||||||
line!()
|
|
||||||
);
|
|
||||||
match main_event {
|
|
||||||
NewEvents(e) => match e {
|
|
||||||
StartCause::ResumeTimeReached { .. } => {}
|
|
||||||
StartCause::WaitCancelled { .. } => {}
|
|
||||||
StartCause::Poll => {}
|
|
||||||
StartCause::Init => {}
|
|
||||||
},
|
|
||||||
WindowEvent {
|
|
||||||
window_id,
|
|
||||||
ref event,
|
|
||||||
} => {
|
|
||||||
if let winit::event::WindowEvent::Resized(r) = event {
|
|
||||||
size = *r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DeviceEvent { .. } => {}
|
|
||||||
UserEvent(_) => {}
|
|
||||||
Suspended => {
|
|
||||||
control_flow.set_poll();
|
|
||||||
}
|
|
||||||
Resumed => {
|
|
||||||
if let Some(primary_mon) = tgt.primary_monitor() {
|
|
||||||
size = primary_mon.size();
|
|
||||||
window.set_inner_size(size);
|
|
||||||
warn!(
|
|
||||||
"Set to new size: {:?} at {} line {}",
|
|
||||||
&size,
|
|
||||||
file!(),
|
|
||||||
line!()
|
|
||||||
);
|
|
||||||
} else if let Some(other_mon) = tgt.available_monitors().next() {
|
|
||||||
size = other_mon.size();
|
|
||||||
window.set_inner_size(size);
|
|
||||||
warn!(
|
|
||||||
"Set to new size: {:?} at {} line {}",
|
|
||||||
&size,
|
|
||||||
file!(),
|
|
||||||
line!()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
control_flow.set_exit();
|
|
||||||
}
|
|
||||||
MainEventsCleared => {}
|
|
||||||
RedrawRequested(rdr) => {}
|
|
||||||
RedrawEventsCleared => {}
|
|
||||||
LoopDestroyed => {}
|
|
||||||
};
|
|
||||||
platform.handle_event(&main_event);
|
|
||||||
});
|
|
||||||
|
|
||||||
Platform::new(PlatformDescriptor {
|
|
||||||
physical_width: size.width as u32,
|
|
||||||
physical_height: size.height as u32,
|
|
||||||
scale_factor: window.scale_factor(),
|
|
||||||
font_definitions: FontDefinitions::default(),
|
|
||||||
style: Default::default(),
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
warn!("WGPU new surface at {} line {}", file!(), line!());
|
|
||||||
let mut surface = unsafe { instance.create_surface(&window).unwrap_or_else(|e| {
|
|
||||||
panic!(
|
|
||||||
"Failed to create surface at {} line {} with error\n{:?}",
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
e
|
|
||||||
)
|
|
||||||
}) };
|
|
||||||
|
|
||||||
warn!("instance request_adapter at {} line {}", file!(), line!());
|
|
||||||
// WGPU 0.11+ support force fallback (if HW implementation not supported), set it to true or false (optional).
|
|
||||||
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
|
|
||||||
power_preference: wgpu::PowerPreference::HighPerformance,
|
|
||||||
compatible_surface: Some(&surface),
|
|
||||||
force_fallback_adapter: false,
|
|
||||||
}))
|
|
||||||
.unwrap_or_else(|| panic!("Failed get adapter at {} line {}", file!(), line!()));
|
|
||||||
|
|
||||||
warn!("adapter request_device at {} line {}", file!(), line!());
|
|
||||||
let (device, queue) = pollster::block_on(adapter.request_device(
|
|
||||||
&wgpu::DeviceDescriptor {
|
|
||||||
features: wgpu::Features::default(),
|
|
||||||
limits: wgpu::Limits::downlevel_defaults(),
|
|
||||||
label: None,
|
|
||||||
},
|
|
||||||
None,
|
|
||||||
))
|
|
||||||
.unwrap_or_else(|e| {
|
|
||||||
panic!(
|
|
||||||
"Failed to request device at {} line {} with error\n{:?}",
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
e
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let surface_capabilities = surface.get_capabilities(&adapter);
|
|
||||||
let surface_format = surface_capabilities.formats[0];
|
|
||||||
let mut surface_config = wgpu::SurfaceConfiguration {
|
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
|
||||||
format: surface_format,
|
|
||||||
width: size.width as u32,
|
|
||||||
height: size.height as u32,
|
|
||||||
present_mode: wgpu::PresentMode::AutoNoVsync,
|
|
||||||
alpha_mode: CompositeAlphaMode::Auto,
|
|
||||||
view_formats: vec![surface_format],
|
|
||||||
};
|
|
||||||
|
|
||||||
warn!("surface configure at {} line {}", file!(), line!());
|
|
||||||
surface.configure(&device, &surface_config);
|
|
||||||
|
|
||||||
warn!("RenderPass new at {} line {}", file!(), line!());
|
|
||||||
let mut egui_rpass = RenderPass::new(&device, surface_format, 1);
|
|
||||||
|
|
||||||
warn!("DemoWindows default at {} line {}", file!(), line!());
|
|
||||||
// Display the demo application that ships with egui.
|
|
||||||
let mut demo_app = egui_demo_lib::DemoWindows::default();
|
|
||||||
|
|
||||||
let start_time = Instant::now();
|
|
||||||
|
|
||||||
let mut in_bad_state = false;
|
|
||||||
|
|
||||||
warn!("Enter the loop");
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
// Pass the winit events to the platform integration.
|
|
||||||
debug!("Got event: {:?} at {} line {}", &event, file!(), line!());
|
|
||||||
platform.handle_event(&event);
|
|
||||||
match event {
|
|
||||||
RedrawRequested(..) => {
|
|
||||||
platform.update_time(start_time.elapsed().as_secs_f64());
|
|
||||||
|
|
||||||
let output_frame = match surface.get_current_texture() {
|
|
||||||
Ok(frame) => frame,
|
|
||||||
Err(wgpu::SurfaceError::Outdated) => {
|
|
||||||
// This error occurs when the app is minimized on Windows.
|
|
||||||
// Silently return here to prevent spamming the console with:
|
|
||||||
error!("The underlying surface has changed, and therefore the swap chain must be updated");
|
|
||||||
in_bad_state = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Err(wgpu::SurfaceError::Lost) => {
|
|
||||||
// This error occurs when the app is minimized on Windows.
|
|
||||||
// Silently return here to prevent spamming the console with:
|
|
||||||
error!("LOST surface, drop frame. Originally: \"The swap chain has been lost and needs to be recreated\"");
|
|
||||||
in_bad_state = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Dropped frame with error: {}", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let output_view = output_frame
|
|
||||||
.texture
|
|
||||||
.create_view(&wgpu::TextureViewDescriptor::default());
|
|
||||||
|
|
||||||
// Begin to draw the UI frame.
|
|
||||||
platform.begin_frame();
|
|
||||||
|
|
||||||
// Draw the demo application.
|
|
||||||
demo_app.ui(&platform.context());
|
|
||||||
|
|
||||||
// End the UI frame. We could now handle the output and draw the UI with the backend.
|
|
||||||
let full_output = platform.end_frame(Some(&window));
|
|
||||||
let paint_jobs = platform.context().tessellate(full_output.shapes);
|
|
||||||
|
|
||||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
|
||||||
label: Some("encoder"),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Upload all resources for the GPU.
|
|
||||||
let screen_descriptor = ScreenDescriptor {
|
|
||||||
physical_width: surface_config.width,
|
|
||||||
physical_height: surface_config.height,
|
|
||||||
scale_factor: window.scale_factor() as f32
|
|
||||||
};
|
|
||||||
let tdelta: egui::TexturesDelta = full_output.textures_delta;
|
|
||||||
egui_rpass
|
|
||||||
.add_textures(&device, &queue, &tdelta)
|
|
||||||
.expect("add texture ok");
|
|
||||||
egui_rpass.update_buffers(&device, &queue, &paint_jobs, &screen_descriptor);
|
|
||||||
|
|
||||||
// Record all render passes.
|
|
||||||
egui_rpass
|
|
||||||
.execute(
|
|
||||||
&mut encoder,
|
|
||||||
&output_view,
|
|
||||||
&paint_jobs,
|
|
||||||
&screen_descriptor,
|
|
||||||
Some(wgpu::Color::BLACK),
|
|
||||||
)
|
|
||||||
.unwrap_or_else(|e| panic!("Failed to render pass at {} line {} with error\n{:?}", file!(), line!(), e));
|
|
||||||
// Submit the commands.
|
|
||||||
queue.submit(iter::once(encoder.finish()));
|
|
||||||
|
|
||||||
// Redraw egui
|
|
||||||
output_frame.present();
|
|
||||||
|
|
||||||
egui_rpass
|
|
||||||
.remove_textures(tdelta)
|
|
||||||
.expect("remove texture ok");
|
|
||||||
|
|
||||||
// Support reactive on windows only, but not on linux.
|
|
||||||
// if _output.needs_repaint {
|
|
||||||
// *control_flow = ControlFlow::Poll;
|
|
||||||
// } else {
|
|
||||||
// *control_flow = ControlFlow::Wait;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
MainEventsCleared | UserEvent(Event::RequestRedraw) => {
|
|
||||||
window.request_redraw();
|
|
||||||
}
|
|
||||||
WindowEvent { event, .. } => match event {
|
|
||||||
winit::event::WindowEvent::Resized(size) => {
|
|
||||||
// Resize with 0 width and height is used by winit to signal a minimize event on Windows.
|
|
||||||
// See: https://github.com/rust-windowing/winit/issues/208
|
|
||||||
// This solves an issue where the app would panic when minimizing on Windows.
|
|
||||||
if size.width > 0 && size.height > 0 {
|
|
||||||
surface_config.width = size.width;
|
|
||||||
surface_config.height = size.height;
|
|
||||||
surface.configure(&device, &surface_config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
winit::event::WindowEvent::CloseRequested => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
winit::event::WindowEvent::Focused(focused) => {
|
|
||||||
in_bad_state |= !focused;
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
Resumed => {
|
|
||||||
if in_bad_state {
|
|
||||||
//https://github.com/gfx-rs/wgpu/issues/2302
|
|
||||||
warn!("WGPU new surface at {} line {}", file!(), line!());
|
|
||||||
surface = unsafe { instance.create_surface(&window).unwrap_or_else(|e| {
|
|
||||||
panic!(
|
|
||||||
"Failed to create surface at {} line {} with error\n{:?}",
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
e
|
|
||||||
)
|
|
||||||
}) };
|
|
||||||
warn!("surface configure at {} line {}", file!(), line!());
|
|
||||||
surface.configure(&device, &surface_config);
|
|
||||||
in_bad_state = false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Suspended => (),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
0
src/gui/root.rs
Normal file
0
src/gui/root.rs
Normal file
Loading…
Reference in a new issue