diff --git a/src/changevaluedisplay_chrono.h b/src/changevaluedisplay_chrono.h index 858463f..96dc67d 100644 --- a/src/changevaluedisplay_chrono.h +++ b/src/changevaluedisplay_chrono.h @@ -103,6 +103,8 @@ void ChangeValueDisplayChrono::buttonPressed(Button button) { case Button::Left: this->back(); break; case Button::Right: m_pressed = true; break; + case Button::Up: m_value += T{1}; break; + case Button::Down: m_value -= T{1}; break; default:; } } diff --git a/src/changevaluedisplay_ip_address_t.cpp b/src/changevaluedisplay_ip_address_t.cpp index 6b00662..9e10b64 100644 --- a/src/changevaluedisplay_ip_address_t.cpp +++ b/src/changevaluedisplay_ip_address_t.cpp @@ -3,68 +3,112 @@ // local includes #include "tftinstance.h" -void espgui::ChangeValueDisplay::start() +namespace espgui { + +void ChangeValueDisplay::start() { Base::start(); m_value = this->getValue(); - m_pressed = false; + m_currentIndex = 0; } -void espgui::ChangeValueDisplay::initScreen() +void ChangeValueDisplay::initScreen() { Base::initScreen(); - tft.drawRect(25, 75, 190, 65, TFT_WHITE); - m_valueLabel.start(); - - tft.setTextFont(4); tft.setTextColor(TFT_WHITE); - tft.drawString("Change value and", 10, 160); - tft.drawString("press button to", 10, 185); - tft.drawString("confirm and go", 10, 210); - tft.drawString("back.", 10, 235); + tft.drawString("Change IP", 0, 50); + + for(int i = 0; i <= 3; i++) + { + drawRect(i, 3, TFT_WHITE); + drawRect(i, 4, TFT_WHITE); + } + + for (auto &label : m_labels) + label.start(); + + drawRect(m_currentIndex, 1, TFT_YELLOW); + drawRect(m_currentIndex, 2, TFT_YELLOW); + + m_lastIndex = m_currentIndex; } -void espgui::ChangeValueDisplay::update() +void ChangeValueDisplay::update() { Base::update(); - if (m_pressed) - { - m_pressed = false; - if (auto result = this->setValue(m_value); result) - confirm(); - else - errorOccured(std::move(result).error()); - } + // TODO auto scroll } -void espgui::ChangeValueDisplay::redraw() +void ChangeValueDisplay::redraw() { Base::redraw(); tft.setTextColor(TFT_WHITE, TFT_BLACK); + + if (m_lastIndex != m_currentIndex) + { + drawRect(m_lastIndex, 1, TFT_BLACK); + drawRect(m_lastIndex, 2, TFT_BLACK); + + drawRect(m_currentIndex, 1, TFT_YELLOW); + drawRect(m_currentIndex, 2, TFT_YELLOW); + + m_lastIndex = m_currentIndex; + } + tft.setTextFont(4); - m_valueLabel.redraw(wifi_stack::toString(m_value)); + + for (auto i = 0; i < 4; i++) + m_labels[i].redraw(std::to_string(m_value.bytes()[i])); } -void espgui::ChangeValueDisplay::buttonPressed(Button button) +void ChangeValueDisplay::buttonPressed(Button button) { //Base::buttonPressed(button); switch (button) { - case Button::Left: this->back(); break; - case Button::Right: m_pressed = true; break; + case Button::Left: + if (m_currentIndex > 0) + m_currentIndex--; + else + back(); + break; + case Button::Right: + if (m_currentIndex < 3) + m_currentIndex++; + else + { + if (auto result = this->setValue(m_value); result) + confirm(); + else + errorOccured(std::move(result).error()); + } + break; + case Button::Up: + m_value.bytes()[m_currentIndex]++; + break; + case Button::Down: + m_value.bytes()[m_currentIndex]--; + break; default:; } } -void espgui::ChangeValueDisplay::buttonReleased(Button button) +void ChangeValueDisplay::buttonReleased(Button button) { //Base::buttonReleased(button); // TODO stop auto scroll } + +void ChangeValueDisplay::drawRect(int index, int offset, uint32_t color) const +{ + tft.drawRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), color); +} + +} // namespace espgui diff --git a/src/changevaluedisplay_ip_address_t.h b/src/changevaluedisplay_ip_address_t.h index 6ad1168..4191e5d 100644 --- a/src/changevaluedisplay_ip_address_t.h +++ b/src/changevaluedisplay_ip_address_t.h @@ -23,6 +23,12 @@ class ChangeValueDisplay : { using Base = DisplayWithTitle; + static constexpr auto boxWidth = 50; + static constexpr auto boxHeight = 25; + static constexpr auto spacing = 20; + + static constexpr auto y = 90; + public: ChangeValueDisplay *asChangeValueDisplayIpAddress() override { return this; } const ChangeValueDisplay *asChangeValueDisplayIpAddress() const override { return this; } @@ -39,10 +45,19 @@ public: void setShownValue(wifi_stack::ip_address_t value) { m_value = value; } private: - wifi_stack::ip_address_t m_value; - bool m_pressed{}; + void drawRect(int index, int offset, uint32_t color) const; - Label m_valueLabel{26, 81}; // 188, 53 + wifi_stack::ip_address_t m_value; + + std::array m_labels {{ + espgui::Label{spacing, y}, // boxWidth, boxHeight + espgui::Label{spacing*2+boxWidth, y}, // boxWidth, boxHeight + espgui::Label{spacing*3+boxWidth*2, y}, // boxWidth, boxHeight + espgui::Label{spacing*4+boxWidth*3, y} // boxWidth, boxHeight + }}; + + uint8_t m_currentIndex{}; + uint8_t m_lastIndex{}; }; } // namespace espgui