CreateView
Overview
Section titled “Overview”Creates a PrismaView
instance by loading an HTML file. This is the primary method for initializing UI components in your SKSE plugin.
Syntax
Section titled “Syntax”PrismaView CreateView( const char* htmlPath, OnDomReadyCallback onDomReadyCallback = nullptr);
Parameters
Section titled “Parameters”htmlPath
(required)
Section titled “htmlPath (required)”- Type:
const char*
- Description: The path to the HTML file that will be loaded into the
PrismaView
- Base Directory:
Skyrim/Data/PrismaUI/views/
onDomReadyCallback
(optional)
Section titled “onDomReadyCallback (optional)”- Type:
OnDomReadyCallback
- Default:
nullptr
- Description: An optional callback function that will be invoked when the DOM of this
PrismaView
is fully loaded - Parameters: Takes a single argument - the
PrismaView
instance
Return Value
Section titled “Return Value”Returns a PrismaView
instance representing the created UI component.
Usage Examples
Section titled “Usage Examples”// Simple view creation without callbackPrismaView view = PrismaUI->CreateView("MyPlugin/index.html");
// View creation with DOM ready callbackPrismaView view = PrismaUI->CreateView("MyPlugin/index.html", [](PrismaView view) -> void { // The callback is executed after the DOM tree is fully initialized logger::info("View DOM is ready {}", view);
// You can now safely invoke JavaScript methods PrismaUI->Invoke(view, "initializeUI()");});
#include "PrismaUI_API.h"
PRISMA_UI_API::IVPrismaUI1* PrismaUI;
static void SKSEMessageHandler(SKSE::MessagingInterface::Message* message){ switch (message->type) { case SKSE::MessagingInterface::kDataLoaded: // Initialize PrismaUI API PrismaUI = static_cast<PRISMA_UI_API::IVPrismaUI1*>( PRISMA_UI_API::RequestPluginAPI(PRISMA_UI_API::InterfaceVersion::V1) );
// Create view with comprehensive setup PrismaView view = PrismaUI->CreateView("MyPlugin/index.html", [](PrismaView view) -> void { logger::info("View DOM is ready {}", view);
// Initialize UI state PrismaUI->Invoke(view, "setPlayerName('" + GetPlayerName() + "')"); PrismaUI->Invoke(view, "updateHealthBar(" + std::to_string(GetPlayerHealth()).c_str() + ")"); });
// Register JavaScript event listeners PrismaUI->RegisterJSListener(view, "onButtonClick", [](const char* data) -> void { logger::info("Button clicked with data: {}", data); });
break; }}
File Structure
Section titled “File Structure”Your HTML file should be placed in the following directory structure:
Skyrim/└── Data/ └── PrismaUI/ └── views/ └── MyPlugin/ ├── index.html ├── styles.css └── script.js
Best Practices
Section titled “Best Practices”- Single Instance: Always create only one
PrismaView
per plugin - DOM Ready: Use the callback to initialize your UI state safely
- View Management: Store the returned
PrismaView
instance for later use with other API methods