Added ChangeValueDisplay for string
This commit is contained in:
@@ -7,6 +7,7 @@ set(headers
|
|||||||
src/changevaluedisplay_bool.h
|
src/changevaluedisplay_bool.h
|
||||||
src/changevaluedisplay_daylightsavingmode.h
|
src/changevaluedisplay_daylightsavingmode.h
|
||||||
src/changevaluedisplay_sntp_sync_mode_t.h
|
src/changevaluedisplay_sntp_sync_mode_t.h
|
||||||
|
src/changevaluedisplay_string.h
|
||||||
src/changevaluedisplay_wifi_auth_mode_t.h
|
src/changevaluedisplay_wifi_auth_mode_t.h
|
||||||
src/changevaluedisplay_wifi_mode_t.h
|
src/changevaluedisplay_wifi_mode_t.h
|
||||||
src/checkboxicon.h
|
src/checkboxicon.h
|
||||||
@@ -50,6 +51,7 @@ set(sources
|
|||||||
src/changevaluedisplay_bool.cpp
|
src/changevaluedisplay_bool.cpp
|
||||||
src/changevaluedisplay_daylightsavingmode.cpp
|
src/changevaluedisplay_daylightsavingmode.cpp
|
||||||
src/changevaluedisplay_sntp_sync_mode_t.cpp
|
src/changevaluedisplay_sntp_sync_mode_t.cpp
|
||||||
|
src/changevaluedisplay_string.cpp
|
||||||
src/changevaluedisplay_wifi_auth_mode_t.cpp
|
src/changevaluedisplay_wifi_auth_mode_t.cpp
|
||||||
src/changevaluedisplay_wifi_mode_t.cpp
|
src/changevaluedisplay_wifi_mode_t.cpp
|
||||||
src/display.cpp
|
src/display.cpp
|
||||||
|
@@ -77,7 +77,7 @@ void ChangeValueDisplay<Tvalue>::start()
|
|||||||
{
|
{
|
||||||
Base::start();
|
Base::start();
|
||||||
|
|
||||||
m_value = static_cast<AccessorInterface<Tvalue>*>(this)->getValue();
|
m_value = /*static_cast<AccessorInterface<Tvalue>*>*/(this)->getValue();
|
||||||
|
|
||||||
m_rotateOffset = 0;
|
m_rotateOffset = 0;
|
||||||
m_pressed = false;
|
m_pressed = false;
|
||||||
@@ -93,7 +93,7 @@ void ChangeValueDisplay<Tvalue>::update()
|
|||||||
const auto rotateOffset = m_rotateOffset;
|
const auto rotateOffset = m_rotateOffset;
|
||||||
m_rotateOffset = 0;
|
m_rotateOffset = 0;
|
||||||
|
|
||||||
m_value -= rotateOffset * static_cast<ChangeValueDisplaySettingsInterface<Tvalue>*>(this)->step();
|
m_value -= rotateOffset * /*static_cast<ChangeValueDisplaySettingsInterface<Tvalue>*>*/(this)->step();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
63
src/changevaluedisplay_string.cpp
Normal file
63
src/changevaluedisplay_string.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "changevaluedisplay_string.h"
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "tftinstance.h"
|
||||||
|
|
||||||
|
void espgui::ChangeValueDisplay<std::string>::start()
|
||||||
|
{
|
||||||
|
Base::start();
|
||||||
|
|
||||||
|
m_value = /*static_cast<AccessorInterface<std::string>*>*/(this)->getValue();
|
||||||
|
|
||||||
|
m_pressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void espgui::ChangeValueDisplay<std::string>::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<std::string>::update()
|
||||||
|
{
|
||||||
|
Base::update();
|
||||||
|
|
||||||
|
if (m_pressed)
|
||||||
|
{
|
||||||
|
m_pressed = false;
|
||||||
|
if (auto result = /*static_cast<AccessorInterface<std::string>*>*/(this)->setValue(m_value); result)
|
||||||
|
confirm();
|
||||||
|
else
|
||||||
|
errorOccured(std::move(result).error());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void espgui::ChangeValueDisplay<std::string>::redraw()
|
||||||
|
{
|
||||||
|
Base::redraw();
|
||||||
|
|
||||||
|
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
tft.setTextFont(4);
|
||||||
|
m_valueLabel.redraw(m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void espgui::ChangeValueDisplay<std::string>::buttonPressed(Button button)
|
||||||
|
{
|
||||||
|
//Base::buttonPressed(button);
|
||||||
|
|
||||||
|
switch (button)
|
||||||
|
{
|
||||||
|
case Button::Left: this->back(); break;
|
||||||
|
case Button::Right: m_pressed = true; break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
}
|
44
src/changevaluedisplay_string.h
Normal file
44
src/changevaluedisplay_string.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 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<std::string> :
|
||||||
|
public DisplayWithTitle,
|
||||||
|
public virtual AccessorInterface<std::string>,
|
||||||
|
public virtual ConfirmInterface,
|
||||||
|
public virtual BackInterface,
|
||||||
|
public virtual ErrorHandlerInterface
|
||||||
|
{
|
||||||
|
using Base = DisplayWithTitle;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ChangeValueDisplay<std::string> *asChangeValueDisplayString() override { return this; }
|
||||||
|
const ChangeValueDisplay<std::string> *asChangeValueDisplayString() const override { return this; }
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
void initScreen() override;
|
||||||
|
void update() override;
|
||||||
|
void redraw() override;
|
||||||
|
|
||||||
|
void buttonPressed(Button button) override;
|
||||||
|
|
||||||
|
const std::string &shownValue() const { return m_value; }
|
||||||
|
void setShownValue(std::string &&value) { m_value = std::move(value); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_value;
|
||||||
|
bool m_pressed{};
|
||||||
|
|
||||||
|
Label m_valueLabel{26, 81}; // 188, 53
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace espgui
|
@@ -12,9 +12,11 @@ namespace espgui {
|
|||||||
class TextInterface;
|
class TextInterface;
|
||||||
class MenuDisplay;
|
class MenuDisplay;
|
||||||
class ChangeValueDisplayInterface;
|
class ChangeValueDisplayInterface;
|
||||||
}
|
template<typename Tvalue> class ChangeValueDisplay;
|
||||||
|
} // namespace espgui
|
||||||
|
|
||||||
namespace espgui {
|
namespace espgui {
|
||||||
|
|
||||||
template<typename ...T>
|
template<typename ...T>
|
||||||
class makeComponent : public T...
|
class makeComponent : public T...
|
||||||
{};
|
{};
|
||||||
@@ -58,5 +60,9 @@ public:
|
|||||||
|
|
||||||
virtual ChangeValueDisplayInterface *asChangeValueDisplayInterface() { return nullptr; }
|
virtual ChangeValueDisplayInterface *asChangeValueDisplayInterface() { return nullptr; }
|
||||||
virtual const ChangeValueDisplayInterface *asChangeValueDisplayInterface() const { return nullptr; }
|
virtual const ChangeValueDisplayInterface *asChangeValueDisplayInterface() const { return nullptr; }
|
||||||
|
|
||||||
|
virtual ChangeValueDisplay<std::string> *asChangeValueDisplayString() { return nullptr; }
|
||||||
|
virtual const ChangeValueDisplay<std::string> *asChangeValueDisplayString() const { return nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
Reference in New Issue
Block a user