Settings menu API
Include <RPS_UI_Framework/SettingsMenu.h> and acquire rpsui::api::settings_menu::Api with rpsui::api::acquire, as in getting started. Interface SettingsMenu (id 9), version 2.0. The table needs an owner token from the Framework interface's registerConsumer.
RPS UI's settings menu holds the Spawner, the Console and the pages mods add on one panel; see the menu's guide. Mods' settings are not in it: each mod has its own page in Mods Config FO4 VR. The menu has no way in of its own: a mod opens it, as RobCo PALM's Config does, and may add pages of its own to the menu's top bar, as PALM does for its wheel pages and ROCK for its setup wizard.
Opening and closing
const rpsui::api::settings_menu::Api* menu{};
rpsui::api::acquire(query, menu);
rpsui::api::settings_menu::OpenRequest request{};
request.pose = wheelPose; // or leave hasPose 0: in front of the headset
request.hasPose = 1;
menu->open(owner, &request);
| Function | Thread | Result |
|---|---|---|
open(owner, request) | Game | Ok; FrameworkNotReady outside gameplay or before the host is ready; ResourceConflict while the menu is open or opening; InvalidPose for a pose RPS UI cannot place a panel at; OwnerNotRegistered for an unknown owner. |
close(owner) | Game | Ok. |
isOpen() | Any | The menu is open or opening. |
closedCount() | Any | A count that increases each time the menu closes; compare it with the last value you saw to refresh what the Spawner or the Console may have changed. |
The menu's size is the player's last menu size; a pose sets only where it appears.
Pages
A page is a tab after Spawner and Console. It draws with the mod's own Dear ImGui copy, exactly like a Framework panel: the registration carries the mod's ImGuiBuild, and each frame passes the host's context through imgui, which the page binds with RPSUI_IMGUI_BIND before any ImGui call. See Dear ImGui integration.
bool RPSUI_CALL drawPage(const rpsui::api::settings_menu::PageDrawFrame* frame, void* user) noexcept
{
RPSUI_IMGUI_BIND(frame->imgui);
ImGui::TextUnformatted("My page");
return false; // Back not used: the menu goes back
}
rpsui::api::settings_menu::PageRegistration page{};
std::snprintf(page.pageId, sizeof(page.pageId), "mymod.page");
std::snprintf(page.title, sizeof(page.title), "My page");
page.sortOrder = 10;
page.imgui = RPSUI_IMGUI_BUILD();
page.drawCallback = &drawPage;
std::uint64_t handle{};
menu->registerPage(owner, &page, &handle);
drawCallbackruns on the render thread inside a child window that fills the page area.widthandheightare that area in the menu's layout units;fontsare the theme's faces byframework::FontRole. A page adds no fonts of its own;d3dDeviceis for the page's own textures.backPressedis 1 on the frame after a Back press while the page is shown. Return true when the page used it (closing a sub-view of its own); otherwise the menu goes back: to its home tab, or closed when the page is the home tab.- Pages are ordered by
sortOrder, then by registration. At mostkMaxPages(8) pages exist at once; one more returnsCapacityReached. ApageIdalready registered returnsResourceConflict. unregisterPage(owner, handle)returnsCallbackBusywhile the page's callback is running; call it again. AfterOkthe callback is never called again anduserDatamay be freed. Unregistering the consumer removes its pages.
Home tab and settings
The menu opens on its home tab: the first page mods added (PALM's Wheel items), or the Spawner when there is none. Later openings return to the tab the player closed it on.
The menu has no settings pages. A mod that wants in-game settings ships a page for Mods Config FO4 VR, as every RPS mod does; RPS UI Framework's own Theme, Sharpness and haptics are on its page there too.
Complete public declarations: RPS_UI_Framework/SettingsMenu.h
#pragma once
#include "Framework.h"
// The settings menu: the Spawner, the Console and the pages mods add, on one
// panel RPS UI owns. A mod opens it (RobCo PALM's wheel does) and may add its own pages,
// which it draws with its own copy of Dear ImGui exactly like a Framework panel. Owner tokens come from
// Framework::registerConsumer.
#pragma pack(push, 8)
namespace rpsui::api::settings_menu
{
inline constexpr InterfaceId kInterfaceId = InterfaceId::SettingsMenu;
inline constexpr std::uint32_t kMajor = 2;
inline constexpr std::uint32_t kMinor = 0;
inline constexpr std::uint32_t kMaxPages = 8;
struct OpenRequest
{
std::uint32_t size{ sizeof(OpenRequest) };
std::uint32_t version{ kRecordVersion };
// Where the menu appears; its size is the player's last menu size. Without a
// pose it opens in front of the headset.
framework::PanelPose pose{};
std::uint8_t hasPose{ 0 };
std::uint8_t reservedBytes[7]{};
};
/*
* A page's frame, between the menu's NewFrame and Render, inside a child window
* that fills the page area. Bind imgui with RPSUI_IMGUI_BIND before any ImGui call.
* Coordinates are the menu's layout units. fonts are the theme's faces by
* framework::FontRole; a page adds no fonts of its own.
*/
struct PageDrawFrame
{
std::uint32_t size{ sizeof(PageDrawFrame) };
std::uint32_t version{ kRecordVersion };
std::uint64_t pageHandle{ 0 };
std::uint64_t contextGeneration{ 0 };
void* d3dDevice{ nullptr }; // ID3D11Device*, for the page's own textures
framework::ImGuiBinding imgui{};
const framework::Theme* theme{ nullptr };
void* fonts[framework::kFontRoleCount]{};
float width{ 0.0f };
float height{ 0.0f };
float deltaSeconds{ 0.0f };
// 1 on the frame after a Back press on the menu; a page that consumes it (closing
// its own sub-view) returns true from its callback, otherwise the menu goes back.
std::uint8_t backPressed{ 0 };
std::uint8_t reservedBytes[3]{};
};
// Render thread. Returns true when the page used backPressed.
using PageDrawCallback = bool(RPSUI_CALL*)(const PageDrawFrame* frame, void* userData) noexcept;
struct PageRegistration
{
std::uint32_t size{ sizeof(PageRegistration) };
std::uint32_t version{ kRecordVersion };
char pageId[64]{};
char title[32]{}; // The tab's label
std::int32_t sortOrder{ 0 }; // Pages follow Spawner and Console in this order
std::uint32_t reserved{ 0 };
framework::ImGuiBuild imgui{};
PageDrawCallback drawCallback{ nullptr };
void* userData{ nullptr };
};
struct Api
{
static constexpr InterfaceId interfaceId = kInterfaceId;
static constexpr std::uint32_t majorVersion = kMajor;
static constexpr std::uint32_t minorVersion = kMinor;
// Game thread. FrameworkNotReady outside gameplay or before the host is ready;
// ResourceConflict while the menu is open or opening; InvalidPose for a bad pose.
Result(RPSUI_CALL* open)(std::uint64_t ownerToken, const OpenRequest* request) noexcept {};
Result(RPSUI_CALL* close)(std::uint64_t ownerToken) noexcept {};
// Any thread: the menu is open or opening.
bool(RPSUI_CALL* isOpen)() noexcept {};
// Any thread. CapacityReached past kMaxPages; ResourceConflict for a pageId already
// registered; ImGuiBuildMismatch as for panels. The callback may run until
// unregisterPage returns Ok; CallbackBusy while it runs.
Result(RPSUI_CALL* registerPage)(std::uint64_t ownerToken, const PageRegistration* registration,
std::uint64_t* outPageHandle) noexcept {};
Result(RPSUI_CALL* unregisterPage)(std::uint64_t ownerToken, std::uint64_t pageHandle) noexcept {};
// Any thread: increases each time the menu closes, so a mod can refresh what the
// Spawner or the Console changed.
std::uint64_t(RPSUI_CALL* closedCount)() noexcept {};
};
static_assert(std::is_standard_layout_v<OpenRequest> && sizeof(OpenRequest) == 72);
static_assert(std::is_standard_layout_v<PageDrawFrame> && sizeof(PageDrawFrame) == 120);
static_assert(std::is_standard_layout_v<PageRegistration> && sizeof(PageRegistration) == 184);
static_assert(std::is_standard_layout_v<Api> && sizeof(Api) == 48);
}
#pragma pack(pop)