Added a new fastScrolling property to the carousel.

This commit is contained in:
Leon Styhre 2023-02-23 17:08:21 +01:00
parent 5f66cb80d8
commit fbd804460c
5 changed files with 56 additions and 38 deletions

View file

@ -169,6 +169,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"reflectionsOpacity", FLOAT},
{"reflectionsFalloff", FLOAT},
{"unfocusedItemOpacity", FLOAT},
{"fastScrolling", BOOLEAN},
{"defaultLogo", PATH}, // For backward compatibility with legacy themes.
{"logoSize", NORMALIZED_PAIR}, // For backward compatibility with legacy themes.
{"logoScale", FLOAT}, // For backward compatibility with legacy themes.

View file

@ -25,39 +25,6 @@ enum class ListLoopType {
LIST_NEVER_LOOP
};
struct ScrollTier {
int length; // How long we stay on this tier before going to the next.
int scrollDelay; // How long between scrolls.
};
struct ScrollTierList {
const int count;
const ScrollTier* tiers;
};
// Default scroll tiers.
// clang-format off
const ScrollTier QUICK_SCROLL_TIERS[] = {
{500, 500},
{1200, 114},
{0, 16}
};
const ScrollTierList LIST_SCROLL_STYLE_QUICK = {
3,
QUICK_SCROLL_TIERS
};
const ScrollTier SLOW_SCROLL_TIERS[] = {
{500, 500},
{0, 200}
};
const ScrollTierList LIST_SCROLL_STYLE_SLOW = {
2,
SLOW_SCROLL_TIERS
};
// clang-format on
template <typename EntryData, typename UserData> class IList : public virtual GuiComponent
{
public:
@ -68,9 +35,54 @@ public:
};
protected:
struct ScrollTier {
int length; // How long we stay on this tier before going to the next.
int scrollDelay; // How long between scrolls.
};
struct ScrollTierList {
int count;
const ScrollTier* tiers;
};
// Default scroll tiers.
// clang-format off
static inline const ScrollTier QUICK_SCROLL_TIERS[3] {
{500, 500},
{1200, 114},
{0, 16}
};
static inline const ScrollTierList LIST_SCROLL_STYLE_QUICK {
3,
QUICK_SCROLL_TIERS
};
static inline const ScrollTier MEDIUM_SCROLL_TIERS[3] {
{500, 500},
{1100, 180},
{0, 80}
};
static inline const ScrollTierList LIST_SCROLL_STYLE_MEDIUM {
3,
MEDIUM_SCROLL_TIERS
};
static inline const ScrollTier SLOW_SCROLL_TIERS[2] {
{500, 500},
{0, 200}
};
static inline const ScrollTierList LIST_SCROLL_STYLE_SLOW {
2,
SLOW_SCROLL_TIERS
};
// clang-format on
Window* mWindow;
std::vector<Entry> mEntries;
const ScrollTierList& mTierList;
ScrollTierList mTierList;
const ListLoopType mLoopType;
int mCursor;
int mLastCursor;

View file

@ -199,7 +199,7 @@ private:
template <typename T>
CarouselComponent<T>::CarouselComponent()
: IList<CarouselEntry, T> {LIST_SCROLL_STYLE_SLOW,
: IList<CarouselEntry, T> {IList<CarouselEntry, T>::LIST_SCROLL_STYLE_SLOW,
(std::is_same_v<T, SystemData*> ?
ListLoopType::LIST_ALWAYS_LOOP :
ListLoopType::LIST_PAUSE_AT_END_ON_JUMP)}
@ -1614,6 +1614,9 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("unfocusedItemOpacity"))
mUnfocusedItemOpacity =
glm::clamp(elem->get<float>("unfocusedItemOpacity"), 0.1f, 1.0f);
if (elem->has("fastScrolling") && elem->get<bool>("fastScrolling"))
List::mTierList = IList<CarouselEntry, T>::LIST_SCROLL_STYLE_MEDIUM;
}
// Legacy themes.

View file

@ -198,7 +198,8 @@ private:
template <typename T>
GridComponent<T>::GridComponent()
: IList<GridEntry, T> {LIST_SCROLL_STYLE_SLOW, ListLoopType::LIST_PAUSE_AT_END}
: IList<GridEntry, T> {IList<GridEntry, T>::LIST_SCROLL_STYLE_SLOW,
ListLoopType::LIST_PAUSE_AT_END}
, mRenderer {Renderer::getInstance()}
, mEntryOffset {0.0f}
, mScrollPos {0.0f}

View file

@ -159,8 +159,9 @@ private:
template <typename T>
TextListComponent<T>::TextListComponent()
: IList<TextListData, T> {(std::is_same_v<T, SystemData*> ? LIST_SCROLL_STYLE_SLOW :
LIST_SCROLL_STYLE_QUICK),
: IList<TextListData, T> {(std::is_same_v<T, SystemData*> ?
IList<TextListData, T>::LIST_SCROLL_STYLE_SLOW :
IList<TextListData, T>::LIST_SCROLL_STYLE_QUICK),
ListLoopType::LIST_PAUSE_AT_END}
, mRenderer {Renderer::getInstance()}
, mCamOffset {0.0f}