Play your Steam library's Windows games on a jailbroken PS5.
C++
Split Sort and filters into sections
Leonardo Lobatoaf91665d6c52
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex c8d93f7..40591b8 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -507,6 +507,9 @@ std::vector<std::string> split_overrides(const std::string& list) {return entries;}+// A sheet row that only sets the others apart: a section heading ("heading-sort") or an untitled divider.+bool SheetDecoration(const std::string& key) { return key.rfind("heading-", 0) == 0 || key == "divider"; }+std::string action_label(const std::string& key) {static const std::map<std::string, std::string> labels = {{"cancel", "Cancel"}, {"confirm-destructive", "Confirm"}, {"ready-later", "Later"}, {"alert-ok", "OK"}, {"alert-settings", "Game settings"}, {"runtime-cleanup-confirm", "Clean up"}, {"quit-to-home", "Play"}, {"favorite", "Favorite"},@@ -524,7 +527,8 @@ std::string action_label(const std::string& key) {{"preset-picker", "Preset"}, {"game-settings", "Game settings"}, {"game-maintenance", "Maintenance"}, {"run-once", "Run a program once…"}, {"run-once-start", "Run once"}, {"game-move", "Move to…"}, {"runtime-check-again", "Check again"}, {"reset-settings", "Reset all to preset"}, {"clear-shader-cache", "Clear shader cache"},{"section-compatibility", "Compatibility"}, {"section-advanced", "Advanced"}, {"heading-game", "Game"},{"heading-display", "Display"}, {"heading-controls", "Controls"}, {"heading-sound", "Sound"},- {"heading-graphics", "Graphics"}, {"heading-windows", "Windows"},+ {"heading-graphics", "Graphics"}, {"heading-windows", "Windows"}, {"heading-sort", "Sort"}, {"heading-filter", "Filter"},+ {"divider", ""},{"sort-name", "Name"}, {"sort-recent-played", "Recently played"}, {"sort-recent-added", "Recently added"},{"sort-playtime", "Playtime"}, {"sort-install-size", "Install size"}, {"filter-installed", "Installed"},{"filter-genre-adventure", "Adventure"}, {"filter-controller-full", "Full controller support"},@@ -5636,12 +5640,18 @@ void Simulation::rebuild_view() {item.value = playden::steam::LanguageName(install_language(id));item.subtitle = install_language_.empty() ? "From Settings › Downloads" : "This game only";}- // Demos and Family sharing are on unless the player hid them.- if (action_key == "filter-hide-demos" || action_key == "filter-hide-family") {+ // Every library filter is a toggle. Demos and Family sharing are on unless the player hid them;+ // the others (Playable) narrow the library while on.+ if (modal.id == "filters" && action_key.rfind("filter-", 0) == 0) {+ const bool hide = action_key == "filter-hide-demos" || action_key == "filter-hide-family";item.kind = RowKind::Toggle;- item.selected = !state_.library.filters.contains(action_key.substr(7));+ item.selected = state_.library.filters.contains(action_key.substr(7)) != hide;item.value = item.selected ? "On" : "Off";}+ // The sort in use gets a tick.+ if (modal.id == "filters" && action_key.rfind("sort-", 0) == 0)+ item.checked = action_key.substr(5) ==+ (state_.library.view_sort.empty() ? state_.library.sort : state_.library.view_sort);// The menu's Favorite says what it will do for this game.if (modal.id == "context" && action_key == "favorite")item.title = state_.library.favorites.contains(state_.navigation.selected_game_id) ? "Remove from Favorites"@@ -5763,8 +5773,8 @@ void Simulation::rebuild_view() {if (inside && game_settings_row_shown(definition, settings_game)) ++count;}item.value = expanded_settings_sections_.count(action_key) ? "Hide" : "Show " + std::to_string(count);- } else if (settings_ready && action_key.rfind("heading-", 0) == 0) {- // Names the rows below it; not focusable (move_game_settings skips it).+ } else if (SheetDecoration(action_key)) {+ // Names the rows below it, or (a divider) only sets them apart; never focused (move skips it).item.kind = RowKind::Separator;item.action.clear();item.enabled = false;@@ -7394,7 +7404,12 @@ void Simulation::rebuild_view() {void Simulation::open_modal(ModalEntry modal) {if (!state_.navigation.modals.empty()) modal.opener_focus_key = state_.navigation.modals.back().action_keys[static_cast<std::size_t>(state_.navigation.modals.back().focused_action)];state_.navigation.modals.push_back(std::move(modal));- state_.navigation.focus_key = state_.navigation.modals.back().action_keys[static_cast<std::size_t>(state_.navigation.modals.back().focused_action)];+ // A sheet opens on its first row the focus can take, past a heading.+ auto& opened = state_.navigation.modals.back();+ const int last = static_cast<int>(opened.action_keys.size()) - 1;+ while (opened.focused_action < last && SheetDecoration(opened.action_keys[static_cast<std::size_t>(opened.focused_action)]))+ ++opened.focused_action;+ state_.navigation.focus_key = opened.action_keys[static_cast<std::size_t>(opened.focused_action)];}void Simulation::close_modal() {@@ -7877,9 +7892,9 @@ void Simulation::move(int delta_x, int delta_y) {const int delta = delta_y != 0 ? delta_y : delta_x;const int last = static_cast<int>(modal.action_keys.size()) - 1;modal.focused_action = std::clamp(modal.focused_action + delta, 0, last);- // Game settings' topic headings only label the rows below them: focus goes on past them.- if (modal.id == "game-settings" && delta != 0) {- const auto heading = [&modal](int index) { return modal.action_keys[static_cast<std::size_t>(index)].rfind("heading-", 0) == 0; };+ // A sheet's headings and dividers only set its rows apart: focus goes on past them.+ if (delta != 0) {+ const auto heading = [&modal](int index) { return SheetDecoration(modal.action_keys[static_cast<std::size_t>(index)]); };const int step = delta > 0 ? 1 : -1;while (heading(modal.focused_action) && modal.focused_action + step >= 0 && modal.focused_action + step <= last)modal.focused_action += step;@@ -10052,6 +10067,8 @@ bool Simulation::action(const std::string& logical_action) {const auto key = logical_action.substr(6);const auto found = std::find_if(view_.rows.begin(), view_.rows.end(), [&key](const ViewRow& row) { return row.key == key; });if (found == view_.rows.end()) { last_error_ = "Unknown focus key: " + key; return false; }+ // A sheet's headings and dividers are never focused, however the focus is asked for.+ if (!state_.navigation.modals.empty() && SheetDecoration(key)) { last_error_ = "Not focusable: " + key; return false; }state_.navigation.focus_key = key; state_.navigation.selected_index = static_cast<int>(std::distance(view_.rows.begin(), found));if (!state_.navigation.modals.empty()) state_.navigation.modals.back().focused_action = state_.navigation.selected_index;save_profile(); rebuild_view(); return true;@@ -10158,21 +10175,24 @@ bool Simulation::action(const std::string& logical_action) {// Demos is listed while there are demos, or while they are hidden so they can be shown again.const bool demos = state_.library.filters.contains("hide-demos") ||std::any_of(state_.games.begin(), state_.games.end(), [](const Game& game) { return game.demo; });- std::vector<std::string> actions = live()- ? (dated ? std::vector<std::string>{"sort-name", "sort-recent-played", "sort-recent-added", "sort-playtime",- "filter-compat-playable", "filters-reset", "refresh-library", "cancel"}- : std::vector<std::string>{"sort-name", "sort-recent-played", "sort-playtime", "filter-compat-playable",- "filters-reset", "refresh-library", "cancel"})- : std::vector<std::string>{"sort-name", "sort-recent-played", "sort-recent-added", "sort-playtime", "sort-install-size",- "filter-installed", "filter-genre-adventure", "filter-controller-full", "filter-compat-playable",- "filters-reset", "refresh-library", "cancel"};+ // Sort, then Filter, then the actions after an untitled divider.+ std::vector<std::string> sorts = live()+ ? (dated ? std::vector<std::string>{"sort-name", "sort-recent-played", "sort-recent-added", "sort-playtime"}+ : std::vector<std::string>{"sort-name", "sort-recent-played", "sort-playtime"})+ : std::vector<std::string>{"sort-name", "sort-recent-played", "sort-recent-added", "sort-playtime", "sort-install-size"};+ std::vector<std::string> filters = live()+ ? std::vector<std::string>{"filter-compat-playable"}+ : std::vector<std::string>{"filter-installed", "filter-genre-adventure", "filter-controller-full", "filter-compat-playable"};// Family sharing likewise, for games a Steam family member shares.const bool family = state_.library.filters.contains("hide-family") ||std::any_of(state_.games.begin(), state_.games.end(), [](const Game& game) { return game.family_shared; });- if (demos)- actions.insert(std::find(actions.begin(), actions.end(), "filters-reset"), "filter-hide-demos");- if (family)- actions.insert(std::find(actions.begin(), actions.end(), "filters-reset"), "filter-hide-family");+ if (demos) filters.push_back("filter-hide-demos");+ if (family) filters.push_back("filter-hide-family");+ std::vector<std::string> actions{"heading-sort"};+ actions.insert(actions.end(), sorts.begin(), sorts.end());+ actions.push_back("heading-filter");+ actions.insert(actions.end(), filters.begin(), filters.end());+ actions.insert(actions.end(), {"divider", "filters-reset", "refresh-library", "cancel"});open_modal({"filters", "Sort and filters", state_.navigation.focus_key, std::move(actions), 0, false});}}diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex 4cbca37..db838d4 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -821,6 +821,7 @@ struct ViewRow {bool selected = false;bool dangerous = false;bool modified = false; // Game settings: the player changed this value+ bool checked = false; // a sheet's pick-one row (the sort): the current choice, an accent tickstd::string section; // Settings: the rail section the row belongs tostd::string tone; // Saves: the status colour (good, busy, attention, problem, quiet)std::string aside; // Saves: the right-hand note (size, last sync)diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cppindex 662fec7..2a62888 100644--- a/src/homebrew/view.cpp+++ b/src/homebrew/view.cpp@@ -22,6 +22,7 @@#include "ui/components/keyboard.hpp"#include "ui/components/list.hpp"#include "ui/components/progress.hpp"+#include "ui/components/surface.hpp"#include "ui/components/tabs.hpp"#include "ui/fonts.hpp"#include "ui/glyphs.hpp"@@ -4265,6 +4266,9 @@ class Render::Implreturn about_height(row) + 12.0F;if (settings_sheet && row.kind == RowKind::Heading)return 54.0F + 12.0F;+ // An untitled separator is a divider: a line, shorter than a heading.+ if (row.kind == RowKind::Separator && row.title.empty())+ return 30.0F;if (row.kind == RowKind::Heading || row.kind == RowKind::Separator)return 54.0F;const bool checkbox = (view.surface == "kept-data" || view.surface == "leftover-titles" || (view.surface == "collections" && row.action.rfind("collection-toggle-", 0) == 0)) &&@@ -4349,6 +4353,17 @@ class Render::Implfocus_ring(overlay_, rect, amount);continue;}+ if (row.kind == RowKind::Separator && row.title.empty())+ {+ // Sets the rows after it apart, with no name: a line inset as a heading's words are.+ ui::DividerStyle line;+ line.theme = theme_;+ line.on_panel = true;+ line.color = kText.with_alpha(0.12F);+ ui::Canvas canvas{overlay_, fonts_, renderer_.glass_texture(), clock_};+ ui::draw_divider(canvas, line, {bounds.x + 12.0F, y, bounds.w - 24.0F, 18.0F});+ continue;+ }if (row.kind == RowKind::Heading || row.kind == RowKind::Separator){ui::text(overlay_, fonts_.display, ui::upper(row.title), bounds.x + 12.0F, y + 28.0F,@@ -4419,6 +4434,13 @@ class Render::Implui::text(overlay_, fonts_.regular, fit(fonts_.regular, value, 22.0F, value_width), rect.x + rect.w - 24.0F,described ? rect.y + 52.0F : rect.cy() + 8.0F, 22.0F,row.modified || row.selected ? kAccent : row.enabled ? kSecondary : kMuted, gfx::Align::right);+ if (row.checked && value.empty())+ {+ // The current choice of a pick-one group: a tick drawn as two strokes, where a value would go.+ const float cx = rect.x + rect.w - 35.0F, cy = rect.cy();+ overlay_.line(cx - 8.0F, cy + 0.5F, cx - 2.5F, cy + 6.0F, 2.8F, kAccent);+ overlay_.line(cx - 2.5F, cy + 6.0F, cx + 8.0F, cy - 5.5F, 2.8F, kAccent);+ }if (row.progress > 0.0F)painter.progress({rect.x + 22.0F, rect.y + 60.0F, rect.w - 44.0F, 6.0F}, row.progress);focus_ring(overlay_, rect, amount);diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cppindex beecd59..ac39aab 100644--- a/tests/homebrew_library_model_test.cpp+++ b/tests/homebrew_library_model_test.cpp@@ -1186,6 +1186,57 @@ void live_demos_filter_defaults_on() {check(row!=nullptr && !row->selected,"Demos stays listed while demos are hidden");}+// Sort and filters is in sections: Sort, Filter, then the actions after an untitled divider. Headings and the+// divider never take the focus; the sort in use has a tick and every filter shows On or Off.+void live_filters_sheet_sections() {+ auto model=make_live();+ model.UpdateAccount({AuthState::SignedIn,"123","Synthetic",{},{},true});+ auto demo=game(SteamId(43),"Synthetic Demo");demo.demo=true;+ check(model.UpdateLibrary({{game(SteamId(42),"Synthetic"),demo},false,{},false,false,{}}),"library with a demo loaded");+ check(model.action("r1") && model.action("triangle"),"live filter modal opens");+ const auto& actions=model.state().navigation.modals.back().action_keys;+ check(actions==std::vector<std::string>{"heading-sort","sort-name","sort-recent-played","sort-playtime","heading-filter",+ "filter-compat-playable","filter-hide-demos","divider","filters-reset",+ "refresh-library","cancel"},"sorts, filters and actions in their sections");+ check(model.state().navigation.focus_key=="sort-name","the sheet opens on its first sort, past the heading");+ const auto* heading=find_row(model,"heading-sort");+ const auto* divider=find_row(model,"divider");+ check(heading && heading->kind==RowKind::Separator && heading->title=="Sort" && !heading->enabled &&+ divider && divider->kind==RowKind::Separator && divider->title.empty() && !divider->enabled,+ "a titled heading and an untitled divider");+ const auto* name=find_row(model,"sort-name");+ const auto* played=find_row(model,"sort-recent-played");+ check(name && name->checked && played && !played->checked,"the sort in use has a tick");+ const auto* playable=find_row(model,"filter-compat-playable");+ check(playable && playable->kind==RowKind::Toggle && !playable->selected && playable->value=="Off","Playable is a toggle, off");++ // Up from the first sort stays there; down goes past the Filter heading and the divider.+ check(model.action("up") && model.state().navigation.focus_key=="sort-name","no row above the first sort");+ for(const auto* expected:{"sort-recent-played","sort-playtime","filter-compat-playable","filter-hide-demos","filters-reset"})+ check(model.action("down") && model.state().navigation.focus_key==expected,"down skips headings and the divider");+ check(model.action("up") && model.state().navigation.focus_key=="filter-hide-demos","up goes back past the divider");++ // A jump that ends on a heading or the divider goes on past it, and asking for one directly is refused.+ check(model.action("focus:sort-playtime") && model.action("r2") && model.state().navigation.focus_key=="filters-reset",+ "a jump down lands past the divider");+ check(model.action("l2") && model.state().navigation.focus_key=="sort-playtime","a jump up lands past the Filter heading");+ check(model.action("focus:sort-name") && model.action("l2") && model.state().navigation.focus_key=="sort-name",+ "a jump up from the first sort stays on it");+ check(!model.action("focus:heading-sort") && !model.action("focus:divider") && model.state().navigation.focus_key=="sort-name",+ "a heading or the divider can't be focused directly");+ // The last action can be reached, past everything else.+ for(int step=0;step<12;++step) model.action("down");+ check(model.state().navigation.focus_key=="cancel","down ends on the last action");++ activate(model,"filter-compat-playable");+ check(model.action("triangle"),"filter modal opens again");+ playable=find_row(model,"filter-compat-playable");+ check(playable && playable->selected && playable->value=="On","Playable shows on");+ activate(model,"sort-recent-played");+ check(model.action("triangle"),"filter modal opens once more");+ check(find_row(model,"sort-recent-played")->checked && !find_row(model,"sort-name")->checked,"the tick follows the sort");+}+// A game a Steam family member shares keeps that mark in the Library; the rest of the library does not.void live_family_shared_projected() {auto model=make_live();@@ -1284,6 +1335,8 @@ void continue_playing_more_keeps_the_chosen_sort() {check(model.action("l1"),"back to Home");for(int step=0;step<30 && model.state().navigation.focus_key!="shelf-continue-more";++step) model.action("right");check(model.action("cross") && model.action("triangle"),"sort sheet from the More view");+ check(find_row(model,"sort-recent-played")->checked && !find_row(model,"sort-playtime")->checked,+ "the tick shows the More view's order, not the saved sort");activate(model,"sort-name");check(model.state().library.sort=="name" && model.visible_games().front()->id==SteamId(1),"a chosen sort replaces the More order");check(model.action("l1") && model.action("r1") && model.state().library.sort=="name" &&@@ -4016,6 +4069,7 @@ void live_game_update() {}int main() {+ live_filters_sheet_sections();live_game_update();live_install_language_row();live_install_version_row();diff --git a/tests/homebrew_simulation_test.cpp b/tests/homebrew_simulation_test.cppindex 9c9ca69..156a34b 100644--- a/tests/homebrew_simulation_test.cpp+++ b/tests/homebrew_simulation_test.cpp@@ -178,6 +178,13 @@ void t03_search_filters_and_focus_reconciliation(const std::filesystem::path& fisimulation.action("triangle");activate(simulation, "filter-controller-full");simulation.action("triangle");+ const auto filter_row = [&simulation](const std::string& key) {+ return *std::find_if(simulation.view().rows.begin(), simulation.view().rows.end(),+ [&key](const auto& row) { return row.key == key; });+ };+ check(filter_row("filter-controller-full").selected && filter_row("filter-controller-full").value == "On" &&+ filter_row("filter-installed").value == "Off" && filter_row("sort-playtime").checked,+ "T03 a filter shows On when it applies, and the sort in use has its tick");activate(simulation, "filters-reset");check(simulation.state().library.filters.empty() && simulation.state().library.sort == "name","T03 reset clears every filter and restores name sort");