Fix: fall back to default egui icon if non is set (#3610)

It broke in one of the recent multi-viewport prs
This commit is contained in:
Emil Ernerfeldt 2023-11-22 20:54:16 +01:00 committed by GitHub
parent 4ece25bd05
commit 6490dfafb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -248,6 +248,9 @@ pub struct NativeOptions {
/// Controls the native window of the root viewport. /// Controls the native window of the root viewport.
/// ///
/// This is where you set things like window title and size. /// This is where you set things like window title and size.
///
/// If you don't set an icon, a default egui icon will be used.
/// To avoid this, set the icon to [`egui::IconData::default`].
pub viewport: egui::ViewportBuilder, pub viewport: egui::ViewportBuilder,
/// Turn on vertical syncing, limiting the FPS to the display refresh rate. /// Turn on vertical syncing, limiting the FPS to the display refresh rate.
@ -379,13 +382,7 @@ impl Clone for NativeOptions {
impl Default for NativeOptions { impl Default for NativeOptions {
fn default() -> Self { fn default() -> Self {
Self { Self {
viewport: egui::ViewportBuilder { viewport: Default::default(),
icon: Some(std::sync::Arc::new(
crate::icon_data::from_png_bytes(&include_bytes!("../data/icon.png")[..])
.unwrap(),
)),
..Default::default()
},
vsync: true, vsync: true,
multisampling: 0, multisampling: 0,

View File

@ -13,7 +13,13 @@ pub struct AppTitleIconSetter {
} }
impl AppTitleIconSetter { impl AppTitleIconSetter {
pub fn new(title: String, icon_data: Option<Arc<IconData>>) -> Self { pub fn new(title: String, mut icon_data: Option<Arc<IconData>>) -> Self {
if let Some(icon) = &icon_data {
if **icon == IconData::default() {
icon_data = None;
}
}
Self { Self {
title, title,
icon_data, icon_data,

View File

@ -169,13 +169,19 @@ impl EpiIntegration {
raw_window_handle: window.raw_window_handle(), raw_window_handle: window.raw_window_handle(),
}; };
let icon = native_options
.viewport
.icon
.clone()
.unwrap_or_else(|| std::sync::Arc::new(load_default_egui_icon()));
let app_icon_setter = super::app_icon::AppTitleIconSetter::new( let app_icon_setter = super::app_icon::AppTitleIconSetter::new(
native_options native_options
.viewport .viewport
.title .title
.clone() .clone()
.unwrap_or_else(|| app_name.to_owned()), .unwrap_or_else(|| app_name.to_owned()),
native_options.viewport.icon.clone(), Some(icon),
); );
Self { Self {
@ -356,6 +362,11 @@ impl EpiIntegration {
} }
} }
fn load_default_egui_icon() -> egui::IconData {
crate::profile_function!();
crate::icon_data::from_png_bytes(&include_bytes!("../../data/icon.png")[..]).unwrap()
}
#[cfg(feature = "persistence")] #[cfg(feature = "persistence")]
const STORAGE_EGUI_MEMORY_KEY: &str = "egui"; const STORAGE_EGUI_MEMORY_KEY: &str = "egui";