Added DisplayWithTitle

This commit is contained in:
2021-11-01 22:21:29 +01:00
parent 1bf5aec0fd
commit aad3fcedcb
9 changed files with 102 additions and 38 deletions

View File

@ -8,6 +8,7 @@ set(headers
src/checkboxicon.h
src/colorinterface.h
src/display.h
src/displaywithtitle.h
src/fontinterface.h
src/icon.h
src/iconinterface.h
@ -38,6 +39,8 @@ set(sources
src/changevaluedisplay_bool.cpp
src/changevaluedisplay_daylightsavingmode.cpp
src/changevaluedisplay_sntp_sync_mode_t.cpp
src/display.cpp
src/displaywithtitle.cpp
src/menudisplay.cpp
src/screenmanager.cpp
src/richtextrenderer.cpp

View File

@ -1,13 +1,12 @@
#include "changevaluedisplay.h"
// 3rdparty lib includes
#include <fmt/core.h>
namespace espgui {
void ChangeValueDisplayInterface::initScreen()
{
tft.fillScreen(TFT_BLACK);
m_titleLabel.start();
tft.fillRect(0, 33, tft.width(), 3, TFT_WHITE);
Base::initScreen();
tft.drawRect(25, 75, 190, 65, TFT_WHITE);
m_valueLabel.start();
@ -23,9 +22,7 @@ void ChangeValueDisplayInterface::initScreen()
template<>
void ChangeValueDisplay<float>::redraw()
{
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW);
m_titleLabel.redraw(text());
Base::redraw();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextFont(7);

View File

@ -1,10 +1,7 @@
#pragma once
// 3rdparty lib includes
#include <fmt/core.h>
// local includes
#include "display.h"
#include "displaywithtitle.h"
#include "textinterface.h"
#include "actioninterface.h"
#include "accessorinterface.h"
@ -13,16 +10,13 @@
namespace espgui {
class ChangeValueDisplayInterface :
public Display,
public virtual TextInterface,
public DisplayWithTitle,
public virtual ActionInterface
{
using Base = DisplayWithTitle;
public:
void initScreen() override;
TextInterface *asTextInterface() override { return this; }
const TextInterface *asTextInterface() const override { return this; }
ChangeValueDisplayInterface *asChangeValueDisplayInterface() override { return this; }
const ChangeValueDisplayInterface *asChangeValueDisplayInterface() const override { return this; }
@ -30,7 +24,6 @@ public:
virtual void setShownValue(int value) = 0;
protected:
Label m_titleLabel{5, 5}; // 230, 25
Label m_valueLabel{26, 81}; // 188, 53
};
@ -86,6 +79,8 @@ void ChangeValueDisplay<Tvalue>::start()
template<typename Tvalue>
void ChangeValueDisplay<Tvalue>::update()
{
Base::update();
if (!m_pressed)
{
const auto rotateOffset = m_rotateOffset;
@ -103,9 +98,7 @@ void ChangeValueDisplay<Tvalue>::update()
template<typename Tvalue>
void ChangeValueDisplay<Tvalue>::redraw()
{
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW);
m_titleLabel.redraw(text());
Base::redraw();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextFont(7);

13
src/display.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "display.h"
// local includes
#include "tftinstance.h"
namespace espgui {
void Display::initScreen()
{
tft.fillScreen(TFT_BLACK);
}
} // namespace espgui

View File

@ -64,14 +64,17 @@ public:
void back() override {}
};
class Display : public virtual ConfirmInterface, public virtual BackInterface {
class Display :
public virtual ConfirmInterface,
public virtual BackInterface
{
public:
virtual ~Display() = default;
virtual void start() {};
virtual void initScreen() {};
virtual void update() {};
virtual void redraw() {};
virtual void start() {}
virtual void initScreen();
virtual void update() {}
virtual void redraw() {}
virtual void stop() {}
virtual void rotate(int offset) {}

25
src/displaywithtitle.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "displaywithtitle.h"
// local includes
#include "tftinstance.h"
namespace espgui {
void DisplayWithTitle::initScreen()
{
Base::initScreen();
m_titleLabel.start();
tft.fillRect(0, 33, tft.width(), 3, TFT_WHITE);
}
void DisplayWithTitle::redraw()
{
Base::redraw();
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
m_titleLabel.redraw(text());
}
} // namespace espgui

27
src/displaywithtitle.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
// local includes
#include "display.h"
#include "textinterface.h"
#include "widgets/label.h"
namespace espgui {
class DisplayWithTitle :
public Display,
public virtual TextInterface
{
using Base = Display;
public:
TextInterface *asTextInterface() override { return this; }
const TextInterface *asTextInterface() const override { return this; }
void initScreen() override;
void redraw() override;
private:
Label m_titleLabel{5, 5}; // 230, 25
};
} // namespace espgui

View File

@ -6,6 +6,8 @@
namespace espgui {
void MenuDisplay::start()
{
Base::start();
m_selectedIndex = 0;
m_scrollOffset = 0;
@ -15,10 +17,7 @@ void MenuDisplay::start()
void MenuDisplay::initScreen()
{
tft.fillScreen(TFT_BLACK);
m_titleLabel.start();
tft.fillRect(0, 33, tft.width(), 3, TFT_WHITE);
Base::initScreen();
for (auto &label : m_labels)
label.start();
@ -34,6 +33,8 @@ void MenuDisplay::initScreen()
void MenuDisplay::update()
{
Base::update();
if (!m_pressed)
{
const auto offset = m_rotateOffset;
@ -78,9 +79,10 @@ void MenuDisplay::update()
void MenuDisplay::redraw()
{
Base::redraw();
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
m_titleLabel.redraw(text());
int i{0};
@ -163,6 +165,8 @@ void MenuDisplay::redraw()
void MenuDisplay::stop()
{
Base::stop();
runForEveryMenuItem([](MenuItem &item){
item.stop();
});
@ -170,11 +174,13 @@ void MenuDisplay::stop()
void MenuDisplay::rotate(int offset)
{
Base::rotate(offset);
m_rotateOffset += offset;
}
void MenuDisplay::confirm()
{
//Base::confirm();
m_pressed = true;
}
} // namespace espgui

View File

@ -10,14 +10,16 @@
#include <memory>
// local includes
#include "display.h"
#include "displaywithtitle.h"
#include "textinterface.h"
#include "widgets/label.h"
#include "menuitem.h"
namespace espgui {
class MenuDisplay : public Display, public virtual TextInterface
class MenuDisplay : public DisplayWithTitle
{
using Base = DisplayWithTitle;
public:
void start() override;
void initScreen() override;
@ -28,9 +30,6 @@ public:
void rotate(int offset) override;
void confirm() override;
TextInterface *asTextInterface() override { return this; }
const TextInterface *asTextInterface() const override { return this; }
MenuDisplay *asMenuDisplay() override { return this; }
const MenuDisplay *asMenuDisplay() const override { return this; }
@ -94,8 +93,6 @@ protected:
void setSelectedIndex(int selectedIndex) { m_selectedIndex = selectedIndex; }
private:
Label m_titleLabel{5, 5}; // 230, 25
static constexpr size_t rowCount = CONFIG_ESPGUI_MENUDISPLAY_ROWS;
static constexpr auto iconWidth = 25;
static constexpr auto horizontalSpacing = 10;