Refine UI panels and render mode flow

This commit is contained in:
lennlouisgeek
2026-06-26 02:03:07 +08:00
parent 156df50d33
commit 0b658d11c5
8 changed files with 1375687 additions and 345 deletions

View File

@@ -1,16 +1,17 @@
use crate::connection::ConnectionManager;
use crate::recording::Recorder;
use crate::theme::{ONE_DARK_PRO, apply_fonts, apply_theme};
use crate::render::{ActiveMode, FingerMode, HandGatewayMode};
use crate::style::{ONE_DARK_PRO, apply_fonts, apply_theme, layout};
use crate::ui::SerialMode;
use crate::{
matrix::{MATRIX_COLS, MATRIX_ROWS},
render::{
BackgroundRenderResources, MarkerMode, PRESSURE_CELL_COUNT, PressureFrame,
WgpuBackgroundCallback,
BackgroundRenderResources, PRESSURE_CELL_COUNT, PressureFrame, WgpuBackgroundCallback,
},
ui::{
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
draw_config_panel, draw_connect_panel, draw_export_panel, draw_matrix_config_panel,
draw_scene_panel, draw_stats_panel,
draw_stats_panel, panel_restore_item,
},
};
use eframe::{egui, egui_wgpu};
@@ -35,6 +36,7 @@ pub struct EskinDesktopApp {
matrix_config_panel: FloatingPanelState,
matrix_config: MatrixConfigState,
signal_history: Vec<f32>,
active_mode: ActiveMode,
}
impl EskinDesktopApp {
@@ -60,21 +62,42 @@ impl EskinDesktopApp {
));
Self {
connect_panel: FloatingPanelState::new([0.0, 0.0], [0.0, 0.0]),
connect_panel: FloatingPanelState::new([0.0, 0.0], [layout::RIGHT_TAG_X, 48.0]),
connect_state: ConnectPanelState::default(),
connection: Arc::new(ConnectionManager::new()),
pressure_matrix: [[0.0, 0.0]; PRESSURE_CELL_COUNT],
data_log_frame: 0,
scene_panel: FloatingPanelState::new([16.0, 48.0], [16.0, 48.0]),
config_panel: FloatingPanelState::new([840.0, 48.0], [128.0, 48.0]),
scene_panel: FloatingPanelState::new(
[layout::LEFT_X, layout::TOP_Y],
[layout::LEFT_TAG_X, layout::TOP_Y],
),
config_panel: FloatingPanelState::new(
[layout::RIGHT_X, layout::TOP_Y],
[layout::RIGHT_TAG_X, layout::TOP_Y],
),
config_state: ConfigPanelState::default(),
stats_panel: FloatingPanelState::new([16.0, 520.0], [240.0, 48.0]),
stats_panel: FloatingPanelState::new(
[layout::LEFT_X, layout::LEFT_SECOND_Y],
[layout::LEFT_TAG_X, layout::LEFT_SECOND_Y],
),
recorder: Recorder::full(),
export_panel: FloatingPanelState::new([16.0, 280.0], [16.0, 280.0]),
export_panel: FloatingPanelState::new(
[layout::LEFT_X, layout::TOP_Y],
[layout::LEFT_TAG_X, layout::TOP_Y],
),
export_path: String::new(),
matrix_config_panel: FloatingPanelState::new([840.0, 280.0], [400.0, 48.0]),
matrix_config_panel: FloatingPanelState::new(
[layout::RIGHT_X, layout::RIGHT_SECOND_Y],
[layout::RIGHT_TAG_X, layout::RIGHT_SECOND_Y],
),
matrix_config: MatrixConfigState::default(),
signal_history: Vec::with_capacity(128),
active_mode: ActiveMode::Finger(FingerMode {
rows: 12,
cols: 7,
range: 0..7000,
dot: true,
}),
}
}
@@ -91,7 +114,7 @@ impl EskinDesktopApp {
width,
height,
pressure: self.pressure_matrix,
marker_mode: MarkerMode::Number,
active_mode: self.active_mode.clone(),
},
));
}
@@ -123,7 +146,7 @@ impl EskinDesktopApp {
}
fn draw_title_bar(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
let title_bar_height = 36.0;
let title_bar_height = layout::TITLE_BAR_HEIGHT;
let title_bar_rect = ui
.allocate_space(egui::vec2(ui.available_width(), title_bar_height))
.1;
@@ -242,8 +265,12 @@ impl EskinDesktopApp {
&self.recorder,
&mut self.export_path,
);
draw_scene_panel(ctx, &mut self.scene_panel);
draw_config_panel(ctx, &mut self.config_panel, &mut self.config_state);
// draw_scene_panel(ctx, &mut self.scene_panel);
if let Some(next_mode) =
draw_config_panel(ctx, &mut self.config_panel, &mut self.config_state)
{
self.switch_mode(next_mode);
}
draw_stats_panel(ctx, &mut self.stats_panel);
draw_export_panel(
ctx,
@@ -253,6 +280,54 @@ impl EskinDesktopApp {
);
draw_matrix_config_panel(ctx, &mut self.matrix_config_panel, &mut self.matrix_config);
}
fn draw_panel_context_menu(&mut self, ui: &mut egui::Ui) {
let response = ui.interact(
ui.max_rect(),
egui::Id::new("workspace_panel_context_menu"),
egui::Sense::click(),
);
response.context_menu(|ui| {
ui.label("显示面板");
ui.separator();
panel_restore_item(ui, "连接", &mut self.connect_panel);
panel_restore_item(ui, "配置", &mut self.config_panel);
panel_restore_item(ui, "录制", &mut self.export_panel);
panel_restore_item(ui, "矩阵", &mut self.matrix_config_panel);
panel_restore_item(ui, "统计", &mut self.stats_panel);
ui.separator();
if ui.button("全部显示").clicked() {
self.connect_panel.visible = true;
self.config_panel.visible = true;
self.export_panel.visible = true;
self.matrix_config_panel.visible = true;
self.stats_panel.visible = true;
ui.close();
}
});
}
fn switch_mode(&mut self, next: SerialMode) {
self.connect_state.mode = next;
self.config_state.mode = next;
self.connection.disconnect();
self.pressure_matrix.fill([0.0, 0.0]);
self.data_log_frame = 0;
self.active_mode = match next {
SerialMode::Finger => ActiveMode::Finger(FingerMode {
rows: self.matrix_config.rows,
cols: self.matrix_config.cols,
range: 0..7000,
dot: true,
}),
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
}
}
}
fn log_pressure_sample(raw: &[u32], rows: u32, cols: u32) {
@@ -305,6 +380,7 @@ impl eframe::App for EskinDesktopApp {
let ctx = ui.ctx().clone();
self.draw_wgpu_background(ui);
self.draw_panel_context_menu(ui);
self.draw_title_bar(ui, frame);
self.draw_floating_panels(&ctx);