feat: Add touch coordinate mapping and RTOS task yielding (#2481)

Co-authored-by: Julia Nguyen <julia@uxj.io>
This commit is contained in:
Justin Mitchell
2026-07-20 16:31:07 -04:00
committed by GitHub
co-authored by Julia Nguyen
parent c9188a7347
commit f42fab1c66
123 changed files with 3564 additions and 1380 deletions
@@ -424,6 +424,36 @@ bool FontDownloadActivity::isSelectedFamilyDeletable() const {
void FontDownloadActivity::loop() {
if (state_ == FAMILY_LIST) {
auto activateSelected = [this] {
if (families_.empty()) return;
if (isDownloadAllRow(selectedIndex_)) {
currentFileIndex_ = 0;
currentFileTotal_ = 0;
for (const auto& f : families_) {
if (!f.installed) currentFileTotal_ += f.files.size();
}
downloadAll();
} else if (isUpdateAllRow(selectedIndex_)) {
currentFileIndex_ = 0;
currentFileTotal_ = 0;
for (const auto& f : families_) {
if (f.hasUpdate) currentFileTotal_ += f.files.size();
}
updateAll();
} else {
auto& family = families_[familyIndexFromList(selectedIndex_)];
if (!family.installed || family.hasUpdate) {
currentFileIndex_ = 0;
currentFileTotal_ = family.files.size();
downloadFamily(family);
} else {
promptDeleteSelectedFamily();
return;
}
}
requestUpdateAndWait();
};
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
finish();
return;
@@ -432,6 +462,34 @@ void FontDownloadActivity::loop() {
const int listSize = listItemCount();
const int pageItems = UITheme::getNumberOfItemsPerPage(renderer, true, false, true, false);
if (!families_.empty()) {
const auto& metrics = UITheme::getInstance().getMetrics();
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentHeight =
renderer.getScreenHeight() - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing;
switch (handleListTouch(selectedIndex_, listSize, contentTop, contentHeight, true)) {
case ListTouchResult::Activated:
activateSelected();
return;
case ListTouchResult::Consumed:
return;
case ListTouchResult::None:
break;
}
const auto swipe = mappedInput.wasSwipe();
if (swipe == MappedInputManager::SwipeDir::Up) {
selectedIndex_ = ButtonNavigator::nextPageIndex(selectedIndex_, listSize, pageItems);
requestUpdate();
return;
}
if (swipe == MappedInputManager::SwipeDir::Down) {
selectedIndex_ = ButtonNavigator::previousPageIndex(selectedIndex_, listSize, pageItems);
requestUpdate();
return;
}
}
buttonNavigator_.onNextRelease([this, listSize] {
selectedIndex_ = ButtonNavigator::nextIndex(selectedIndex_, listSize);
requestUpdate();
@@ -453,40 +511,14 @@ void FontDownloadActivity::loop() {
});
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
if (!families_.empty()) {
if (isDownloadAllRow(selectedIndex_)) {
currentFileIndex_ = 0;
currentFileTotal_ = 0;
for (const auto& f : families_) {
if (!f.installed) currentFileTotal_ += f.files.size();
}
downloadAll();
} else if (isUpdateAllRow(selectedIndex_)) {
currentFileIndex_ = 0;
currentFileTotal_ = 0;
for (const auto& f : families_) {
if (f.hasUpdate) currentFileTotal_ += f.files.size();
}
updateAll();
} else {
auto& family = families_[familyIndexFromList(selectedIndex_)];
if (!family.installed || family.hasUpdate) {
currentFileIndex_ = 0;
currentFileTotal_ = family.files.size();
downloadFamily(family);
} else {
promptDeleteSelectedFamily();
return;
}
}
requestUpdateAndWait();
return;
}
activateSelected();
return;
}
} else if (state_ == COMPLETE) {
int x = 0;
int y = 0;
if (mappedInput.wasPressed(MappedInputManager::Button::Back) ||
mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
mappedInput.wasPressed(MappedInputManager::Button::Confirm) || mappedInput.wasScreenTapped(x, y)) {
{
RenderLock lock(*this);
state_ = FAMILY_LIST;
@@ -512,6 +544,21 @@ void FontDownloadActivity::loop() {
}
requestUpdate();
}
} else {
int x = 0;
int y = 0;
if (mappedInput.wasScreenTapped(x, y)) {
if (downloadingFamilyIndex_ >= 0 && downloadingFamilyIndex_ < static_cast<int>(families_.size())) {
downloadFamily(families_[downloadingFamilyIndex_]);
requestUpdateAndWait();
return;
}
{
RenderLock lock(*this);
state_ = FAMILY_LIST;
}
requestUpdate();
}
}
}
}