feat: 添加 app/theme/ui/matrix/render 模块,重构 shader
This commit is contained in:
89
src/app.rs
Normal file
89
src/app.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use eframe::{egui, egui_wgpu};
|
||||
|
||||
use crate::theme::{ENGINEERING_DARK, apply_theme};
|
||||
use crate::{
|
||||
matrix::{MATRIX_COLS, MATRIX_ROWS},
|
||||
render::{BackgroundRenderResources, WgpuBackgroundCallback},
|
||||
ui::{FloatingPanelState, draw_config_panel, draw_scene_panel, draw_stats_panel},
|
||||
};
|
||||
|
||||
pub struct EskinDesktopApp {
|
||||
scene_panel: FloatingPanelState,
|
||||
config_panel: FloatingPanelState,
|
||||
stats_panel: FloatingPanelState,
|
||||
started_at: Instant,
|
||||
}
|
||||
|
||||
impl EskinDesktopApp {
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
apply_theme(&cc.egui_ctx, &ENGINEERING_DARK);
|
||||
|
||||
let wgpu_state = cc
|
||||
.wgpu_render_state
|
||||
.as_ref()
|
||||
.expect("need open eframe wgpu renderer feature");
|
||||
|
||||
let mut renderer = wgpu_state.renderer.write();
|
||||
renderer
|
||||
.callback_resources
|
||||
.insert(BackgroundRenderResources::new(
|
||||
&wgpu_state.device,
|
||||
&wgpu_state.target_format,
|
||||
MATRIX_ROWS,
|
||||
MATRIX_COLS,
|
||||
));
|
||||
|
||||
Self {
|
||||
scene_panel: FloatingPanelState::new([16.0, 48.0], [16.0, 48.0]),
|
||||
config_panel: FloatingPanelState::new([840.0, 48.0], [128.0, 48.0]),
|
||||
stats_panel: FloatingPanelState::new([16.0, 520.0], [240.0, 48.0]),
|
||||
started_at: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_wgpu_background(&mut self, ui: &mut egui::Ui) {
|
||||
let rect = ui.max_rect();
|
||||
let width = rect.width().max(1.0);
|
||||
let height = rect.height().max(1.0);
|
||||
|
||||
ui.painter().add(egui_wgpu::Callback::new_paint_callback(
|
||||
rect,
|
||||
WgpuBackgroundCallback {
|
||||
width,
|
||||
height,
|
||||
time: self.started_at.elapsed().as_secs_f32(),
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
fn draw_toolbar(&mut self, ui: &mut egui::Ui) {
|
||||
egui::Panel::top("main_menu").show_inside(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.checkbox(&mut self.scene_panel.visible, "Scene");
|
||||
ui.checkbox(&mut self.config_panel.visible, "Config");
|
||||
ui.checkbox(&mut self.stats_panel.visible, "Stats");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_floating_panels(&mut self, ctx: &egui::Context) {
|
||||
draw_scene_panel(ctx, &mut self.scene_panel);
|
||||
draw_config_panel(ctx, &mut self.config_panel);
|
||||
draw_stats_panel(ctx, &mut self.stats_panel);
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for EskinDesktopApp {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
let ctx = ui.ctx().clone();
|
||||
|
||||
self.draw_wgpu_background(ui);
|
||||
self.draw_toolbar(ui);
|
||||
self.draw_floating_panels(&ctx);
|
||||
|
||||
// Keep repainting while the wgpu background is a realtime viewport.
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user