diff --git a/res/rml/popup.rcss b/res/rml/popup.rcss index 52c3e42d5d..852ab2ce39 100644 --- a/res/rml/popup.rcss +++ b/res/rml/popup.rcss @@ -29,11 +29,11 @@ button { border-bottom: 2dp #92875B; backdrop-filter: blur(5dp); transform: translateY(0); - transition: transform 0.5s cubic-in-out, opacity 0.5s cubic-in-out; + transition: transform 0.2s cubic-in-out; } .popup.popup-hidden { - transform: translateY(-100%); + transform: translateY(-64dp); } .popup .tab-bar { diff --git a/res/rml/popup.rml b/res/rml/popup.rml index 0a9f4824e8..05be1a5c2d 100644 --- a/res/rml/popup.rml +++ b/res/rml/popup.rml @@ -4,6 +4,6 @@ - + diff --git a/src/dusk/ui/popup.cpp b/src/dusk/ui/popup.cpp index e2f5815e50..54b016dade 100644 --- a/src/dusk/ui/popup.cpp +++ b/src/dusk/ui/popup.cpp @@ -14,36 +14,40 @@ namespace dusk::ui { Popup::Popup() : Document("res/rml/popup.rml"), mRoot(mDocument->GetElementById("popup")) { mTabBar = std::make_unique(mRoot, TabBar::Props{.autoSelect = false}); - mTabBar->add_tab("Settings", [this] { - hide(); - // TODO: make this better - auto& settingsWindow = add_document(std::make_unique()); - settingsWindow.show(); - }); + mTabBar->add_tab("Settings", [] { push_document(std::make_unique()); }); mTabBar->add_tab("Warp", [] { // TODO }); - mTabBar->add_tab("Editor", [this] { - hide(); - // TODO: make this better - auto& editorWindow = add_document(std::make_unique()); - editorWindow.show(); - }); + mTabBar->add_tab("Editor", [] { push_document(std::make_unique()); }); mTabBar->add_tab("Reset", [] { // TODO }); mTabBar->add_tab("Exit", [] { // TODO }); + + // Hide document after transition completion + listen(mRoot, Rml::EventId::Transitionend, [this](Rml::Event& event) { + if (event.GetTargetElement() == mRoot && + *mRoot->GetProperty(Rml::PropertyId::Visibility) == Rml::Style::Visibility::Visible && + !mVisible) + { + Document::hide(); + } + }); + + // We start hidden, but want focus for an open nav event + mDocument->Focus(); } void Popup::show() { - if (mDocument == nullptr) { + if (mDocument == nullptr || mVisible) { return; } - mHideDeadline.reset(); Document::show(); + mRoot->SetClass("popup-hidden", false); + mTabBar->set_active_tab(-1); mVisible = true; } @@ -52,15 +56,11 @@ void Popup::hide() { mVisible = false; return; } - - if (auto* popup = mDocument->GetElementById("popup")) { - popup->SetClass("popup-hidden", true); - mHideDeadline = - std::chrono::steady_clock::now() + - std::chrono::milliseconds(500); // Must match the transition duration in popup.rcss - } else { - Document::hide(); + if (!mVisible) { + return; } + + mRoot->SetClass("popup-hidden", true); mVisible = false; } @@ -78,23 +78,12 @@ bool Popup::is_visible() const { bool Popup::handle_nav_command(Rml::Event& event, NavCommand cmd) { if (cmd == NavCommand::Cancel) { - hide(); + toggle(); return true; } return false; } -void Popup::update() { - if (mDocument == nullptr) { - return; - } - if (mHideDeadline.has_value() && std::chrono::steady_clock::now() >= *mHideDeadline) { - mDocument->Hide(); - mHideDeadline.reset(); - } - Document::update(); -} - bool Popup::focus() { return mTabBar->focus(); } diff --git a/src/dusk/ui/popup.hpp b/src/dusk/ui/popup.hpp index 727b211eba..0eeceddde2 100644 --- a/src/dusk/ui/popup.hpp +++ b/src/dusk/ui/popup.hpp @@ -2,14 +2,10 @@ #include "button.hpp" #include "document.hpp" - -#include -#include -#include -#include - #include "tab_bar.hpp" +#include + namespace dusk::ui { class Popup : public Document { @@ -21,7 +17,6 @@ public: void show() override; void hide() override; - void update() override; bool focus() override; void toggle(); @@ -35,7 +30,6 @@ private: std::unique_ptr mTabBar; std::unique_ptr