Implemented ChangeValueDisplay for IPs
This commit is contained in:
@@ -103,6 +103,8 @@ void ChangeValueDisplayChrono<T>::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:;
|
||||
}
|
||||
}
|
||||
|
@@ -3,68 +3,112 @@
|
||||
// local includes
|
||||
#include "tftinstance.h"
|
||||
|
||||
void espgui::ChangeValueDisplay<wifi_stack::ip_address_t>::start()
|
||||
namespace espgui {
|
||||
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
m_value = this->getValue();
|
||||
|
||||
m_pressed = false;
|
||||
m_currentIndex = 0;
|
||||
}
|
||||
|
||||
void espgui::ChangeValueDisplay<wifi_stack::ip_address_t>::initScreen()
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::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<wifi_stack::ip_address_t>::update()
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::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<wifi_stack::ip_address_t>::redraw()
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::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<wifi_stack::ip_address_t>::buttonPressed(Button button)
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::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<wifi_stack::ip_address_t>::buttonReleased(Button button)
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::buttonReleased(Button button)
|
||||
{
|
||||
//Base::buttonReleased(button);
|
||||
|
||||
// TODO stop auto scroll
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<wifi_stack::ip_address_t>::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
|
||||
|
@@ -23,6 +23,12 @@ class ChangeValueDisplay<wifi_stack::ip_address_t> :
|
||||
{
|
||||
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<wifi_stack::ip_address_t> *asChangeValueDisplayIpAddress() override { return this; }
|
||||
const ChangeValueDisplay<wifi_stack::ip_address_t> *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<espgui::Label, 4> 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
|
||||
|
Reference in New Issue
Block a user