fix: two roundedraff bugs (#1851)
This commit is contained in:
@@ -122,7 +122,7 @@ void RoundedRaffTheme::drawTabBar(const GfxRenderer& renderer, Rect rect, const
|
||||
}
|
||||
|
||||
// Full-width divider between tabs and setting rows.
|
||||
renderer.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1, true);
|
||||
renderer.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1, true);
|
||||
}
|
||||
|
||||
void RoundedRaffTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBook>& recentBooks,
|
||||
@@ -243,6 +243,77 @@ void RoundedRaffTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int butt
|
||||
drawScrollBar(renderer, rect, buttonCount, pageStartIndex, pageItems);
|
||||
}
|
||||
|
||||
void RoundedRaffTheme::drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth, bool cursorMode,
|
||||
int contentStartX, int contentWidth) const {
|
||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
||||
const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
||||
const int lineY = rect.y + rect.height + lineHeight + metrics.verticalSpacing;
|
||||
const int thickness = cursorMode ? 3 : 2;
|
||||
|
||||
if (contentWidth > 0) {
|
||||
renderer.drawLine(rect.x + contentStartX, lineY, rect.x + contentStartX + contentWidth - 1, lineY, thickness, true);
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr int hPadding = 8;
|
||||
const int lineW = textWidth + hPadding * 2;
|
||||
const int lineStart = rect.x + (rect.width - lineW) / 2;
|
||||
renderer.drawLine(lineStart, lineY, lineStart + lineW - 1, lineY, thickness, true);
|
||||
}
|
||||
|
||||
void RoundedRaffTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const char* label, const bool isSelected,
|
||||
const char* secondaryLabel, const KeyboardKeyType keyType,
|
||||
const bool inactiveSelection) const {
|
||||
constexpr int keyRadius = 10;
|
||||
const bool disabled = keyType == KeyboardKeyType::Disabled;
|
||||
const bool invert = isSelected && !inactiveSelection;
|
||||
|
||||
if (isSelected) {
|
||||
const Color fillColor = (inactiveSelection || disabled) ? Color::LightGray : Color::Black;
|
||||
renderer.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, keyRadius, fillColor);
|
||||
} else {
|
||||
if (disabled) {
|
||||
renderer.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, keyRadius, Color::LightGray);
|
||||
} else {
|
||||
renderer.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, keyRadius, Color::White);
|
||||
}
|
||||
renderer.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 1, keyRadius, true);
|
||||
}
|
||||
|
||||
if (keyType == KeyboardKeyType::Space) {
|
||||
const int lineHalfWidth = rect.width * 3 / 10;
|
||||
const int centerX = rect.x + rect.width / 2;
|
||||
const int lineY = rect.y + rect.height / 2 + 3;
|
||||
renderer.drawLine(centerX - lineHalfWidth, lineY, centerX + lineHalfWidth, lineY, 3, !invert);
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyType == KeyboardKeyType::Del) {
|
||||
const int centerX = rect.x + rect.width / 2;
|
||||
const int centerY = rect.y + rect.height / 2;
|
||||
const int arrowLen = rect.width / 4;
|
||||
const int arrowHead = std::max(1, arrowLen / 2);
|
||||
renderer.drawLine(centerX - arrowLen / 2, centerY, centerX + arrowLen / 2, centerY, 3, !invert);
|
||||
renderer.drawLine(centerX - arrowLen / 2, centerY, centerX - arrowLen / 2 + arrowHead, centerY - arrowHead, 3,
|
||||
!invert);
|
||||
renderer.drawLine(centerX - arrowLen / 2, centerY, centerX - arrowLen / 2 + arrowHead, centerY + arrowHead, 3,
|
||||
!invert);
|
||||
return;
|
||||
}
|
||||
|
||||
if (label != nullptr && label[0] != '\0') {
|
||||
const int itemWidth = renderer.getTextWidth(UI_12_FONT_ID, label);
|
||||
const int textX = rect.x + (rect.width - itemWidth) / 2;
|
||||
const int textY = rect.y + (rect.height - renderer.getLineHeight(UI_12_FONT_ID)) / 2;
|
||||
renderer.drawText(UI_12_FONT_ID, textX, textY, label, !invert);
|
||||
}
|
||||
|
||||
if (secondaryLabel != nullptr && secondaryLabel[0] != '\0') {
|
||||
const int secWidth = renderer.getTextWidth(SMALL_FONT_ID, secondaryLabel);
|
||||
renderer.drawText(SMALL_FONT_ID, rect.x + rect.width - secWidth - 3, rect.y + 1, secondaryLabel, !invert);
|
||||
}
|
||||
}
|
||||
|
||||
void RoundedRaffTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
|
||||
const std::function<std::string(int index)>& rowTitle,
|
||||
const std::function<std::string(int index)>& rowSubtitle,
|
||||
|
||||
@@ -36,8 +36,14 @@ constexpr ThemeMetrics values = {.batteryWidth = 15,
|
||||
.keyboardKeyWidth = 22,
|
||||
.keyboardKeyHeight = 30,
|
||||
.keyboardKeySpacing = 10,
|
||||
.keyboardBottomAligned = false,
|
||||
.keyboardCenteredText = false};
|
||||
.keyboardBottomKeyHeight = 30,
|
||||
.keyboardBottomKeySpacing = 5,
|
||||
.keyboardBottomAligned = true,
|
||||
.keyboardCenteredText = false,
|
||||
.keyboardVerticalOffset = 0,
|
||||
.keyboardTextFieldWidthPercent = 85,
|
||||
.keyboardWidthPercent = 90,
|
||||
.keyboardKeyCornerRadius = 0};
|
||||
}
|
||||
|
||||
class RoundedRaffTheme : public BaseTheme {
|
||||
@@ -52,6 +58,11 @@ class RoundedRaffTheme : public BaseTheme {
|
||||
void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
|
||||
const std::function<std::string(int index)>& buttonLabel,
|
||||
const std::function<UIIcon(int index)>& rowIcon) const override;
|
||||
void drawTextField(const GfxRenderer& renderer, Rect rect, int textWidth, bool cursorMode = false,
|
||||
int contentStartX = 0, int contentWidth = 0) const override;
|
||||
void drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const char* label, bool isSelected,
|
||||
const char* secondaryLabel = nullptr, KeyboardKeyType keyType = KeyboardKeyType::Normal,
|
||||
bool inactiveSelection = false) const override;
|
||||
void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
|
||||
const std::function<std::string(int index)>& rowTitle,
|
||||
const std::function<std::string(int index)>& rowSubtitle = nullptr,
|
||||
|
||||
Reference in New Issue
Block a user