Refactor to hand-mode UI and reorganize WGSL shader

Replace spatial force / stats panels with unified hand force panels; simplify app.rs wiring and reorganize shader.wgsl for the hand rendering layout.
This commit is contained in:
lenn
2026-07-03 13:41:02 +08:00
parent 71d314ac44
commit a999d9c064
3 changed files with 113 additions and 144 deletions

View File

@@ -13,7 +13,7 @@ use crate::{
},
ui::{
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
draw_config_panel, draw_spatial_force_panel, draw_stats_panel, panel_restore_item,
draw_config_panel, draw_hand_force_panels, panel_restore_item,
},
};
use eframe::{egui, egui_wgpu};
@@ -167,12 +167,7 @@ impl EskinDesktopApp {
live_rates: LiveRateMeters::new(),
context_menu_open: false,
context_menu_pos: egui::pos2(24.0, 48.0),
active_mode: ActiveMode::Finger(FingerMode {
rows: 12,
cols: 7,
range: 0..7000,
dot: true,
}),
active_mode: ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
}
}
@@ -190,7 +185,6 @@ impl EskinDesktopApp {
active_mode: self.active_mode.clone(),
},
));
self.paint_spatial_force_overlay(ui, rect);
}
fn paint_spatial_force_overlay(&self, ui: &egui::Ui, rect: egui::Rect) {
@@ -223,11 +217,7 @@ impl EskinDesktopApp {
}
fn draw_workspace(&mut self, ui: &mut egui::Ui) {
if self.breakout_visible {
self.draw_split_workspace(ui);
} else {
self.draw_wgpu_background_rect(ui, ui.max_rect());
}
self.draw_wgpu_background_rect(ui, ui.max_rect());
}
fn draw_split_workspace(&mut self, ui: &mut egui::Ui) {
@@ -295,9 +285,7 @@ impl EskinDesktopApp {
self.signal_history.remove(0);
}
if self.config_state.mode == SerialMode::Hand {
update_hand_signal_histories(&mut self.hand_signal_histories, &sample.matrix);
}
update_hand_signal_histories(&mut self.hand_signal_histories, &sample.matrix);
}
}
@@ -423,12 +411,6 @@ impl EskinDesktopApp {
self.matrix_config_panel.visible = false;
self.context_menu_open = false;
if self.breakout_visible {
self.config_panel.visible = false;
self.stats_panel.visible = false;
return;
}
if let Some(next_mode) = draw_config_panel(
ctx,
&mut self.config_panel,
@@ -439,39 +421,11 @@ impl EskinDesktopApp {
self.live_rates.sample_rate_hz,
self.live_rates.render_rate_hz,
) {
if next_mode == SerialMode::Hand {
self.config_state.mode = SerialMode::Finger;
self.connect_state.mode = SerialMode::Finger;
self.config_state.baud_rate = SerialMode::Finger.baud_rate();
self.active_mode = ActiveMode::Finger(FingerMode {
rows: self.matrix_config.rows,
cols: self.matrix_config.cols,
range: 0..7000,
dot: true,
});
self.breakout_visible = true;
} else {
self.switch_mode(next_mode);
}
self.switch_mode(next_mode);
}
if self.config_state.mode == SerialMode::Finger {
self.stats_panel.visible = true;
draw_stats_panel(
ctx,
&mut self.stats_panel,
&self.signal_history,
self.latest_spatial_force,
);
} else {
self.stats_panel.visible = false;
}
if let Some(force) = self.latest_spatial_force {
self.spatial_force_panel_force = Some(force);
}
draw_spatial_force_panel(ctx, self.spatial_force_panel_force, &self.signal_history);
self.stats_panel.visible = false;
draw_hand_force_panels(ctx, true, &self.hand_signal_histories);
}
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {

View File

@@ -104,10 +104,10 @@ impl Default for ConfigPanelState {
.unwrap_or_else(|| "COM3".to_owned());
Self {
mode: SerialMode::Finger,
mode: SerialMode::Hand,
port,
available_ports,
baud_rate: 921_600,
baud_rate: SerialMode::Hand.baud_rate(),
data_bits: 8,
stop_bits: 1,
parity: Parity::None,
@@ -126,7 +126,7 @@ impl Default for ConnectPanelState {
let port = serial_enum().unwrap_or_default();
let selected_port = port.first().cloned().unwrap_or_default();
Self {
mode: SerialMode::Finger,
mode: SerialMode::Hand,
port,
selected_port,
duration: 10,
@@ -499,27 +499,14 @@ pub fn draw_spatial_force_panel(
}
fn draw_mode_row(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
let mut changed_to = None;
config.mode = SerialMode::Hand;
config.baud_rate = SerialMode::Hand.baud_rate();
ui.horizontal_wrapped(|ui| {
ui.colored_label(dim_text(), "模式");
ui.colored_label(dim_text(), "Mode");
ui.add_space(12.0);
if mode_button(ui, &mut config.mode, SerialMode::Finger, "指尖模块") {
changed_to = Some(SerialMode::Finger)
}
if mode_button(ui, &mut config.mode, SerialMode::Hand, "游戏体验") {
changed_to = Some(SerialMode::Hand)
}
// mode_button(ui, &mut config.mode, SerialMode::Model, "模型");
// Legacy reconnect controls. Current sensors run fixed 921600 baud without auto-reconnect UI.
// ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
// ui.checkbox(&mut config.auto_reconnect, "自动");
// ui.colored_label(dim_text(), "重连");
// });
ui.label(style::panel_title("Hand Gateway"));
});
changed_to
None
}
fn draw_connection_row(