New button interface
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
set(headers
|
||||
src/accessorinterface.h
|
||||
src/actioninterface.h
|
||||
src/backinterface.h
|
||||
src/changevaluedisplay.h
|
||||
src/changevaluedisplay_bool.h
|
||||
src/changevaluedisplay_daylightsavingmode.h
|
||||
src/changevaluedisplay_sntp_sync_mode_t.h
|
||||
src/checkboxicon.h
|
||||
src/colorinterface.h
|
||||
src/confirminterface.h
|
||||
src/display.h
|
||||
src/displaywithtitle.h
|
||||
src/fontinterface.h
|
||||
|
24
src/backinterface.h
Normal file
24
src/backinterface.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
namespace espgui {
|
||||
|
||||
class BackInterface
|
||||
{
|
||||
public:
|
||||
virtual void back() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class BackActionInterface : public virtual BackInterface
|
||||
{
|
||||
public:
|
||||
void back() override { T{}.triggered(); }
|
||||
};
|
||||
|
||||
class DummyBack : public virtual BackInterface
|
||||
{
|
||||
public:
|
||||
void back() override {}
|
||||
};
|
||||
|
||||
} // namespace espgui
|
@@ -7,6 +7,7 @@
|
||||
#include "accessorinterface.h"
|
||||
#include "widgets/label.h"
|
||||
#include "tftinstance.h"
|
||||
#include "backinterface.h"
|
||||
|
||||
namespace espgui {
|
||||
class ChangeValueDisplayInterface :
|
||||
@@ -14,6 +15,7 @@ class ChangeValueDisplayInterface :
|
||||
public virtual ActionInterface
|
||||
{
|
||||
using Base = DisplayWithTitle;
|
||||
|
||||
public:
|
||||
void initScreen() override;
|
||||
|
||||
@@ -45,7 +47,8 @@ template<typename Tvalue>
|
||||
class ChangeValueDisplay :
|
||||
public ChangeValueDisplayInterface,
|
||||
public virtual AccessorInterface<Tvalue>,
|
||||
public virtual ChangeValueDisplaySettingsInterface<Tvalue>
|
||||
public virtual ChangeValueDisplaySettingsInterface<Tvalue>,
|
||||
public virtual BackInterface
|
||||
{
|
||||
using Base = ChangeValueDisplayInterface;
|
||||
|
||||
@@ -54,8 +57,7 @@ public:
|
||||
void update() override;
|
||||
void redraw() override;
|
||||
|
||||
void rotate(int offset) override;
|
||||
void confirm() override;
|
||||
void buttonPressed(Button button) override;
|
||||
|
||||
int shownValue() const { return m_value; }
|
||||
void setShownValue(int value) { m_value = value; }
|
||||
@@ -70,6 +72,8 @@ private:
|
||||
template<typename Tvalue>
|
||||
void ChangeValueDisplay<Tvalue>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
m_value = static_cast<AccessorInterface<Tvalue>*>(this)->getValue();
|
||||
|
||||
m_rotateOffset = 0;
|
||||
@@ -109,14 +113,16 @@ template<>
|
||||
void ChangeValueDisplay<float>::redraw();
|
||||
|
||||
template<typename Tvalue>
|
||||
void ChangeValueDisplay<Tvalue>::rotate(int offset)
|
||||
void ChangeValueDisplay<Tvalue>::buttonPressed(Button button)
|
||||
{
|
||||
m_rotateOffset += offset;
|
||||
}
|
||||
Base::buttonPressed(button);
|
||||
|
||||
template<typename Tvalue>
|
||||
void ChangeValueDisplay<Tvalue>::confirm()
|
||||
{
|
||||
m_pressed = true;
|
||||
switch (button)
|
||||
{
|
||||
case Button::Left: this->back(); break;
|
||||
case Button::Right: m_pressed = true; break;
|
||||
case Button::Up: m_rotateOffset--; break;
|
||||
case Button::Down: m_rotateOffset++; break;
|
||||
}
|
||||
}
|
||||
} // namespace espgui
|
||||
|
24
src/confirminterface.h
Normal file
24
src/confirminterface.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
namespace espgui {
|
||||
|
||||
class ConfirmInterface
|
||||
{
|
||||
public:
|
||||
virtual void confirm() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ConfirmActionInterface : public virtual ConfirmInterface
|
||||
{
|
||||
public:
|
||||
void confirm() override { T{}.triggered(); }
|
||||
};
|
||||
|
||||
class DummyConfirm : public virtual ConfirmInterface
|
||||
{
|
||||
public:
|
||||
void confirm() override {}
|
||||
};
|
||||
|
||||
} // namespace espgui
|
@@ -2,6 +2,7 @@
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
// forward declares
|
||||
namespace espgui {
|
||||
@@ -26,58 +27,40 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ConfirmInterface
|
||||
enum Button
|
||||
{
|
||||
public:
|
||||
virtual void confirm() = 0;
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
ButtonMax = Down
|
||||
};
|
||||
|
||||
class BackInterface
|
||||
{
|
||||
public:
|
||||
virtual void back() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ConfirmActionInterface : public virtual ConfirmInterface
|
||||
{
|
||||
public:
|
||||
void confirm() override { T{}.triggered(); }
|
||||
};
|
||||
|
||||
class DummyConfirm : public virtual ConfirmInterface
|
||||
{
|
||||
public:
|
||||
void confirm() override {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class BackActionInterface : public virtual BackInterface
|
||||
{
|
||||
public:
|
||||
void back() override { T{}.triggered(); }
|
||||
};
|
||||
|
||||
class DummyBack : public virtual BackInterface
|
||||
{
|
||||
public:
|
||||
void back() override {}
|
||||
};
|
||||
|
||||
class Display :
|
||||
public virtual ConfirmInterface,
|
||||
public virtual BackInterface
|
||||
class Display
|
||||
{
|
||||
public:
|
||||
virtual ~Display() = default;
|
||||
|
||||
//! Display comes into existance, is shown
|
||||
virtual void start() {}
|
||||
|
||||
//! Display needs to fully initialize screen
|
||||
virtual void initScreen();
|
||||
|
||||
//! Display can do work needed to update correctly
|
||||
virtual void update() {}
|
||||
|
||||
//! Display can update screen incrementally
|
||||
virtual void redraw() {}
|
||||
|
||||
//! Display goes out of existance, is not shown anymore
|
||||
virtual void stop() {}
|
||||
|
||||
virtual void rotate(int offset) {}
|
||||
virtual void rawButtonPressed(uint8_t button) = 0;
|
||||
virtual void rawButtonReleased(uint8_t button) = 0;
|
||||
|
||||
virtual void buttonPressed(Button button) = 0;
|
||||
virtual void buttonReleased(Button button) = 0;
|
||||
|
||||
virtual TextInterface *asTextInterface() { return nullptr; }
|
||||
virtual const TextInterface *asTextInterface() const { return nullptr; }
|
||||
|
@@ -172,15 +172,16 @@ void MenuDisplay::stop()
|
||||
});
|
||||
}
|
||||
|
||||
void MenuDisplay::rotate(int offset)
|
||||
void MenuDisplay::buttonPressed(Button button)
|
||||
{
|
||||
Base::rotate(offset);
|
||||
m_rotateOffset += offset;
|
||||
}
|
||||
Base::buttonPressed(button);
|
||||
|
||||
void MenuDisplay::confirm()
|
||||
{
|
||||
//Base::confirm();
|
||||
m_pressed = true;
|
||||
switch (button)
|
||||
{
|
||||
case Button::Left: this->back(); break;
|
||||
case Button::Right: m_pressed = true; break;
|
||||
case Button::Up: m_rotateOffset--; break;
|
||||
case Button::Down: m_rotateOffset++; break;
|
||||
}
|
||||
}
|
||||
} // namespace espgui
|
||||
|
@@ -14,9 +14,10 @@
|
||||
#include "textinterface.h"
|
||||
#include "widgets/label.h"
|
||||
#include "menuitem.h"
|
||||
#include "backinterface.h"
|
||||
|
||||
namespace espgui {
|
||||
class MenuDisplay : public DisplayWithTitle
|
||||
class MenuDisplay : public DisplayWithTitle, public virtual BackInterface
|
||||
{
|
||||
using Base = DisplayWithTitle;
|
||||
|
||||
@@ -27,8 +28,7 @@ public:
|
||||
void redraw() override;
|
||||
void stop() override;
|
||||
|
||||
void rotate(int offset) override;
|
||||
void confirm() override;
|
||||
void buttonPressed(Button button) override;
|
||||
|
||||
MenuDisplay *asMenuDisplay() override { return this; }
|
||||
const MenuDisplay *asMenuDisplay() const override { return this; }
|
||||
|
Reference in New Issue
Block a user