overlays/home: Refactor to support having some home pages inside other containers

This commit is contained in:
kd-11 2026-03-08 18:07:06 +03:00 committed by kd-11
parent 5cb688f309
commit 3c16105c3b
6 changed files with 50 additions and 15 deletions

View file

@ -5,14 +5,14 @@ namespace rsx
{
namespace overlays
{
home_menu_entry::home_menu_entry(const std::string& text)
home_menu_entry::home_menu_entry(const std::string& text, u16 width)
{
std::unique_ptr<overlay_element> text_stack = std::make_unique<vertical_layout>();
std::unique_ptr<overlay_element> padding = std::make_unique<spacer>();
std::unique_ptr<overlay_element> title = std::make_unique<label>(text);
padding->set_size(1, 1);
title->set_size(overlay::virtual_width - 2 * menu_entry_margin, menu_entry_height);
title->set_size(width, menu_entry_height);
title->set_font("Arial", 16);
title->set_wrap_text(true);
title->align_text(text_align::center);

View file

@ -25,7 +25,7 @@ namespace rsx
struct home_menu_entry : horizontal_layout
{
public:
home_menu_entry(const std::string& text);
home_menu_entry(const std::string& text, u16 width);
};
template <typename T, typename C>

View file

@ -28,7 +28,7 @@ namespace rsx
m_config_changed = std::make_shared<bool>(g_backup_cfg.to_string() != g_cfg.to_string());
std::unique_ptr<overlay_element> resume = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_RESUME));
std::unique_ptr<overlay_element> resume = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_RESUME), width);
add_item(resume, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;
@ -41,7 +41,7 @@ namespace rsx
if (rsx::overlays::friends_list_dialog::rpcn_configured())
{
std::unique_ptr<overlay_element> friends = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_FRIENDS));
std::unique_ptr<overlay_element> friends = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_FRIENDS), width);
add_item(friends, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;
@ -76,7 +76,7 @@ namespace rsx
}
if (!trop_name.empty())
{
std::unique_ptr<overlay_element> trophies = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_TROPHIES));
std::unique_ptr<overlay_element> trophies = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_TROPHIES), width);
add_item(trophies, [trop_name = std::move(trop_name)](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;
@ -93,7 +93,7 @@ namespace rsx
});
}
std::unique_ptr<overlay_element> screenshot = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_SCREENSHOT));
std::unique_ptr<overlay_element> screenshot = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_SCREENSHOT), width);
add_item(screenshot, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;
@ -102,7 +102,7 @@ namespace rsx
return page_navigation::exit_for_screenshot;
});
std::unique_ptr<overlay_element> recording = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_RECORDING));
std::unique_ptr<overlay_element> recording = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_RECORDING), width);
add_item(recording, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;
@ -112,7 +112,7 @@ namespace rsx
return page_navigation::exit;
});
std::unique_ptr<overlay_element> fullscreen = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_TOGGLE_FULLSCREEN));
std::unique_ptr<overlay_element> fullscreen = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_TOGGLE_FULLSCREEN), width);
add_item(fullscreen, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross)
@ -125,7 +125,7 @@ namespace rsx
add_page(std::make_shared<home_menu_savestate>(x, y, width, height, use_separators, this));
std::unique_ptr<overlay_element> restart = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_RESTART));
std::unique_ptr<overlay_element> restart = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_RESTART), width);
add_item(restart, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;
@ -141,7 +141,7 @@ namespace rsx
return page_navigation::exit;
});
std::unique_ptr<overlay_element> exit_game = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_EXIT_GAME));
std::unique_ptr<overlay_element> exit_game = std::make_unique<home_menu_entry>(get_localized_string(localized_string_id::HOME_MENU_EXIT_GAME), width);
add_item(exit_game, [](pad_button btn) -> page_navigation
{
if (btn != pad_button::cross) return page_navigation::stay;

View file

@ -40,6 +40,16 @@ namespace rsx
set_pos(x, y);
}
void home_menu_page::on_activate()
{
hide_scroll_indicators(false);
}
void home_menu_page::on_deactivate()
{
hide_scroll_indicators(true);
}
void home_menu_page::set_current_page(home_menu_page* page)
{
if (page)
@ -79,7 +89,7 @@ namespace rsx
void home_menu_page::add_page(std::shared_ptr<home_menu_page> page)
{
ensure(page);
std::unique_ptr<overlay_element> elem = std::make_unique<home_menu_entry>(page->title);
std::unique_ptr<overlay_element> elem = std::make_unique<home_menu_entry>(page->title, w);
m_pages.push_back(page);
add_item(elem, [this, page](pad_button btn) -> page_navigation
@ -100,6 +110,13 @@ namespace rsx
void home_menu_page::apply_layout(bool center_vertically)
{
if (!m_items.empty())
{
m_entries = std::move(m_items);
}
clear_items();
// Center vertically if necessary
if (center_vertically)
{
@ -118,6 +135,7 @@ namespace rsx
for (auto& entry : m_entries)
{
entry->set_pos(0, 0);
add_entry(entry);
}
}
@ -275,6 +293,19 @@ namespace rsx
m_reset_btn.translate(_x, _y);
}
void home_menu_page::set_size(u16 _w, u16 _h)
{
const auto prev_w = w;
list_view::set_size(_w, _h);
for (auto& entry : m_items)
{
entry->set_size(_w, entry->h);
}
apply_layout();
}
compiled_resource& home_menu_page::get_compiled()
{
if (!is_compiled() || (m_message_box && !m_message_box->is_compiled()))
@ -285,7 +316,7 @@ namespace rsx
{
compiled_resources = page->get_compiled();
}
else
else if (visible)
{
compiled_resources = list_view::get_compiled();

View file

@ -18,8 +18,12 @@ namespace rsx
page_navigation handle_button_press(pad_button button_press, bool is_auto_repeat, u64 auto_repeat_interval_ms);
void translate(s16 _x, s16 _y) override;
void set_size(u16 _w, u16 _h) override;
compiled_resource& get_compiled() override;
void on_activate();
void on_deactivate();
virtual bool show_reset_button() const { return false; }
bool is_current_page = false;

View file

@ -15,7 +15,7 @@ namespace rsx
const bool suspend_mode = g_cfg.savestate.suspend_emu.get();
std::unique_ptr<overlay_element> save_state = std::make_unique<home_menu_entry>(
get_localized_string(suspend_mode ? localized_string_id::HOME_MENU_SAVESTATE_AND_EXIT : localized_string_id::HOME_MENU_SAVESTATE_SAVE));
get_localized_string(suspend_mode ? localized_string_id::HOME_MENU_SAVESTATE_AND_EXIT : localized_string_id::HOME_MENU_SAVESTATE_SAVE), width);
add_item(save_state, [suspend_mode](pad_button btn) -> page_navigation
{
@ -40,7 +40,7 @@ namespace rsx
if (boot_current_game_savestate(true, save_index))
{
const localized_string_id str_id = static_cast<localized_string_id>(static_cast<usz>(localized_string_id::HOME_MENU_RELOAD_SAVESTATE) + (save_index - 1));
std::unique_ptr<overlay_element> reload_state = std::make_unique<home_menu_entry>(get_localized_string(str_id));
std::unique_ptr<overlay_element> reload_state = std::make_unique<home_menu_entry>(get_localized_string(str_id), width);
add_item(reload_state, [save_index](pad_button btn) -> page_navigation
{