refactor: Consolidate theme rendering into ThemeMetrics (#1868)
This commit is contained in:
@@ -33,8 +33,6 @@ namespace {
|
||||
constexpr int hPaddingInSelection = 8;
|
||||
constexpr int cornerRadius = 6;
|
||||
constexpr int topHintButtonY = 345;
|
||||
constexpr int popupMarginX = 16;
|
||||
constexpr int popupMarginY = 12;
|
||||
constexpr int maxListValueWidth = 200;
|
||||
constexpr int mainMenuIconSize = 32;
|
||||
constexpr int listIconSize = 24;
|
||||
@@ -536,41 +534,3 @@ void LyraTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
|
||||
renderer.drawText(UI_12_FONT_ID, textX, textY, label, true);
|
||||
}
|
||||
}
|
||||
|
||||
Rect LyraTheme::drawPopup(const GfxRenderer& renderer, const char* message) const {
|
||||
// Scale y position proportionally to screen height (16.5% from top)
|
||||
const int y = static_cast<int>(renderer.getScreenHeight() * 0.165f);
|
||||
constexpr int outline = 2;
|
||||
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::REGULAR);
|
||||
const int textHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
||||
const int w = textWidth + popupMarginX * 2;
|
||||
const int h = textHeight + popupMarginY * 2;
|
||||
const int x = (renderer.getScreenWidth() - w) / 2;
|
||||
|
||||
renderer.fillRoundedRect(x - outline, y - outline, w + outline * 2, h + outline * 2, cornerRadius + outline,
|
||||
Color::White);
|
||||
renderer.fillRoundedRect(x, y, w, h, cornerRadius, Color::Black);
|
||||
|
||||
const int textX = x + (w - textWidth) / 2;
|
||||
const int textY = y + popupMarginY - 2;
|
||||
renderer.drawText(UI_12_FONT_ID, textX, textY, message, false, EpdFontFamily::REGULAR);
|
||||
renderer.displayBuffer();
|
||||
|
||||
return Rect{x, y, w, h};
|
||||
}
|
||||
|
||||
void LyraTheme::fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress) const {
|
||||
constexpr int barHeight = 4;
|
||||
|
||||
// Twice the margin in drawPopup to match text width
|
||||
const int barWidth = layout.width - popupMarginX * 2;
|
||||
const int barX = layout.x + (layout.width - barWidth) / 2;
|
||||
// Center inside the margin of drawPopup. The - 1 is added to account for the - 2 in drawPopup.
|
||||
const int barY = layout.y + layout.height - popupMarginY / 2 - barHeight / 2 - 1;
|
||||
|
||||
int fillWidth = barWidth * progress / 100;
|
||||
|
||||
renderer.fillRect(barX, barY, fillWidth, barHeight, false);
|
||||
|
||||
renderer.displayBuffer(HalDisplay::FAST_REFRESH);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,30 @@ constexpr ThemeMetrics values = {.batteryWidth = 16,
|
||||
.keyboardVerticalOffset = -7,
|
||||
.keyboardTextFieldWidthPercent = 85,
|
||||
.keyboardWidthPercent = 90,
|
||||
.keyboardKeyCornerRadius = 6};
|
||||
.keyboardKeyCornerRadius = 6,
|
||||
.keyboardFillUnselected = false,
|
||||
.keyboardOutlineAllUnselected = false,
|
||||
.keyboardDrawSpecialOutlineWhenUnselected = true,
|
||||
.keyboardSecondaryLabelRightPadding = 1,
|
||||
.keyboardSecondaryLabelTopPadding = 0,
|
||||
.keyboardMinArrowHeadSize = 0,
|
||||
.popupTopOffsetRatio = 0.165f,
|
||||
.popupMarginX = 16,
|
||||
.popupMarginY = 12,
|
||||
.popupFrameThickness = 2,
|
||||
.popupCornerRadius = 6,
|
||||
.popupTextBold = false,
|
||||
.popupTextInverted = false,
|
||||
.popupTextBaselineOffsetY = -2,
|
||||
.popupProgressBarHeight = 4,
|
||||
.popupProgressDrawOutline = false,
|
||||
.popupProgressClampPercent = false,
|
||||
.popupProgressFillInverted = false,
|
||||
.popupProgressOutlineInverted = false,
|
||||
.textFieldHorizontalPadding = 6,
|
||||
.textFieldNormalThickness = 1,
|
||||
.textFieldCursorThickness = 3,
|
||||
.textFieldLineEndOffset = 0};
|
||||
}
|
||||
|
||||
class LyraTheme : public BaseTheme {
|
||||
@@ -70,7 +93,5 @@ class LyraTheme : public BaseTheme {
|
||||
const int selectorIndex, bool& coverRendered, bool& coverBufferStored, bool& bufferRestored,
|
||||
std::function<bool()> storeCoverBuffer) const override;
|
||||
void drawEmptyRecents(const GfxRenderer& renderer, const Rect rect) const;
|
||||
Rect drawPopup(const GfxRenderer& renderer, const char* message) const override;
|
||||
void fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress) const override;
|
||||
bool showsFileIcons() const override { return true; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user