Surface error notifications

This commit is contained in:
2024-12-09 23:18:42 -05:00
parent 25b88c622c
commit ae04f9f73b
4 changed files with 76 additions and 19 deletions
+25 -6
View File
@@ -1,12 +1,15 @@
use std::sync::mpsc;
use crate::{
app::UserEvent,
emulator::{EmulatorClient, EmulatorCommand, SimId},
};
use egui::{
ecolor::HexColor, menu, Align2, Button, CentralPanel, Color32, Context, Frame, Layout,
Response, Sense, TopBottomPanel, Ui, Vec2, ViewportBuilder, ViewportCommand, ViewportId,
WidgetText, Window,
ecolor::HexColor, menu, Align2, Button, CentralPanel, Color32, Context, Direction, Frame,
Layout, Response, Sense, TopBottomPanel, Ui, Vec2, ViewportBuilder, ViewportCommand,
ViewportId, WidgetText, Window,
};
use egui_toast::{Toast, Toasts};
use winit::event_loop::EventLoopProxy;
use super::{
@@ -36,6 +39,7 @@ pub struct GameWindow {
display_mode: DisplayMode,
colors: [Color32; 2],
screen: Option<GameScreen>,
messages: Option<mpsc::Receiver<Toast>>,
color_picker: Option<ColorPickerState>,
}
@@ -48,6 +52,7 @@ impl GameWindow {
display_mode: DisplayMode::Anaglyph,
colors: COLOR_PRESETS[0],
screen: None,
messages: None,
color_picker: None,
}
}
@@ -257,6 +262,14 @@ impl AppWindow for GameWindow {
}
fn show(&mut self, ctx: &Context) {
let mut toasts = Toasts::new()
.anchor(Align2::LEFT_BOTTOM, (10.0, 10.0))
.direction(Direction::BottomUp);
if let Some(messages) = self.messages.as_mut() {
while let Ok(toast) = messages.try_recv() {
toasts.add(toast);
}
}
TopBottomPanel::top("menubar")
.exact_height(22.0)
.show(ctx, |ui| {
@@ -280,13 +293,19 @@ impl AppWindow for GameWindow {
ui.add(screen);
}
});
toasts.show(ctx);
}
fn on_init(&mut self, render_state: &egui_wgpu::RenderState) {
let (screen, sink) = GameScreen::init(render_state);
self.client
.send_command(EmulatorCommand::SetRenderer(self.sim_id, sink));
self.screen = Some(screen)
let (message_sink, message_source) = mpsc::channel();
self.client.send_command(EmulatorCommand::ConnectToSim(
self.sim_id,
sink,
message_sink,
));
self.screen = Some(screen);
self.messages = Some(message_source);
}
fn on_destroy(&mut self) {