More button improvements

This commit is contained in:
2021-12-28 13:40:56 +01:00
parent 4cb29d1d3b
commit 3d01a04aa4
8 changed files with 69 additions and 25 deletions

View File

@@ -2,6 +2,7 @@ set(headers
src/accessorinterface.h src/accessorinterface.h
src/actioninterface.h src/actioninterface.h
src/backinterface.h src/backinterface.h
src/buttonsinterface.h
src/changevaluedisplay.h src/changevaluedisplay.h
src/changevaluedisplay_bool.h src/changevaluedisplay_bool.h
src/changevaluedisplay_daylightsavingmode.h src/changevaluedisplay_daylightsavingmode.h

27
src/buttonsinterface.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
//system includes
#include <cstdint>
namespace espgui {
enum Button
{
Left,
Right,
Up,
Down,
ButtonMax = Down
};
class ButtonsInterface
{
public:
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;
};
} // namespace espgui

View File

@@ -10,6 +10,7 @@
#include "backinterface.h" #include "backinterface.h"
namespace espgui { namespace espgui {
class ChangeValueDisplayInterface : class ChangeValueDisplayInterface :
public DisplayWithTitle, public DisplayWithTitle,
public virtual ActionInterface public virtual ActionInterface
@@ -115,7 +116,7 @@ void ChangeValueDisplay<float>::redraw();
template<typename Tvalue> template<typename Tvalue>
void ChangeValueDisplay<Tvalue>::buttonPressed(Button button) void ChangeValueDisplay<Tvalue>::buttonPressed(Button button)
{ {
Base::buttonPressed(button); //Base::buttonPressed(button);
switch (button) switch (button)
{ {
@@ -125,4 +126,5 @@ void ChangeValueDisplay<Tvalue>::buttonPressed(Button button)
case Button::Down: m_rotateOffset++; break; case Button::Down: m_rotateOffset++; break;
} }
} }
} // namespace espgui } // namespace espgui

View File

@@ -4,6 +4,9 @@
#include <string> #include <string>
#include <cstdint> #include <cstdint>
// local includes
#include "buttonsinterface.h"
// forward declares // forward declares
namespace espgui { namespace espgui {
class TextInterface; class TextInterface;
@@ -27,16 +30,7 @@ public:
} }
}; };
enum Button class Display : public virtual ButtonsInterface
{
Left,
Right,
Up,
Down,
ButtonMax = Down
};
class Display
{ {
public: public:
virtual ~Display() = default; virtual ~Display() = default;
@@ -56,12 +50,6 @@ public:
//! Display goes out of existance, is not shown anymore //! Display goes out of existance, is not shown anymore
virtual void stop() {} virtual void stop() {}
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; }

View File

@@ -13,6 +13,7 @@
#include "backinterface.h" #include "backinterface.h"
namespace espgui { namespace espgui {
template<size_t COUNT> template<size_t COUNT>
class GraphAccessorInterface class GraphAccessorInterface
{ {
@@ -81,7 +82,7 @@ void GraphDisplay<COUNT>::redraw()
template<size_t COUNT> template<size_t COUNT>
void GraphDisplay<COUNT>::buttonPressed(Button button) void GraphDisplay<COUNT>::buttonPressed(Button button)
{ {
Base::buttonPressed(button); //Base::buttonPressed(button);
switch (button) switch (button)
{ {
@@ -90,4 +91,5 @@ void GraphDisplay<COUNT>::buttonPressed(Button button)
default:; default:;
} }
} }
}
} // namespace espgui

View File

@@ -174,7 +174,7 @@ void MenuDisplay::stop()
void MenuDisplay::buttonPressed(Button button) void MenuDisplay::buttonPressed(Button button)
{ {
Base::buttonPressed(button); //Base::buttonPressed(button);
switch (button) switch (button)
{ {

View File

@@ -17,7 +17,9 @@
#include "backinterface.h" #include "backinterface.h"
namespace espgui { namespace espgui {
class MenuDisplay : public DisplayWithTitle, public virtual BackInterface class MenuDisplay :
public DisplayWithTitle,
public virtual BackInterface
{ {
using Base = DisplayWithTitle; using Base = DisplayWithTitle;

View File

@@ -1,11 +1,15 @@
#pragma once #pragma once
// local includes
#include "display.h" #include "display.h"
#include "textinterface.h" #include "textinterface.h"
#include "widgets/label.h" #include "widgets/label.h"
#include "widgets/graph.h" #include "widgets/graph.h"
#include "confirminterface.h"
#include "backinterface.h"
namespace espgui { namespace espgui {
template<std::size_t COUNT> template<std::size_t COUNT>
class TopGraphAccessorInterface class TopGraphAccessorInterface
{ {
@@ -42,15 +46,19 @@ public:
template<std::size_t COUNT0, std::size_t COUNT1> template<std::size_t COUNT0, std::size_t COUNT1>
class SplitGraphDisplay : class SplitGraphDisplay :
public Display, public Display,
public virtual TextInterface, public virtual TextInterface,
public virtual TopGraphAccessorInterface<COUNT0>, public virtual TopGraphAccessorInterface<COUNT0>,
public virtual BottomGraphAccessorInterface<COUNT1> public virtual BottomGraphAccessorInterface<COUNT1>,
public virtual ConfirmInterface,
public virtual BackInterface
{ {
public: public:
void initScreen() override; void initScreen() override;
void redraw() override; void redraw() override;
void buttonPressed(Button button) override;
private: private:
Label m_titleLabel{5, 5}; // 230, 25 Label m_titleLabel{5, 5}; // 230, 25
@@ -80,4 +88,18 @@ void SplitGraphDisplay<COUNT0, COUNT1>::redraw()
m_graph0.redraw(static_cast<const TopGraphAccessorInterface<COUNT0>&>(*this).getTopBuffers()); m_graph0.redraw(static_cast<const TopGraphAccessorInterface<COUNT0>&>(*this).getTopBuffers());
m_graph1.redraw(static_cast<const BottomGraphAccessorInterface<COUNT1>&>(*this).getBottomBuffers()); m_graph1.redraw(static_cast<const BottomGraphAccessorInterface<COUNT1>&>(*this).getBottomBuffers());
} }
template<std::size_t COUNT0, std::size_t COUNT1>
void SplitGraphDisplay<COUNT0, COUNT1>::buttonPressed(Button button)
{
//Base::buttonPressed(button);
switch (button)
{
case Button::Left: back(); break;
case Button::Right: confirm(); break;
default:;
}
} }
} // namespace espgui