fix: 节点列表单击滚动,双击切换模式\n\n- 单击 UP/DOWN:滚动界面\n- 双击(400ms内):切换模式"

This commit is contained in:
2026-03-30 20:48:35 +08:00
parent d305752333
commit ee6a843349
3 changed files with 45 additions and 19 deletions
@@ -1597,17 +1597,19 @@ int Screen::handleInputEvent(const InputEvent *event)
} else if (event->inputEvent == INPUT_BROKER_RIGHT || event->inputEvent == INPUT_BROKER_USER_PRESS) { } else if (event->inputEvent == INPUT_BROKER_RIGHT || event->inputEvent == INPUT_BROKER_USER_PRESS) {
showNextFrame(); showNextFrame();
} else if (event->inputEvent == INPUT_BROKER_UP) { } else if (event->inputEvent == INPUT_BROKER_UP) {
// 在节点列表界面,双击切换到上一个模式 // 在节点列表界面,单击滚动,双击切换模式
if (this->ui->getUiState()->currentFrame == framesetInfo.positions.nodelist) { if (this->ui->getUiState()->currentFrame == framesetInfo.positions.nodelist) {
if (graphics::NodeListRenderer::handleUpDoubleClick()) { int result = graphics::NodeListRenderer::handleUpKey();
if (result > 0) {
setFastFramerate(); setFastFramerate();
ui->update(); ui->update();
} }
} }
} else if (event->inputEvent == INPUT_BROKER_DOWN) { } else if (event->inputEvent == INPUT_BROKER_DOWN) {
// 在节点列表界面,双击切换到下一个模式 // 在节点列表界面,单击滚动,双击切换模式
if (this->ui->getUiState()->currentFrame == framesetInfo.positions.nodelist) { if (this->ui->getUiState()->currentFrame == framesetInfo.positions.nodelist) {
if (graphics::NodeListRenderer::handleDownDoubleClick()) { int result = graphics::NodeListRenderer::handleDownKey();
if (result > 0) {
setFastFramerate(); setFastFramerate();
ui->update(); ui->update();
} }
@@ -74,38 +74,57 @@ void switchToPrevMode()
currentMode = static_cast<NodeListMode>((currentMode + MODE_COUNT - 1) % MODE_COUNT); currentMode = static_cast<NodeListMode>((currentMode + MODE_COUNT - 1) % MODE_COUNT);
} }
// 处理 UP 按键双击检测(从 Screen.cpp 调用) // 滚动控制函数
// 返回 true 表示检测到双击,需要切换模式 void scrollUp()
bool handleUpDoubleClick() {
scrollIndex--;
if (scrollIndex < 0) {
scrollIndex = 0;
}
}
void scrollDown()
{
scrollIndex++;
// 最大滚动值在渲染时计算,这里只做简单限制
}
// 处理 UP 按键:单击滚动,双击切换模式
// 返回 0: 无操作, 1: 滚动触发, 2: 模式切换触发
int handleUpKey()
{ {
unsigned long now = millis(); unsigned long now = millis();
if (lastUpPressTime > 0 && (now - lastUpPressTime) < DOUBLE_CLICK_THRESHOLD_MS) { if (lastUpPressTime > 0 && (now - lastUpPressTime) < DOUBLE_CLICK_THRESHOLD_MS) {
// 双击触发:切换到上一个模式 // 双击触发:切换到上一个模式
switchToPrevMode(); switchToPrevMode();
lastUpPressTime = 0; // 重置,防止三次点击触发两次 lastUpPressTime = 0;
return true; return 2;
} }
// 单击触发:滚动
scrollUp();
lastUpPressTime = now; lastUpPressTime = now;
return false; return 1;
} }
// 处理 DOWN 按键双击检测(从 Screen.cpp 调用) // 处理 DOWN 按键:单击滚动,双击切换模式
// 返回 true 表示检测到双击,需要切换模式 // 返回 0: 无操作, 1: 滚动触发, 2: 模式切换触发
bool handleDownDoubleClick() int handleDownKey()
{ {
unsigned long now = millis(); unsigned long now = millis();
if (lastDownPressTime > 0 && (now - lastDownPressTime) < DOUBLE_CLICK_THRESHOLD_MS) { if (lastDownPressTime > 0 && (now - lastDownPressTime) < DOUBLE_CLICK_THRESHOLD_MS) {
// 双击触发:切换到下一个模式 // 双击触发:切换到下一个模式
switchToNextMode(); switchToNextMode();
lastDownPressTime = 0; // 重置,防止三次点击触发两次 lastDownPressTime = 0;
return true; return 2;
} }
// 单击触发:滚动
scrollDown();
lastDownPressTime = now; lastDownPressTime = now;
return false; return 1;
} }
// ============================= // =============================
@@ -59,9 +59,14 @@ void switchToNextMode();
void switchToPrevMode(); void switchToPrevMode();
NodeListMode getCurrentMode(); NodeListMode getCurrentMode();
// Double-click detection for UP/DOWN keys (returns true if double-click detected) // Scroll control functions
bool handleUpDoubleClick(); void scrollUp();
bool handleDownDoubleClick(); void scrollDown();
// UP/DOWN key handler: single click = scroll, double click = switch mode
// Returns: 0=no action, 1=scroll triggered, 2=mode switch triggered
int handleUpKey();
int handleDownKey();
// Bitmap drawing function // Bitmap drawing function
void drawScaledXBitmap16x16(int x, int y, int width, int height, const uint8_t *bitmapXBM, OLEDDisplay *display); void drawScaledXBitmap16x16(int x, int y, int width, int height, const uint8_t *bitmapXBM, OLEDDisplay *display);