refactor: 配置面板改造为顶部固定栏 + 压力归一化优化
This commit is contained in:
51
src/app.rs
51
src/app.rs
@@ -217,7 +217,13 @@ impl EskinDesktopApp {
|
||||
}
|
||||
|
||||
fn draw_workspace(&mut self, ui: &mut egui::Ui) {
|
||||
self.draw_wgpu_background_rect(ui, ui.max_rect());
|
||||
let screen = ui.max_rect();
|
||||
let workspace = egui::Rect::from_min_max(
|
||||
screen.left_top()
|
||||
+ egui::vec2(0.0, layout::TITLE_BAR_HEIGHT + layout::CONFIG_BAR_HEIGHT),
|
||||
screen.right_bottom(),
|
||||
);
|
||||
self.draw_wgpu_background_rect(ui, workspace);
|
||||
}
|
||||
|
||||
fn draw_split_workspace(&mut self, ui: &mut egui::Ui) {
|
||||
@@ -475,17 +481,6 @@ impl EskinDesktopApp {
|
||||
} else {
|
||||
panel_restore_item(ui, "统计", &mut self.stats_panel);
|
||||
}
|
||||
if ui
|
||||
.add_sized(
|
||||
egui::vec2(ui.available_width(), 0.0),
|
||||
egui::Button::new("打砖块"),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.breakout_visible = true;
|
||||
close_menu = true;
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui
|
||||
@@ -499,7 +494,6 @@ impl EskinDesktopApp {
|
||||
self.export_panel.visible = true;
|
||||
self.matrix_config_panel.visible = true;
|
||||
self.stats_panel.visible = true;
|
||||
self.breakout_visible = true;
|
||||
close_menu = true;
|
||||
}
|
||||
});
|
||||
@@ -676,16 +670,45 @@ fn normalize_pressure_samples(raw: &[u32]) -> PressureSamples {
|
||||
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
||||
const RANGE_MIN: f32 = 0.0;
|
||||
const RANGE_MAX: f32 = 7000.0;
|
||||
const DISPLAY_GAMMA: f32 = 0.45;
|
||||
|
||||
let raw_value = value as f32;
|
||||
let mapped = ((raw_value - RANGE_MIN) / (RANGE_MAX - RANGE_MIN)).clamp(0.0, 1.0);
|
||||
let intensity = if raw_value <= RANGE_MIN + 4.0 {
|
||||
0.0
|
||||
} else {
|
||||
mapped.powf(DISPLAY_GAMMA)
|
||||
};
|
||||
let display_value = if raw_value <= RANGE_MIN + 4.0 {
|
||||
0.0
|
||||
} else {
|
||||
raw_value.round().min(9999.0)
|
||||
};
|
||||
|
||||
[mapped, display_value]
|
||||
[intensity, display_value]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn pressure_normalization_makes_low_hand_values_visible() {
|
||||
let [zero_intensity, zero_label] = normalize_pressure_value(4);
|
||||
assert_eq!(zero_intensity, 0.0);
|
||||
assert_eq!(zero_label, 0.0);
|
||||
|
||||
let [low_intensity, low_label] = normalize_pressure_value(100);
|
||||
assert!(
|
||||
low_intensity > 0.10,
|
||||
"low hand-gateway values should be visible in the wgpu dot matrix"
|
||||
);
|
||||
assert_eq!(low_label, 100.0);
|
||||
|
||||
let [max_intensity, max_label] = normalize_pressure_value(7000);
|
||||
assert_eq!(max_intensity, 1.0);
|
||||
assert_eq!(max_label, 7000.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for EskinDesktopApp {
|
||||
|
||||
Reference in New Issue
Block a user