UI: Split active/visible concepts & fix nav forwarding

This commit is contained in:
Luke Street
2026-06-16 15:10:09 -06:00
parent cc9c15de54
commit f5642f3073
6 changed files with 29 additions and 20 deletions
+1 -1
+14 -9
View File
@@ -3,9 +3,7 @@
#include "aurora/rmlui.hpp"
#include "ui.hpp"
#include "Z2AudioLib/Z2SeMgr.h"
#include "m_Do/m_Do_audio.h"
#include <imgui.h>
namespace dusk::ui {
namespace {
@@ -30,19 +28,19 @@ Document::Document(const Rml::String& source, bool passive)
return;
}
const auto cmd = map_nav_event(event);
if (cmd != NavCommand::Menu && !visible()) {
if (cmd != NavCommand::Menu && (!visible() || !active())) {
event.StopImmediatePropagation();
}
},
true);
const auto blockUnlessVisible = [this](Rml::Event& event) {
if (!visible()) {
const auto blockUnlessActive = [this](Rml::Event& event) {
if (!visible() || !active()) {
event.StopImmediatePropagation();
}
};
listen(Rml::EventId::Mouseover, blockUnlessVisible, true);
listen(Rml::EventId::Click, blockUnlessVisible, true);
listen(Rml::EventId::Scroll, blockUnlessVisible, true);
listen(Rml::EventId::Mouseover, blockUnlessActive, true);
listen(Rml::EventId::Click, blockUnlessActive, true);
listen(Rml::EventId::Scroll, blockUnlessActive, true);
listen(Rml::EventId::Keydown, [this](Rml::Event& event) {
if (mPassive) {
@@ -124,9 +122,16 @@ bool Document::visible() const {
return *mDocument->GetProperty(Rml::PropertyId::Visibility) == Rml::Style::Visibility::Visible;
}
bool Document::active() const {
return !mClosed && !mPendingClose;
}
bool Document::handle_nav_event(Rml::Event& event) {
if (!active()) {
return false;
}
const auto cmd = map_nav_event(event);
if (cmd == NavCommand::None) {
if (cmd == NavCommand::None || (cmd != NavCommand::Menu && !visible())) {
return false;
}
return handle_nav_command(event, cmd);
+3 -3
View File
@@ -18,6 +18,7 @@ public:
virtual void update();
virtual bool focus();
virtual bool visible() const;
virtual bool active() const;
void listen(Rml::Element* element, Rml::EventId event, ScopedEventListener::Callback callback,
bool capture = false);
@@ -41,12 +42,11 @@ public:
push_document(std::move(document));
hide(false);
}
void pop() {
void pop(bool show = true) {
hide(true);
show_top_document();
focus_top_document(show);
}
bool pending_close() const { return mPendingClose; }
bool closed() const { return mClosed; }
bool handle_nav_event(Rml::Event& event);
+1 -1
View File
@@ -715,7 +715,7 @@ Prelaunch::Prelaunch() : Document(kDocumentSource), mRoot(mDocument->GetElementB
}
IsGameLaunched = true;
hide(true);
pop(false);
});
apply_intro_animation(mMenuButtons.back()->root(), "delay-1");
+9 -5
View File
@@ -195,9 +195,13 @@ Document& push_document(std::unique_ptr<Document> doc, bool show, bool passive)
return ret;
}
void show_top_document() noexcept {
void focus_top_document(bool show) noexcept {
if (auto* doc = top_document()) {
doc->show();
if (show) {
doc->show();
} else {
doc->focus();
}
}
input::sync_input_block();
}
@@ -210,13 +214,13 @@ bool any_document_visible() noexcept {
bool is_prelaunch_open() noexcept {
return std::any_of(sDocumentStack.begin(), sDocumentStack.end(), [](const auto& doc) {
const auto* prelaunch = dynamic_cast<const Prelaunch*>(doc.get());
return prelaunch != nullptr && !prelaunch->pending_close() && !prelaunch->closed();
return prelaunch != nullptr && prelaunch->active();
});
}
Document* top_document() noexcept {
for (auto& doc : std::views::reverse(sDocumentStack)) {
if (!doc->closed() && !doc->pending_close()) {
if (doc->active()) {
return doc.get();
}
}
@@ -259,7 +263,7 @@ void update() noexcept {
context->GetFocusElement() == context->GetRootElement()))
{
for (auto& doc : std::views::reverse(sDocumentStack)) {
if (!doc->closed() && !doc->pending_close() && doc->focus()) {
if (doc->active() && doc->focus()) {
break;
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ void update() noexcept;
Document& push_document(
std::unique_ptr<Document> doc, bool show = true, bool passive = false) noexcept;
void show_top_document() noexcept;
void focus_top_document(bool show) noexcept;
bool any_document_visible() noexcept;
bool is_prelaunch_open() noexcept;
Document* top_document() noexcept;