Implemented scrolling
This commit is contained in:
@ -42,6 +42,7 @@ set(headers
|
||||
src/richtextrenderer.h
|
||||
src/screenmanager.h
|
||||
src/scrollinterface.h
|
||||
src/selectorscrollinterface.h
|
||||
src/splitgraphdisplay.h
|
||||
src/textinterface.h
|
||||
src/textwithvaluehelper.h
|
||||
|
@ -95,16 +95,25 @@ void MenuDisplay::redraw()
|
||||
{
|
||||
Base::redraw();
|
||||
|
||||
if (m_upHoldingSince && espchrono::ago(*m_upHoldingSince) > 500ms)
|
||||
// wait for holding since to be above initial scroll speed, then start scrolling in interval set by getScrollSpeed()
|
||||
if (m_upHoldingSince && (espchrono::ago(*m_upHoldingSince) > getInitialScrollSpeed() || m_upScrolling))
|
||||
{
|
||||
m_upHoldingSince = espchrono::millis_clock::now();
|
||||
m_rotateOffset--;
|
||||
if (espchrono::ago(*m_upHoldingSince) > getScrollSpeed())
|
||||
{
|
||||
m_upScrolling = true;
|
||||
m_rotateOffset--;
|
||||
m_upHoldingSince = espchrono::millis_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_downHoldingSince && espchrono::ago(*m_downHoldingSince) > 500ms)
|
||||
if (m_downHoldingSince && (espchrono::ago(*m_downHoldingSince) > getInitialScrollSpeed() || m_downScrolling))
|
||||
{
|
||||
m_downHoldingSince = espchrono::millis_clock::now();
|
||||
m_rotateOffset++;
|
||||
if (espchrono::ago(*m_downHoldingSince) > getScrollSpeed())
|
||||
{
|
||||
m_downScrolling = true;
|
||||
m_rotateOffset++;
|
||||
m_downHoldingSince = espchrono::millis_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
tft.setTextFont(4);
|
||||
@ -209,10 +218,10 @@ void MenuDisplay::buttonPressed(Button button)
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case Button::Left: this->back(); break;
|
||||
case Button::Right: m_pressed = true; break;
|
||||
case Button::Up: m_rotateOffset--; m_upHoldingSince = espchrono::millis_clock::now(); break;
|
||||
case Button::Down: m_rotateOffset++; m_downHoldingSince = espchrono::millis_clock::now(); break;
|
||||
case Button::Left: this->back(); m_leftHoldingSince = espchrono::millis_clock::now(); m_leftScrolling = false; break;
|
||||
case Button::Right: m_pressed = true; m_rightHoldingSince = espchrono::millis_clock::now(); m_rightScrolling = false; break;
|
||||
case Button::Up: m_rotateOffset--; m_upHoldingSince = espchrono::millis_clock::now(); m_upScrolling = false; break;
|
||||
case Button::Down: m_rotateOffset++; m_downHoldingSince = espchrono::millis_clock::now(); m_downScrolling = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,6 +233,8 @@ void MenuDisplay::buttonReleased(Button 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:;
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,24 @@
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <espchrono.h>
|
||||
|
||||
// local includes
|
||||
#include "displaywithtitle.h"
|
||||
#include "selectorscrollinterface.h"
|
||||
#include "textinterface.h"
|
||||
#include "widgets/label.h"
|
||||
#include "menuitem.h"
|
||||
#include "backinterface.h"
|
||||
|
||||
namespace espgui {
|
||||
using namespace std::chrono_literals;
|
||||
class MenuDisplay :
|
||||
public DisplayWithTitle,
|
||||
public virtual BackInterface
|
||||
public virtual BackInterface,
|
||||
public virtual SelectorScrollInterface<>
|
||||
{
|
||||
using Base = DisplayWithTitle;
|
||||
|
||||
@ -149,7 +154,16 @@ private:
|
||||
|
||||
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
|
||||
|
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