Set runtime icon
This commit is contained in:
+30
-7
@@ -2,8 +2,8 @@ use std::{collections::HashSet, num::NonZero, sync::Arc, thread, time::Duration}
|
||||
|
||||
use egui::{
|
||||
ahash::{HashMap, HashMapExt},
|
||||
Context, FontData, FontDefinitions, FontFamily, TextWrapMode, ViewportBuilder, ViewportCommand,
|
||||
ViewportId, ViewportInfo,
|
||||
Context, FontData, FontDefinitions, FontFamily, IconData, TextWrapMode, ViewportBuilder,
|
||||
ViewportCommand, ViewportId, ViewportInfo,
|
||||
};
|
||||
use gilrs::{EventType, Gilrs};
|
||||
use winit::{
|
||||
@@ -20,7 +20,19 @@ use crate::{
|
||||
window::{AppWindow, GameWindow, InputWindow},
|
||||
};
|
||||
|
||||
fn load_icon() -> anyhow::Result<IconData> {
|
||||
let bytes = include_bytes!("../assets/lemur-256x256.png");
|
||||
let img = image::load_from_memory_with_format(bytes, image::ImageFormat::Png)?;
|
||||
let rgba = img.into_rgba8();
|
||||
Ok(IconData {
|
||||
width: rgba.width(),
|
||||
height: rgba.height(),
|
||||
rgba: rgba.into_vec(),
|
||||
})
|
||||
}
|
||||
|
||||
pub struct Application {
|
||||
icon: Option<Arc<IconData>>,
|
||||
client: EmulatorClient,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
mappings: MappingProvider,
|
||||
@@ -31,6 +43,7 @@ pub struct Application {
|
||||
|
||||
impl Application {
|
||||
pub fn new(client: EmulatorClient, proxy: EventLoopProxy<UserEvent>) -> Self {
|
||||
let icon = load_icon().ok().map(Arc::new);
|
||||
let mappings = MappingProvider::new();
|
||||
let controllers = ControllerManager::new(client.clone(), &mappings);
|
||||
{
|
||||
@@ -39,6 +52,7 @@ impl Application {
|
||||
thread::spawn(|| process_gamepad_input(mappings, proxy));
|
||||
}
|
||||
Self {
|
||||
icon,
|
||||
client,
|
||||
proxy,
|
||||
mappings,
|
||||
@@ -53,15 +67,17 @@ impl Application {
|
||||
if self.viewports.contains_key(&viewport_id) {
|
||||
return;
|
||||
}
|
||||
self.viewports
|
||||
.insert(viewport_id, Viewport::new(event_loop, window));
|
||||
self.viewports.insert(
|
||||
viewport_id,
|
||||
Viewport::new(event_loop, self.icon.clone(), window),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler<UserEvent> for Application {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let app = GameWindow::new(self.client.clone(), self.proxy.clone(), SimId::Player1);
|
||||
let wrapper = Viewport::new(event_loop, Box::new(app));
|
||||
let wrapper = Viewport::new(event_loop, self.icon.clone(), Box::new(app));
|
||||
self.focused = Some(wrapper.id());
|
||||
self.viewports.insert(wrapper.id(), wrapper);
|
||||
}
|
||||
@@ -192,7 +208,11 @@ struct Viewport {
|
||||
app: Box<dyn AppWindow>,
|
||||
}
|
||||
impl Viewport {
|
||||
pub fn new(event_loop: &ActiveEventLoop, mut app: Box<dyn AppWindow>) -> Self {
|
||||
pub fn new(
|
||||
event_loop: &ActiveEventLoop,
|
||||
icon: Option<Arc<IconData>>,
|
||||
mut app: Box<dyn AppWindow>,
|
||||
) -> Self {
|
||||
let mut painter = egui_wgpu::winit::Painter::new(
|
||||
egui_wgpu::WgpuConfiguration {
|
||||
present_mode: wgpu::PresentMode::AutoNoVsync,
|
||||
@@ -222,7 +242,10 @@ impl Viewport {
|
||||
});
|
||||
|
||||
let mut info = ViewportInfo::default();
|
||||
let builder = app.initial_viewport();
|
||||
let mut builder = app.initial_viewport();
|
||||
if let Some(icon) = icon {
|
||||
builder = builder.with_icon(icon);
|
||||
}
|
||||
let (window, state) = create_window_and_state(&ctx, event_loop, &builder, &mut painter);
|
||||
egui_winit::update_viewport_info(&mut info, &ctx, &window, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user