Add change value display for IP address
This commit is contained in:
@ -6,6 +6,7 @@ set(headers
|
||||
src/changevaluedisplay.h
|
||||
src/changevaluedisplay_bool.h
|
||||
src/changevaluedisplay_daylightsavingmode.h
|
||||
src/changevaluedisplay_ip_address_t.h
|
||||
src/changevaluedisplay_sntp_sync_mode_t.h
|
||||
src/changevaluedisplay_string.h
|
||||
src/changevaluedisplay_wifi_auth_mode_t.h
|
||||
@ -50,6 +51,7 @@ set(sources
|
||||
src/changevaluedisplay.cpp
|
||||
src/changevaluedisplay_bool.cpp
|
||||
src/changevaluedisplay_daylightsavingmode.cpp
|
||||
src/changevaluedisplay_ip_address_t.cpp
|
||||
src/changevaluedisplay_sntp_sync_mode_t.cpp
|
||||
src/changevaluedisplay_string.cpp
|
||||
src/changevaluedisplay_wifi_auth_mode_t.cpp
|
||||
|
@ -77,7 +77,7 @@ void ChangeValueDisplay<Tvalue>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
m_value = /*static_cast<AccessorInterface<Tvalue>*>*/(this)->getValue();
|
||||
m_value = this->getValue();
|
||||
|
||||
m_rotateOffset = 0;
|
||||
m_pressed = false;
|
||||
@ -93,7 +93,7 @@ void ChangeValueDisplay<Tvalue>::update()
|
||||
const auto rotateOffset = m_rotateOffset;
|
||||
m_rotateOffset = 0;
|
||||
|
||||
m_value -= rotateOffset * /*static_cast<ChangeValueDisplaySettingsInterface<Tvalue>*>*/(this)->step();
|
||||
m_value -= rotateOffset * this->step();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
63
src/changevaluedisplay_ip_address_t.cpp
Normal file
63
src/changevaluedisplay_ip_address_t.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "changevaluedisplay_ip_address_t.h"
|
||||
|
||||
// local includes
|
||||
#include "tftinstance.h"
|
||||
|
||||
void espgui::ChangeValueDisplay<wifi_stack::ip_address_t>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
m_value = this->getValue();
|
||||
|
||||
m_pressed = false;
|
||||
}
|
||||
|
||||
void espgui::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);
|
||||
}
|
||||
|
||||
void espgui::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());
|
||||
}
|
||||
}
|
||||
|
||||
void espgui::ChangeValueDisplay<wifi_stack::ip_address_t>::redraw()
|
||||
{
|
||||
Base::redraw();
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
tft.setTextFont(4);
|
||||
m_valueLabel.redraw(wifi_stack::toString(m_value));
|
||||
}
|
||||
|
||||
void espgui::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;
|
||||
default:;
|
||||
}
|
||||
}
|
47
src/changevaluedisplay_ip_address_t.h
Normal file
47
src/changevaluedisplay_ip_address_t.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <espwifiutils.h>
|
||||
|
||||
// local includes
|
||||
#include "changevaluedisplay.h"
|
||||
#include "displaywithtitle.h"
|
||||
#include "confirminterface.h"
|
||||
#include "backinterface.h"
|
||||
#include "errorhandlerinterface.h"
|
||||
#include "widgets/label.h"
|
||||
|
||||
namespace espgui {
|
||||
|
||||
template<>
|
||||
class ChangeValueDisplay<wifi_stack::ip_address_t> :
|
||||
public DisplayWithTitle,
|
||||
public virtual AccessorInterface<wifi_stack::ip_address_t>,
|
||||
public virtual ConfirmInterface,
|
||||
public virtual BackInterface,
|
||||
public virtual ErrorHandlerInterface
|
||||
{
|
||||
using Base = DisplayWithTitle;
|
||||
|
||||
public:
|
||||
ChangeValueDisplay<wifi_stack::ip_address_t> *asChangeValueDisplayIpAddress() override { return this; }
|
||||
const ChangeValueDisplay<wifi_stack::ip_address_t> *asChangeValueDisplayIpAddress() const override { return this; }
|
||||
|
||||
void start() override;
|
||||
void initScreen() override;
|
||||
void update() override;
|
||||
void redraw() override;
|
||||
|
||||
void buttonPressed(Button button) override;
|
||||
|
||||
wifi_stack::ip_address_t shownValue() const { return m_value; }
|
||||
void setShownValue(wifi_stack::ip_address_t value) { m_value = value; }
|
||||
|
||||
private:
|
||||
wifi_stack::ip_address_t m_value;
|
||||
bool m_pressed{};
|
||||
|
||||
Label m_valueLabel{26, 81}; // 188, 53
|
||||
};
|
||||
|
||||
} // namespace espgui
|
@ -7,7 +7,7 @@ void espgui::ChangeValueDisplay<std::string>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
m_value = /*static_cast<AccessorInterface<std::string>*>*/(this)->getValue();
|
||||
m_value = this->getValue();
|
||||
|
||||
m_pressed = false;
|
||||
}
|
||||
@ -34,7 +34,7 @@ void espgui::ChangeValueDisplay<std::string>::update()
|
||||
if (m_pressed)
|
||||
{
|
||||
m_pressed = false;
|
||||
if (auto result = /*static_cast<AccessorInterface<std::string>*>*/(this)->setValue(m_value); result)
|
||||
if (auto result = this->setValue(m_value); result)
|
||||
confirm();
|
||||
else
|
||||
errorOccured(std::move(result).error());
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
|
||||
// local includes
|
||||
#include "changevaluedisplay.h"
|
||||
#include "displaywithtitle.h"
|
||||
|
@ -14,6 +14,9 @@ class MenuDisplay;
|
||||
class ChangeValueDisplayInterface;
|
||||
template<typename Tvalue> class ChangeValueDisplay;
|
||||
} // namespace espgui
|
||||
namespace wifi_stack {
|
||||
class ip_address_t;
|
||||
} // namespace wifi_stack
|
||||
|
||||
namespace espgui {
|
||||
|
||||
@ -32,6 +35,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename ...T4>
|
||||
class makeComponentArgs2 : public T1, public T2, public T3, public T4...
|
||||
{
|
||||
public:
|
||||
template<typename Targ1, typename Targ2>
|
||||
makeComponentArgs2(Targ1&& arg1, Targ2&& arg2) :
|
||||
T2{std::forward<Targ1>(arg1)},
|
||||
T3{std::forward<Targ2>(arg2)}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class Display : public virtual ButtonsInterface
|
||||
{
|
||||
public:
|
||||
@ -63,6 +78,9 @@ public:
|
||||
|
||||
virtual ChangeValueDisplay<std::string> *asChangeValueDisplayString() { return nullptr; }
|
||||
virtual const ChangeValueDisplay<std::string> *asChangeValueDisplayString() const { return nullptr; }
|
||||
|
||||
virtual ChangeValueDisplay<wifi_stack::ip_address_t> *asChangeValueDisplayIpAddress() { return nullptr; }
|
||||
virtual const ChangeValueDisplay<wifi_stack::ip_address_t> *asChangeValueDisplayIpAddress() const { return nullptr; }
|
||||
};
|
||||
|
||||
} // namespace espgui
|
||||
|
@ -13,15 +13,17 @@
|
||||
namespace espgui {
|
||||
|
||||
template<const char *Tprefix, typename Taccessor>
|
||||
struct TextWithValueHelper : public virtual TextInterface
|
||||
struct TextWithValueHelper : public Taccessor, public virtual TextInterface
|
||||
{
|
||||
using Taccessor::Taccessor;
|
||||
|
||||
std::string text() const override
|
||||
{
|
||||
using cpputils::toString;
|
||||
using espcpputils::toString;
|
||||
using wifi_stack::toString;
|
||||
|
||||
return fmt::format("{} {}", Tprefix, richTextEscape(toString(Taccessor{}.getValue())));
|
||||
return fmt::format("{} {}", Tprefix, richTextEscape(toString(Taccessor::getValue())));
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user