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