Implemented back button in display framework

This commit is contained in:
2020-05-24 13:55:15 +02:00
parent 38fc2d800d
commit d5eb54db7c
8 changed files with 34 additions and 29 deletions

View File

@@ -23,8 +23,6 @@ public:
virtual int shownValue() const = 0;
virtual void setShownValue(int value) = 0;
virtual void confirm() = 0;
protected:
Label m_titleLabel{5, 5}; // 230, 25
Label m_valueLabel{26, 81}; // 188, 53
@@ -55,13 +53,11 @@ public:
void redraw() override;
void rotate(int offset) override;
void button() override;
void confirm() override;
int shownValue() const { return m_value; }
void setShownValue(int value) { m_value = value; }
void confirm() override;
private:
Tvalue m_value{};
@@ -132,12 +128,6 @@ void ChangeValueDisplay<Tvalue>::rotate(int offset)
m_rotateOffset += offset;
}
template<typename Tvalue>
void ChangeValueDisplay<Tvalue>::button()
{
m_pressed = true;
}
template<typename Tvalue>
void ChangeValueDisplay<Tvalue>::confirm()
{

View File

@@ -7,10 +7,10 @@ namespace {
class DemoDisplay : public Display, public virtual ActionInterface
{
public:
void button() override;
void confirm() override;
};
void DemoDisplay::button()
void DemoDisplay::confirm()
{
triggered();
}

View File

@@ -20,7 +20,8 @@ public:
virtual void stop() {}
virtual void rotate(int offset) {}
virtual void button() {}
virtual void confirm() {}
virtual void back() {}
virtual TextInterface *asTextInterface() { return nullptr; }
virtual const TextInterface *asTextInterface() const { return nullptr; }

View File

@@ -29,7 +29,7 @@ public:
void redraw() override;
void stop() override;
void button() override;
void confirm() override;
void rotate(int offset) override;
private:
@@ -146,7 +146,7 @@ void Lockscreen::stop()
currentMode = m_oldMode;
}
void Lockscreen::button()
void Lockscreen::confirm()
{
m_pressed = true;
}

View File

@@ -148,8 +148,8 @@ void StatusDisplay::redraw()
m_labelBrems.redraw(String{brems});
m_progressBarBrems.redraw(brems);
m_frontStatus.redraw(front);
m_backStatus.redraw(back);
m_frontStatus.redraw(::front);
m_backStatus.redraw(::back);
tft.setTextFont(2);
m_labelWifiStatus.redraw(toString(WiFi.status()));

View File

@@ -27,7 +27,7 @@ public:
void start() override;
void initScreen() override;
void redraw() override;
void button() override;
void confirm() override;
public:
bool m_finished;
@@ -85,7 +85,7 @@ void UpdateDisplay::redraw()
m_progressBar.redraw(float(m_progress) / m_total * 100.f);
}
void UpdateDisplay::button()
void UpdateDisplay::confirm()
{
if (m_finished)
switchScreen<StatusDisplay>();

View File

@@ -22,7 +22,7 @@ public:
void stop() override;
void rotate(int offset) override;
void button() override;
void confirm() override;
virtual void itemPressed(int index);
@@ -241,7 +241,7 @@ void MenuDisplay::rotate(int offset)
m_rotateOffset += offset;
}
void MenuDisplay::button()
void MenuDisplay::confirm()
{
m_pressed = true;
}

View File

@@ -345,18 +345,32 @@ void updateDisplay()
currentDisplay->initScreen();
}
if (confirmButtonLongPressed)
{
confirmButtonLongPressed = false;
Serial.println("todo: implement long press");
}
if (confirmButtonPressed)
{
confirmButtonPressed = false;
if (currentDisplay)
currentDisplay->button();
currentDisplay->confirm();
}
if (confirmButtonLongPressed)
{
confirmButtonLongPressed = false;
Serial.println("todo: implement long press for confirm");
}
if (backButtonPressed)
{
backButtonPressed = false;
if (currentDisplay)
currentDisplay->back();
}
if (backButtonLongPressed)
{
backButtonLongPressed = false;
Serial.println("todo: implement long press for back");
}
if (currentDisplay)