Refactor ui content rect
This commit is contained in:
@@ -51,6 +51,7 @@ void UITheme::setTheme(CrossPointSettings::UI_THEME type) {
|
||||
int UITheme::getNumberOfItemsPerPage(const GfxRenderer& renderer, bool hasHeader, bool hasTabBar, bool hasButtonHints,
|
||||
bool hasSubtitle) {
|
||||
const ThemeMetrics& metrics = UITheme::getInstance().getMetrics();
|
||||
const Rect contentRect = getContentRect(renderer, hasButtonHints, /*hasSideHints=*/false);
|
||||
int reservedHeight = metrics.topPadding;
|
||||
if (hasHeader) {
|
||||
reservedHeight += metrics.headerHeight + metrics.verticalSpacing;
|
||||
@@ -59,13 +60,43 @@ int UITheme::getNumberOfItemsPerPage(const GfxRenderer& renderer, bool hasHeader
|
||||
reservedHeight += metrics.tabBarHeight;
|
||||
}
|
||||
if (hasButtonHints) {
|
||||
reservedHeight += metrics.verticalSpacing + metrics.buttonHintsHeight;
|
||||
reservedHeight += metrics.verticalSpacing;
|
||||
}
|
||||
const int availableHeight = renderer.getScreenHeight() - reservedHeight;
|
||||
const int availableHeight = contentRect.height - reservedHeight;
|
||||
int rowHeight = hasSubtitle ? metrics.listWithSubtitleRowHeight : metrics.listRowHeight;
|
||||
return availableHeight / rowHeight;
|
||||
}
|
||||
|
||||
Rect UITheme::getContentRect(const GfxRenderer& renderer, bool hasBottomHints, bool hasSideHints) {
|
||||
const ThemeMetrics& metrics = UITheme::getInstance().getMetrics();
|
||||
const int bh = hasBottomHints ? metrics.buttonHintsHeight : 0;
|
||||
const int sw = hasSideHints ? metrics.sideButtonHintsWidth : 0;
|
||||
|
||||
int top = 0, right = 0, bottom = 0, left = 0;
|
||||
switch (renderer.getOrientation()) {
|
||||
case GfxRenderer::Portrait:
|
||||
bottom = bh;
|
||||
right = sw;
|
||||
break;
|
||||
case GfxRenderer::PortraitInverted:
|
||||
top = bh;
|
||||
left = sw;
|
||||
break;
|
||||
case GfxRenderer::LandscapeClockwise:
|
||||
left = bh;
|
||||
bottom = sw;
|
||||
break;
|
||||
case GfxRenderer::LandscapeCounterClockwise:
|
||||
right = bh;
|
||||
top = sw;
|
||||
break;
|
||||
}
|
||||
|
||||
const int w = renderer.getScreenWidth();
|
||||
const int h = renderer.getScreenHeight();
|
||||
return Rect{left, top, w - left - right, h - top - bottom};
|
||||
}
|
||||
|
||||
std::string UITheme::getCoverThumbPath(std::string coverBmpPath, int coverHeight) {
|
||||
size_t pos = coverBmpPath.find("[HEIGHT]", 0);
|
||||
if (pos != std::string::npos) {
|
||||
|
||||
@@ -20,6 +20,10 @@ class UITheme {
|
||||
void setTheme(CrossPointSettings::UI_THEME type);
|
||||
static int getNumberOfItemsPerPage(const GfxRenderer& renderer, bool hasHeader, bool hasTabBar, bool hasButtonHints,
|
||||
bool hasSubtitle);
|
||||
// Returns the drawable content Rect accounting for screen orientation and visible button hints.
|
||||
// Bottom hints occupy the physical bottom edge; side hints occupy the physical right edge.
|
||||
// The mapping to logical edges is orientation-dependent.
|
||||
static Rect getContentRect(const GfxRenderer& renderer, bool hasBottomHints, bool hasSideHints);
|
||||
static std::string getCoverThumbPath(std::string coverBmpPath, int coverHeight);
|
||||
static UIIcon getFileIcon(const std::string& filename);
|
||||
static int getStatusBarHeight();
|
||||
|
||||
@@ -273,9 +273,9 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
|
||||
rect.width -
|
||||
(totalPages > 1 ? (LyraMetrics::values.scrollBarWidth + LyraMetrics::values.scrollBarRightOffset) : 1);
|
||||
if (selectedIndex >= 0) {
|
||||
renderer.fillRoundedRect(LyraMetrics::values.contentSidePadding, rect.y + selectedIndex % pageItems * rowHeight,
|
||||
contentWidth - LyraMetrics::values.contentSidePadding * 2, rowHeight, cornerRadius,
|
||||
Color::LightGray);
|
||||
renderer.fillRoundedRect(
|
||||
rect.x + LyraMetrics::values.contentSidePadding, rect.y + selectedIndex % pageItems * rowHeight,
|
||||
contentWidth - LyraMetrics::values.contentSidePadding * 2, rowHeight, cornerRadius, Color::LightGray);
|
||||
}
|
||||
|
||||
int textX = rect.x + LyraMetrics::values.contentSidePadding + hPaddingInSelection;
|
||||
@@ -336,7 +336,7 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
|
||||
if (!valueText.empty()) {
|
||||
if (i == selectedIndex && highlightValue) {
|
||||
renderer.fillRoundedRect(
|
||||
contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection - valueWidth, itemY,
|
||||
rect.x + contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection - valueWidth, itemY,
|
||||
valueWidth + hPaddingInSelection, rowHeight, cornerRadius, Color::Black);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user