Show button controls on companion home and message screens
This commit is contained in:
1 parent
ac694d536e
commit
74d87c8d13
6 files changed
+265
-24
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <helpers/ui/CompanionHomeLayout.h>
|
||||
#include <helpers/ui/DisplayTextLayout.h>
|
||||
#include <helpers/ui/SmallMessageText.h>
|
||||
#include <helpers/ui/ReaderNavigationHint.h>
|
||||
#include <helpers/ui/WiFiSetupQrDisplay.h>
|
||||
#include <helpers/ui/WiFiSetupQrPayload.h>
|
||||
|
||||
@@ -233,6 +234,51 @@ TEST(SmallMessageText, MessageBodyRespectsReservedFooter) {
|
||||
for (const auto& pixel : display.fills) EXPECT_LT(pixel.y, 56);
|
||||
}
|
||||
|
||||
TEST(SmallMessageText, ButtonHintKeepsFiveMessageRowsWithoutOverlappingText) {
|
||||
TestDisplay display(128, 64);
|
||||
mesh::ui::SmallMessageText text(display);
|
||||
const auto hint = mesh::ui::makeButtonReaderHintLayout(
|
||||
text, text.lineHeight(), display.height());
|
||||
ASSERT_EQ(1, hint.line_count);
|
||||
EXPECT_EQ(56, hint.top);
|
||||
EXPECT_EQ(5, text.lineCount(2 * text.lineHeight(), hint.top));
|
||||
|
||||
mesh::ui::drawSmallMessageBody(display, "Ch 0 Public [4h]:",
|
||||
std::string(160, 'W').c_str(),
|
||||
text.lineHeight(), hint.top);
|
||||
ASSERT_FALSE(display.fills.empty());
|
||||
for (const auto& pixel : display.fills) EXPECT_LT(pixel.y, hint.top);
|
||||
display.fills.clear();
|
||||
mesh::ui::drawButtonReaderHint(text, hint);
|
||||
ASSERT_FALSE(display.fills.empty());
|
||||
for (const auto& pixel : display.fills) {
|
||||
EXPECT_GE(pixel.x, 0);
|
||||
EXPECT_LE(pixel.x + pixel.width, display.width());
|
||||
EXPECT_GE(pixel.y, hint.top);
|
||||
EXPECT_LE(pixel.y + pixel.height, display.height());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SmallMessageText, ButtonHintReflowsOnTinyAndRotatedScreens) {
|
||||
for (auto dimensions : {std::pair<int, int>{72, 40}, {40, 72},
|
||||
{128, 32}, {32, 128}, {64, 128}, {128, 64}}) {
|
||||
TestDisplay display(dimensions.first, dimensions.second);
|
||||
mesh::ui::SmallMessageText text(display);
|
||||
const auto hint = mesh::ui::makeButtonReaderHintLayout(
|
||||
text, text.lineHeight(), display.height());
|
||||
for (int row = 0; row < hint.line_count; ++row)
|
||||
EXPECT_LE(text.getTextWidth(hint.lines[row]), display.width());
|
||||
mesh::ui::drawButtonReaderHint(text, hint);
|
||||
ASSERT_FALSE(display.fills.empty());
|
||||
for (const auto& pixel : display.fills) {
|
||||
EXPECT_GE(pixel.x, 0);
|
||||
EXPECT_LE(pixel.x + pixel.width, display.width());
|
||||
EXPECT_GE(pixel.y, hint.top);
|
||||
EXPECT_LE(pixel.y + pixel.height, display.height());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SmallMessageText, Full160CharacterSamplesFitInFiveRows) {
|
||||
class RecordingText : public mesh::ui::SmallMessageText {
|
||||
public:
|
||||
@@ -257,6 +303,15 @@ TEST(SmallMessageText, Full160CharacterSamplesFitInFiveRows) {
|
||||
EXPECT_EQ(5, mesh::ui::drawTextWrapped(text, 0, 22, 128,
|
||||
text.lineHeight(), text.lineCount(22), sample));
|
||||
EXPECT_EQ(sample, text.drawn);
|
||||
// The button reader moves its header/origin up to reserve the hint, so
|
||||
// the same complete 160-character text still fits in five body rows.
|
||||
text.drawn.clear();
|
||||
const auto hint = mesh::ui::makeButtonReaderHintLayout(
|
||||
text, text.lineHeight(), display.height());
|
||||
const int message_y = 2 * text.lineHeight();
|
||||
EXPECT_EQ(5, mesh::ui::drawTextWrapped(text, 0, message_y, 128,
|
||||
text.lineHeight(), text.lineCount(message_y, hint.top), sample));
|
||||
EXPECT_EQ(sample, text.drawn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
@@ -141,6 +143,60 @@ class HeltecV4WiFiSetupPageTest(unittest.TestCase):
|
||||
self.assertNotIn("savePrefs", loop[stop:state_service])
|
||||
self.assertNotIn("saveEnabled", loop[stop:state_service])
|
||||
|
||||
def test_reader_exit_wins_over_startup_rescue_but_home_keeps_rescue(self):
|
||||
ui = UI.read_text(encoding="utf-8")
|
||||
start = ui.index("char UITask::handleLongPress(char c) {")
|
||||
end = ui.index("\nchar UITask::handleDoubleClick", start)
|
||||
source = r'''
|
||||
#include <cassert>
|
||||
#define UI_WIFI_SETUP_HOME_PAGE 1
|
||||
unsigned long now = 4000;
|
||||
unsigned long millis() { return now; }
|
||||
struct Screen {};
|
||||
struct HomeScreen : Screen {
|
||||
bool setup = false;
|
||||
bool isWiFiSetupPage() const { return setup; }
|
||||
};
|
||||
struct Mesh {
|
||||
int rescue_calls = 0;
|
||||
void enterCLIRescue() { ++rescue_calls; }
|
||||
} the_mesh;
|
||||
struct UITask {
|
||||
Screen* curr;
|
||||
Screen* home;
|
||||
Screen* msg_preview;
|
||||
unsigned long ui_started_at = 0;
|
||||
char handleLongPress(char c);
|
||||
};
|
||||
''' + ui[start:end] + r'''
|
||||
int main() {
|
||||
HomeScreen home;
|
||||
Screen reader;
|
||||
UITask task{&reader, &home, &reader};
|
||||
assert(task.handleLongPress('E') == 'E');
|
||||
assert(the_mesh.rescue_calls == 0);
|
||||
task.curr = &home;
|
||||
assert(task.handleLongPress('E') == 0);
|
||||
assert(the_mesh.rescue_calls == 1);
|
||||
home.setup = true;
|
||||
assert(task.handleLongPress('E') == 'E');
|
||||
assert(the_mesh.rescue_calls == 1);
|
||||
home.setup = false;
|
||||
now = 9000;
|
||||
assert(task.handleLongPress('E') == 'E');
|
||||
task.curr = &reader;
|
||||
assert(task.handleLongPress('E') == 'E');
|
||||
assert(the_mesh.rescue_calls == 1);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
executable = Path(temp_dir) / "reader_hold"
|
||||
subprocess.run(
|
||||
["c++", "-std=c++17", "-x", "c++", "-", "-o", str(executable)],
|
||||
input=source, text=True, capture_output=True, check=True,
|
||||
)
|
||||
subprocess.run([str(executable)], check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -78,7 +78,7 @@ class T096MessageFooterProfileTest(unittest.TestCase):
|
||||
ui = UI.read_text(encoding="utf-8")
|
||||
self.assertIn(
|
||||
"#ifndef UI_MESSAGE_CHANNEL_FOOTER\n"
|
||||
" #if defined(MESHCORE_HAS_SMALL_DISPLAY)\n"
|
||||
" #if defined(MESHCORE_HAS_SMALL_DISPLAY) || UI_BUTTON_READER_HINT == 1\n"
|
||||
" #define UI_MESSAGE_CHANNEL_FOOTER 0\n"
|
||||
" #else\n"
|
||||
" #define UI_MESSAGE_CHANNEL_FOOTER 1\n"
|
||||
|
||||
Reference in new issue
Block a user