Files
esp-gui-lib/src/splitgraphdisplay.h
T

108 lines
2.8 KiB
C++
Raw Normal View History

2021-11-02 16:11:37 +01:00
#pragma once
2021-12-28 13:40:56 +01:00
// local includes
2021-11-02 16:11:37 +01:00
#include "display.h"
#include "tftinterface.h"
#include "tftcolors.h"
2021-11-02 16:11:37 +01:00
#include "textinterface.h"
#include "widgets/label.h"
#include "widgets/graph.h"
2021-12-28 13:40:56 +01:00
#include "confirminterface.h"
#include "backinterface.h"
2021-11-02 16:11:37 +01:00
namespace espgui {
2021-12-28 13:40:56 +01:00
2021-11-02 16:11:37 +01:00
template<std::size_t COUNT>
class TopGraphAccessorInterface
{
public:
virtual typename Graph<200, COUNT>::Container getTopBuffers() const = 0;
};
template<typename T>
class SingleTopGraphAccessor : public virtual TopGraphAccessorInterface<1>
{
public:
typename Graph<200, 1>::Container getTopBuffers() const override
{
return {T{}.getBuffer()};
}
};
template<std::size_t COUNT>
class BottomGraphAccessorInterface
{
public:
virtual typename Graph<200, COUNT>::Container getBottomBuffers() const = 0;
};
template<typename T>
class SingleBottomGraphAccessor : public virtual BottomGraphAccessorInterface<1>
{
public:
typename Graph<200, 1>::Container getBottomBuffers() const override
{
return {T{}.getBuffer()};
}
};
template<std::size_t COUNT0, std::size_t COUNT1>
class SplitGraphDisplay :
2021-12-28 13:40:56 +01:00
public Display,
public virtual TextInterface,
public virtual TopGraphAccessorInterface<COUNT0>,
public virtual BottomGraphAccessorInterface<COUNT1>,
public virtual ConfirmInterface,
public virtual BackInterface
2021-11-02 16:11:37 +01:00
{
using Base = Display;
2021-11-02 16:11:37 +01:00
public:
void initScreen(TftInterface &tft) override;
void redraw(TftInterface &tft) override;
2021-11-02 16:11:37 +01:00
2021-12-28 13:40:56 +01:00
void buttonPressed(Button button) override;
2021-11-02 16:11:37 +01:00
private:
Label m_titleLabel{5, 5}; // 230, 25
Graph<200, COUNT0> m_graph0{0, 40, 133};
Graph<200, COUNT1> m_graph1{0, 179, 133};
};
template<std::size_t COUNT0, std::size_t COUNT1>
void SplitGraphDisplay<COUNT0, COUNT1>::initScreen(TftInterface &tft)
2021-11-02 16:11:37 +01:00
{
Base::initScreen(tft);
2021-11-02 16:11:37 +01:00
2022-12-25 02:57:51 +01:00
m_titleLabel.start(tft);
2021-11-02 16:11:37 +01:00
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
2022-12-25 02:57:51 +01:00
m_graph0.start(tft, static_cast<const TopGraphAccessorInterface<COUNT0>&>(*this).getTopBuffers());
m_graph1.start(tft, static_cast<const BottomGraphAccessorInterface<COUNT1>&>(*this).getBottomBuffers());
2021-11-02 16:11:37 +01:00
}
template<std::size_t COUNT0, std::size_t COUNT1>
void SplitGraphDisplay<COUNT0, COUNT1>::redraw(TftInterface &tft)
2021-11-02 16:11:37 +01:00
{
2022-12-25 02:57:51 +01:00
m_titleLabel.redraw(tft, text(), TFT_YELLOW, TFT_BLACK, 4);
2021-11-02 16:11:37 +01:00
2022-12-25 02:57:51 +01:00
m_graph0.redraw(tft, static_cast<const TopGraphAccessorInterface<COUNT0>&>(*this).getTopBuffers());
m_graph1.redraw(tft, static_cast<const BottomGraphAccessorInterface<COUNT1>&>(*this).getBottomBuffers());
2021-11-02 16:11:37 +01:00
}
2021-12-28 13:40:56 +01:00
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:;
}
2021-11-02 16:11:37 +01:00
}
2021-12-28 13:40:56 +01:00
} // namespace espgui