WIP: Implement scrolling #16
@ -42,6 +42,7 @@ set(headers
|
|||||||
src/richtextrenderer.h
|
src/richtextrenderer.h
|
||||||
src/screenmanager.h
|
src/screenmanager.h
|
||||||
src/scrollinterface.h
|
src/scrollinterface.h
|
||||||
|
src/selectorscrollinterface.h
|
||||||
src/splitgraphdisplay.h
|
src/splitgraphdisplay.h
|
||||||
src/textinterface.h
|
src/textinterface.h
|
||||||
src/textwithvaluehelper.h
|
src/textwithvaluehelper.h
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
|
|
||||||
virtual void buttonPressed(Button button) = 0;
|
virtual void buttonPressed(Button button) = 0;
|
||||||
virtual void buttonReleased(Button button) = 0;
|
virtual void buttonReleased(Button button) = 0;
|
||||||
|
virtual void buttonHeld(Button button) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "tftinstance.h"
|
#include "tftinstance.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace espgui {
|
namespace espgui {
|
||||||
void MenuDisplay::start()
|
void MenuDisplay::start()
|
||||||
{
|
{
|
||||||
@ -13,6 +17,18 @@ void MenuDisplay::start()
|
|||||||
|
|
||||||
m_rotateOffset = 0;
|
m_rotateOffset = 0;
|
||||||
m_pressed = false;
|
m_pressed = false;
|
||||||
|
|
||||||
|
m_upScrolling = false;
|
||||||
|
m_upHoldingSince = std::nullopt;
|
||||||
|
|
||||||
|
m_downScrolling = false;
|
||||||
|
m_downHoldingSince = std::nullopt;
|
||||||
|
|
||||||
|
m_leftScrolling = false;
|
||||||
|
m_leftHoldingSince = std::nullopt;
|
||||||
|
|
||||||
|
m_rightScrolling = false;
|
||||||
|
m_rightHoldingSince = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuDisplay::initScreen()
|
void MenuDisplay::initScreen()
|
||||||
@ -35,6 +51,84 @@ void MenuDisplay::update()
|
|||||||
{
|
{
|
||||||
Base::update();
|
Base::update();
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_upHoldingSince);
|
||||||
|
if (m_upHoldingSince && (m_upScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_upScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Up);
|
||||||
|
}
|
||||||
|
m_upScrolling = true;
|
||||||
|
m_upHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
m_rotateOffset--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_downHoldingSince);
|
||||||
|
if (m_downHoldingSince && (m_downScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_downScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Down);
|
||||||
|
}
|
||||||
|
m_downScrolling = true;
|
||||||
|
m_downHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
m_rotateOffset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_leftHoldingSince);
|
||||||
|
if (m_leftHoldingSince && (m_leftScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_leftScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Left);
|
||||||
|
}
|
||||||
|
m_leftScrolling = true;
|
||||||
|
m_leftHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto ago = espchrono::ago(*m_rightHoldingSince);
|
||||||
|
if (m_rightHoldingSince && (m_rightScrolling || ago > getInitialScrollSpeed()))
|
||||||
|
{
|
||||||
|
if (ago > getScrollSpeed())
|
||||||
|
{
|
||||||
|
if (!m_rightScrolling)
|
||||||
|
{
|
||||||
|
// gets executed one time
|
||||||
|
buttonHeld(espgui::Right);
|
||||||
|
}
|
||||||
|
m_rightScrolling = true;
|
||||||
|
m_rightHoldingSince = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
// do sth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_pressed)
|
if (!m_pressed)
|
||||||
{
|
{
|
||||||
const auto offset = m_rotateOffset;
|
const auto offset = m_rotateOffset;
|
||||||
@ -195,16 +289,29 @@ void MenuDisplay::buttonPressed(Button button)
|
|||||||
|
|
||||||
switch (button)
|
switch (button)
|
||||||
{
|
{
|
||||||
case Button::Left: this->back(); break;
|
case Button::Left: this->back(); m_leftHoldingSince = espchrono::millis_clock::now(); m_leftScrolling = false; break;
|
||||||
case Button::Right: m_pressed = true; break;
|
case Button::Right: m_pressed = true; m_rightHoldingSince = espchrono::millis_clock::now(); m_rightScrolling = false; break;
|
||||||
case Button::Up: m_rotateOffset--; break;
|
case Button::Up: m_rotateOffset--; m_upHoldingSince = espchrono::millis_clock::now(); m_upScrolling = false; break;
|
||||||
case Button::Down: m_rotateOffset++; break;
|
case Button::Down: m_rotateOffset++; m_downHoldingSince = espchrono::millis_clock::now(); m_downScrolling = false; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuDisplay::buttonReleased(Button button)
|
void MenuDisplay::buttonReleased(Button button)
|
||||||
{
|
{
|
||||||
//Base::buttonPressed(button);
|
//Base::buttonPressed(button);
|
||||||
// TODO stop auto scroll
|
|
||||||
|
switch (button)
|
||||||
|
{
|
||||||
|
case Button::Up: m_upHoldingSince = std::nullopt; break;
|
||||||
|
case Button::Down: m_downHoldingSince = std::nullopt; break;
|
||||||
|
case Button::Left: m_leftHoldingSince = std::nullopt; break;
|
||||||
|
case Button::Right: m_rightHoldingSince = std::nullopt; break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuDisplay::buttonHeld(Button button)
|
||||||
|
{
|
||||||
|
ESP_LOGI("Menudisplay", "buttonHeld %d", button);
|
||||||
}
|
}
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
@ -8,18 +8,25 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <espchrono.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "displaywithtitle.h"
|
#include "displaywithtitle.h"
|
||||||
|
#include "selectorscrollinterface.h"
|
||||||
#include "textinterface.h"
|
#include "textinterface.h"
|
||||||
#include "widgets/label.h"
|
#include "widgets/label.h"
|
||||||
#include "menuitem.h"
|
#include "menuitem.h"
|
||||||
#include "backinterface.h"
|
#include "backinterface.h"
|
||||||
|
|
||||||
namespace espgui {
|
namespace espgui {
|
||||||
|
using namespace std::chrono_literals;
|
||||||
class MenuDisplay :
|
class MenuDisplay :
|
||||||
public DisplayWithTitle,
|
public DisplayWithTitle,
|
||||||
public virtual BackInterface
|
public virtual BackInterface,
|
||||||
|
public virtual SelectorScrollInterface<>
|
||||||
{
|
{
|
||||||
using Base = DisplayWithTitle;
|
using Base = DisplayWithTitle;
|
||||||
|
|
||||||
@ -32,6 +39,7 @@ public:
|
|||||||
|
|
||||||
void buttonPressed(Button button) override;
|
void buttonPressed(Button button) override;
|
||||||
void buttonReleased(Button button) override;
|
void buttonReleased(Button button) override;
|
||||||
|
void buttonHeld(Button button) 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; }
|
||||||
@ -146,5 +154,17 @@ private:
|
|||||||
bool m_pressed;
|
bool m_pressed;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<MenuItem>> m_menuItems;
|
std::vector<std::unique_ptr<MenuItem>> m_menuItems;
|
||||||
|
|
||||||
|
bool m_upScrolling;
|
||||||
|
std::optional<espchrono::millis_clock::time_point> m_upHoldingSince;
|
||||||
|
|
||||||
|
bool m_downScrolling;
|
||||||
|
std::optional<espchrono::millis_clock::time_point> m_downHoldingSince;
|
||||||
|
|
||||||
|
bool m_leftScrolling;
|
||||||
|
std::optional<espchrono::millis_clock::time_point> m_leftHoldingSince;
|
||||||
|
|
||||||
|
bool m_rightScrolling;
|
||||||
|
std::optional<espchrono::millis_clock::time_point> m_rightHoldingSince;
|
||||||
};
|
};
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
50
src/selectorscrollinterface.h
Normal file
50
src/selectorscrollinterface.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <espchrono.h>
|
||||||
|
|
||||||
|
namespace espgui {
|
||||||
|
namespace {
|
||||||
|
template <typename T>
|
||||||
|
struct is_allowed
|
||||||
|
{
|
||||||
|
static constexpr bool value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct is_allowed<espchrono::milliseconds32>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_allowed<espchrono::seconds32>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_allowed<espchrono::minutes32>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_allowed<espchrono::hours32>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
template<typename TimeType = espchrono::milliseconds32, int initialDelay = 750, int delay = 150>
|
||||||
|
class SelectorScrollInterface {
|
||||||
|
static_assert(is_allowed<TimeType>::value, "Type not supported");
|
||||||
|
public:
|
||||||
|
TimeType getInitialScrollSpeed() const { return initialScrollDelay; }
|
||||||
|
TimeType getScrollSpeed() const { return scrollDelay; }
|
||||||
|
|
||||||
|
void setInitialScrollSpeed(TimeType speed) { initialScrollDelay = speed; }
|
||||||
|
void setScrollSpeed(TimeType speed) { scrollDelay = speed; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
TimeType initialScrollDelay{initialDelay};
|
||||||
|
TimeType scrollDelay{delay};
|
||||||
|
};
|
||||||
|
} // namespace espgui
|
Reference in New Issue
Block a user