Mods manager UI & logs viewer

This commit is contained in:
Luke Street
2026-07-08 17:51:13 -06:00
parent 36635f8c62
commit bc11bf3563
35 changed files with 1709 additions and 176 deletions
+68 -14
View File
@@ -2,6 +2,7 @@
#include "aurora/lib/window.hpp"
#include "aurora/rmlui.hpp"
#include "fmt/format.h"
#include "magic_enum.hpp"
#include "pane.hpp"
#include "ui.hpp"
@@ -24,17 +25,24 @@ float base_body_padding(Rml::Context* context) noexcept {
return 64.0f * dpRatio;
}
const Rml::String kDocumentSource = R"RML(
Rml::String window_document_source(const std::vector<Rml::String>& styleSheets) {
Rml::String links;
for (const auto& sheet : styleSheets) {
links += fmt::format(" <link type=\"text/rcss\" href=\"{}\" />\n", sheet);
}
return fmt::format(R"RML(
<rml>
<head>
<link type="text/rcss" href="res/rml/tabbing.rcss" />
<link type="text/rcss" href="res/rml/window.rcss" />
</head>
{}</head>
<body>
<window id="window"></window>
</body>
</rml>
)RML";
)RML",
links);
}
const Rml::String kDocumentSourceSmall = R"RML(
<rml>
@@ -51,12 +59,25 @@ const Rml::String kDocumentSourceSmall = R"RML(
} // namespace
Window::Window() : Document(kDocumentSource), mRoot(mDocument->GetElementById("window")) {
mTabBar = std::make_unique<TabBar>(mRoot, TabBar::Props{
.onClose = [this] { request_close(); },
.selectedTabIndex = 0,
.autoSelect = true,
});
Window::Window(Props props)
: Document(window_document_source(props.styleSheets)),
mRoot(mDocument->GetElementById("window")) {
if (props.tabBar) {
mTabBar = std::make_unique<TabBar>(mRoot, TabBar::Props{
.onClose = [this] { request_close(); },
.selectedTabIndex = 0,
.autoSelect = true,
});
} else {
mCloseButton = std::make_unique<Button>(mRoot, Button::Props{}, "close");
mCloseButton->on_nav_command([this](Rml::Event&, NavCommand cmd) {
if (cmd == NavCommand::Confirm) {
request_close();
return true;
}
return false;
});
}
auto elem = mDocument->CreateElement("content");
elem->SetAttribute("id", "content");
@@ -152,7 +173,7 @@ void Window::update_safe_area() noexcept {
}
bool Window::set_active_tab(int index) {
return mTabBar->set_active_tab(index);
return mTabBar && mTabBar->set_active_tab(index);
}
void Window::request_close() {
@@ -167,10 +188,17 @@ bool Window::consume_close_request() {
}
void Window::refresh_active_tab() {
mTabBar->refresh_active_tab();
if (mTabBar) {
mTabBar->refresh_active_tab();
} else {
rebuild_content();
}
}
void Window::add_tab(const Rml::String& title, TabBuilder builder) {
if (!mTabBar) {
return;
}
mTabBar->add_tab(title, [this, builder = std::move(builder)] {
clear_content();
if (builder) {
@@ -179,6 +207,18 @@ void Window::add_tab(const Rml::String& title, TabBuilder builder) {
});
}
void Window::set_content(TabBuilder builder) {
mContentBuilder = std::move(builder);
rebuild_content();
}
void Window::rebuild_content() {
clear_content();
if (mContentBuilder) {
mContentBuilder(mContentRoot);
}
}
void Window::clear_content() noexcept {
mContentComponents.clear();
while (mContentRoot->GetNumChildren() != 0) {
@@ -187,7 +227,15 @@ void Window::clear_content() noexcept {
}
bool Window::focus() {
return mTabBar->focus();
if (mTabBar) {
return mTabBar->focus();
}
for (const auto& component : mContentComponents) {
if (component->focus()) {
return true;
}
}
return mCloseButton && mCloseButton->focus();
}
bool Window::visible() const {
@@ -211,7 +259,7 @@ bool Window::handle_nav_command(Rml::Event& event, NavCommand cmd) {
request_close();
return true;
}
if (mTabBar->handle_nav_command(event, cmd)) {
if (mTabBar && mTabBar->handle_nav_command(event, cmd)) {
return true;
}
return mSuppressNavFallback ? false : Document::handle_nav_command(event, cmd);
@@ -219,6 +267,9 @@ bool Window::handle_nav_command(Rml::Event& event, NavCommand cmd) {
bool Window::handle_content_nav(Rml::Event& event, NavCommand cmd) noexcept {
if (cmd == NavCommand::Up) {
if (!mTabBar) {
return true;
}
if (focus()) {
mDoAud_seStartMenu(kSoundItemFocus);
return true;
@@ -246,6 +297,9 @@ bool Window::handle_content_nav(Rml::Event& event, NavCommand cmd) noexcept {
return true;
}
}
if (!mTabBar) {
return false;
}
return focus();
} else if (cmd == NavCommand::Left || cmd == NavCommand::Right) {
int currentComponent = -1;
@@ -305,4 +359,4 @@ bool WindowSmall::visible() const {
return mRoot->HasAttribute("open");
}
} // namespace dusk::ui
} // namespace dusk::ui