Files
Crosspoint/src/activities/util/ConfirmationActivity.cpp
T
2026-03-10 19:11:30 +01:00

89 lines
2.9 KiB
C++

#include "ConfirmationActivity.h"
#include <I18n.h>
#include "../../components/UITheme.h"
#include "HalDisplay.h"
ConfirmationActivity::ConfirmationActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::string& heading, const std::string& body)
: Activity("Confirmation", renderer, mappedInput), heading(heading), body(body) {}
void ConfirmationActivity::onEnter() {
Activity::onEnter();
inputArmed = false;
lineHeight = renderer.getLineHeight(fontId);
const Rect contentRect = UITheme::getContentRect(renderer, true, false);
const int maxWidth = contentRect.width - (margin * 2);
if (!heading.empty()) {
safeHeading = renderer.truncatedText(fontId, heading.c_str(), maxWidth, EpdFontFamily::BOLD);
}
if (!body.empty()) {
safeBody = renderer.truncatedText(fontId, body.c_str(), maxWidth, EpdFontFamily::REGULAR);
}
int totalHeight = 0;
if (!safeHeading.empty()) totalHeight += lineHeight;
if (!safeBody.empty()) totalHeight += lineHeight;
if (!safeHeading.empty() && !safeBody.empty()) totalHeight += spacing;
startY = contentRect.y + (contentRect.height - totalHeight) / 2;
requestUpdate(true);
}
void ConfirmationActivity::render(RenderLock&& lock) {
renderer.clearScreen();
int currentY = startY;
LOG_DBG("CONF", "currentY: %d", currentY);
// Draw Heading
if (!safeHeading.empty()) {
renderer.drawCenteredText(fontId, currentY, safeHeading.c_str(), true, EpdFontFamily::BOLD);
currentY += lineHeight + spacing;
}
// Draw Body
if (!safeBody.empty()) {
renderer.drawCenteredText(fontId, currentY, safeBody.c_str(), true, EpdFontFamily::REGULAR);
}
// Draw UI Elements
const auto labels = mappedInput.mapLabels("", "", I18N.get(StrId::STR_CANCEL), I18N.get(StrId::STR_CONFIRM));
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer(HalDisplay::RefreshMode::FAST_REFRESH);
}
void ConfirmationActivity::loop() {
if (!inputArmed) {
const bool anyFrontPressed = mappedInput.isPressed(MappedInputManager::Button::Back) ||
mappedInput.isPressed(MappedInputManager::Button::Confirm) ||
mappedInput.isPressed(MappedInputManager::Button::Left) ||
mappedInput.isPressed(MappedInputManager::Button::Right);
// Ignore inherited press/release events from the parent activity.
if (!anyFrontPressed && !mappedInput.wasAnyPressed() && !mappedInput.wasAnyReleased()) {
inputArmed = true;
}
return;
}
if (mappedInput.wasReleased(MappedInputManager::Button::Right)) {
ActivityResult res;
res.isCancelled = false;
setResult(std::move(res));
finish();
return;
}
if (mappedInput.wasReleased(MappedInputManager::Button::Left)) {
ActivityResult res;
res.isCancelled = true;
setResult(std::move(res));
finish();
return;
}
}