add touch support (#77)

* initial work on touch support

* add touch support to all objects

* add touch scrolling, fix scrollbar, fix appstore search

- when fireing an action, the action array may change. so the loop should break early as soon as an action is handled.
  this fixes the appstore search when pressing B.
- scrollbar no longer goes oob. fixes #76

currently, scrolling has no acceleration.
This commit is contained in:
ITotalJustice
2025-01-06 22:37:38 +00:00
committed by GitHub
parent cf95128f0b
commit 78bda75985
45 changed files with 1080 additions and 1069 deletions

View File

@@ -115,7 +115,7 @@ auto InstallUpdate(ProgressBox* pbox, const std::string url, const std::string v
}
std::vector<char> buf(chunk_size);
u64 offset{};
s64 offset{};
while (offset < info.uncompressed_size) {
const auto bytes_read = unzReadCurrentFile(zfile, buf.data(), buf.size());
if (bytes_read <= 0) {
@@ -205,9 +205,6 @@ MainMenu::MainMenu() {
}
});
AddOnLPress();
AddOnRPress();
this->SetActions(
std::make_pair(Button::START, Action{App::Exit}),
std::make_pair(Button::Y, Action{"Menu"_i18n, [this](){
@@ -229,8 +226,6 @@ MainMenu::MainMenu() {
language_items.push_back("Russian"_i18n);
language_items.push_back("Swedish"_i18n);
options->AddHeader("Header"_i18n);
options->AddSpacer();
options->Add(std::make_shared<SidebarEntryCallback>("Theme"_i18n, [this](){
SidebarEntryArray::Items theme_items{};
const auto theme_meta = App::GetThemeMetaList();
@@ -241,7 +236,7 @@ MainMenu::MainMenu() {
auto options = std::make_shared<Sidebar>("Theme Options"_i18n, Sidebar::Side::LEFT);
ON_SCOPE_EXIT(App::Push(options));
options->Add(std::make_shared<SidebarEntryArray>("Select Theme"_i18n, theme_items, [this, theme_items](std::size_t& index_out){
options->Add(std::make_shared<SidebarEntryArray>("Select Theme"_i18n, theme_items, [this, theme_items](s64& index_out){
App::SetTheme(index_out);
}, App::GetThemeIndex()));
@@ -294,9 +289,9 @@ MainMenu::MainMenu() {
}
}));
options->Add(std::make_shared<SidebarEntryArray>("Language"_i18n, language_items, [this](std::size_t& index_out){
options->Add(std::make_shared<SidebarEntryArray>("Language"_i18n, language_items, [this](s64& index_out){
App::SetLanguage(index_out);
}, (std::size_t)App::GetLanguage()));
}, (s64)App::GetLanguage()));
options->Add(std::make_shared<SidebarEntryCallback>("Misc"_i18n, [this](){
auto options = std::make_shared<Sidebar>("Misc Options"_i18n, Sidebar::Side::LEFT);
@@ -341,9 +336,9 @@ MainMenu::MainMenu() {
App::SetInstallEnable(enable);
}, "Enabled"_i18n, "Disabled"_i18n));
options->Add(std::make_shared<SidebarEntryArray>("Install location"_i18n, install_items, [this](std::size_t& index_out){
options->Add(std::make_shared<SidebarEntryArray>("Install location"_i18n, install_items, [this](s64& index_out){
App::SetInstallSdEnable(index_out);
}, (std::size_t)App::GetInstallSdEnable()));
}, (s64)App::GetInstallSdEnable()));
options->Add(std::make_shared<SidebarEntryBool>("Show install warning"_i18n, App::GetInstallPrompt(), [this](bool& enable){
App::SetInstallPrompt(enable);
@@ -357,6 +352,8 @@ MainMenu::MainMenu() {
m_app_store_menu = std::make_shared<appstore::Menu>(m_homebrew_menu->GetHomebrewList());
m_current_menu = m_homebrew_menu;
AddOnLRPress();
for (auto [button, action] : m_actions) {
m_current_menu->SetAction(button, action);
}
@@ -389,17 +386,11 @@ void MainMenu::OnLRPress(std::shared_ptr<MenuBase> menu, Button b) {
if (m_current_menu == m_homebrew_menu) {
m_current_menu = menu;
RemoveAction(b);
if (b == Button::L) {
AddOnRPress();
} else {
AddOnLPress();
}
} else {
m_current_menu = m_homebrew_menu;
AddOnRPress();
AddOnLPress();
}
AddOnLRPress();
m_current_menu->OnFocusGained();
for (auto [button, action] : m_actions) {
@@ -407,18 +398,20 @@ void MainMenu::OnLRPress(std::shared_ptr<MenuBase> menu, Button b) {
}
}
void MainMenu::AddOnLPress() {
const auto label = m_current_menu == m_homebrew_menu ? "Files" : "Apps";
SetAction(Button::L, Action{i18n::get(label), [this]{
OnLRPress(m_filebrowser_menu, Button::L);
}});
}
void MainMenu::AddOnLRPress() {
if (m_current_menu != m_filebrowser_menu) {
const auto label = m_current_menu == m_homebrew_menu ? "Files" : "Apps";
SetAction(Button::L, Action{i18n::get(label), [this]{
OnLRPress(m_filebrowser_menu, Button::L);
}});
}
void MainMenu::AddOnRPress() {
const auto label = m_current_menu == m_homebrew_menu ? "Store" : "Apps";
SetAction(Button::R, Action{i18n::get(label), [this]{
OnLRPress(m_app_store_menu, Button::R);
}});
if (m_current_menu != m_app_store_menu) {
const auto label = m_current_menu == m_homebrew_menu ? "Store" : "Apps";
SetAction(Button::R, Action{i18n::get(label), [this]{
OnLRPress(m_app_store_menu, Button::R);
}});
}
}
} // namespace sphaira::ui::menu::main