MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / loop

Method loop

src/activities/settings/FontSelectionActivity.cpp:73–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71void FontSelectionActivity::onExit() { Activity::onExit(); }
72
73void FontSelectionActivity::loop() {
74 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
75 SETTINGS.fontFamily = originalFontFamily_;
76 strncpy(SETTINGS.sdFontFamilyName, originalSdFontFamilyName_, sizeof(SETTINGS.sdFontFamilyName) - 1);
77 SETTINGS.sdFontFamilyName[sizeof(SETTINGS.sdFontFamilyName) - 1] = '\0';
78 sdFontSystem.ensureLoaded(renderer);
79 finish();
80 return;
81 }
82
83 if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
84 if (selectedIndex_ == previewFontIndex_) {
85 handleSelection();
86 } else {
87 previewFontIndex_ = selectedIndex_;
88 const auto& font = fonts_[selectedIndex_];
89 if (font.isBuiltin) {
90 SETTINGS.fontFamily = font.settingIndex;
91 SETTINGS.sdFontFamilyName[0] = '\0';
92 } else if (registry_) {
93 const int sdIdx = font.settingIndex - CrossPointSettings::BUILTIN_FONT_COUNT;
94 const auto& families = registry_->getFamilies();
95 if (sdIdx < static_cast<int>(families.size())) {
96 strncpy(SETTINGS.sdFontFamilyName, families[sdIdx].name.c_str(), sizeof(SETTINGS.sdFontFamilyName) - 1);
97 SETTINGS.sdFontFamilyName[sizeof(SETTINGS.sdFontFamilyName) - 1] = '\0';
98 sdFontSystem.ensureLoaded(renderer);
99 }
100 }
101 requestUpdate();
102 }
103 return;
104 }
105
106 const int listSize = static_cast<int>(fonts_.size());
107 const int pageItems =
108 UITheme::getNumberOfItemsPerPage(renderer, true, false, true, false, previewHeight + metrics_.verticalSpacing);
109
110 buttonNavigator_.onNextRelease([this, listSize] {
111 selectedIndex_ = ButtonNavigator::nextIndex(selectedIndex_, listSize);
112 requestUpdate();
113 });
114
115 buttonNavigator_.onPreviousRelease([this, listSize] {
116 selectedIndex_ = ButtonNavigator::previousIndex(selectedIndex_, listSize);
117 requestUpdate();
118 });
119
120 buttonNavigator_.onNextContinuous([this, listSize, pageItems] {
121 selectedIndex_ = ButtonNavigator::nextPageIndex(selectedIndex_, listSize, pageItems);
122 requestUpdate();
123 });
124
125 buttonNavigator_.onPreviousContinuous([this, listSize, pageItems] {
126 selectedIndex_ = ButtonNavigator::previousPageIndex(selectedIndex_, listSize, pageItems);
127 requestUpdate();
128 });
129}
130

Callers

nothing calls this directly

Calls 7

ensureLoadedMethod · 0.80
onNextReleaseMethod · 0.80
onPreviousReleaseMethod · 0.80
onNextContinuousMethod · 0.80
onPreviousContinuousMethod · 0.80
wasPressedMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected