diff --git a/nui/include/nui/frontend/elements/switch.hpp b/nui/include/nui/frontend/elements/switch.hpp index a9ed2325..6ac78453 100644 --- a/nui/include/nui/frontend/elements/switch.hpp +++ b/nui/include/nui/frontend/elements/switch.hpp @@ -64,7 +64,7 @@ namespace Nui::Elements Nui::ElementRenderer renderer; return !((cases.value == observed.value() ? (renderer = cases.renderer, true) : false) || ...) ? [](auto&, auto const&) -> std::shared_ptr { - Console::log("Nui::switch_ error! No case matched and no default case was provided!"); + Console::warn("Nui::switch_ error! No case matched and no default case was provided!"); return nullptr; } : renderer; }); diff --git a/nui/include/nui/frontend/rpc_client.hpp b/nui/include/nui/frontend/rpc_client.hpp index c6c7fc74..61b90b88 100644 --- a/nui/include/nui/frontend/rpc_client.hpp +++ b/nui/include/nui/frontend/rpc_client.hpp @@ -288,11 +288,31 @@ namespace Nui struct AutoUnregister : public OnDestroy { + AutoUnregister() + : OnDestroy{[]() {}} + {} AutoUnregister(std::string name) : OnDestroy{[name = std::move(name)]() { unregisterFunction(name); }} {} + ~AutoUnregister() = default; + + AutoUnregister(AutoUnregister const&) = delete; + AutoUnregister(AutoUnregister&& other) + : OnDestroy{std::move(other)} + {} + AutoUnregister& operator=(AutoUnregister const&) = delete; + AutoUnregister& operator=(AutoUnregister&& other) + { + OnDestroy::operator=(std::move(other)); + return *this; + } + + void reset() + { + trigger(); + } }; template diff --git a/nui/include/nui/shared/on_destroy.hpp b/nui/include/nui/shared/on_destroy.hpp index 73d654b9..345c33a1 100644 --- a/nui/include/nui/shared/on_destroy.hpp +++ b/nui/include/nui/shared/on_destroy.hpp @@ -31,6 +31,14 @@ namespace Nui if (!wasMoved_ && onDestroy_) onDestroy_(); } + void trigger() + { + if (!wasMoved_ && onDestroy_) + { + onDestroy_(); + onDestroy_ = nullptr; + } + } private: bool wasMoved_; diff --git a/nui/include/nui/utility/move_detector.hpp b/nui/include/nui/utility/move_detector.hpp new file mode 100644 index 00000000..746a7481 --- /dev/null +++ b/nui/include/nui/utility/move_detector.hpp @@ -0,0 +1,32 @@ +#pragma once + +namespace Nui +{ + /** + * @brief Utility class to detect if an object was moved. + */ + class MoveDetector + { + public: + MoveDetector() = default; + MoveDetector(MoveDetector const&) = default; + MoveDetector(MoveDetector&& other) noexcept + { + other.wasMoved_ = true; + } + MoveDetector& operator=(MoveDetector const&) = default; + MoveDetector& operator=(MoveDetector&& other) noexcept + { + other.wasMoved_ = true; + return *this; + } + + bool wasMoved() const noexcept + { + return wasMoved_; + } + + private: + bool wasMoved_{false}; + }; +} \ No newline at end of file diff --git a/nui/include/nui/window.hpp b/nui/include/nui/window.hpp index 56a83ee3..886bd12c 100644 --- a/nui/include/nui/window.hpp +++ b/nui/include/nui/window.hpp @@ -363,7 +363,6 @@ namespace Nui void setConsoleOutput(bool active); #endif - private: void runInJavascriptThread(std::function&& func); public: diff --git a/nui/src/nui/frontend/filesystem/file_dialog.cpp b/nui/src/nui/frontend/filesystem/file_dialog.cpp index faabcf53..afa2fc1e 100644 --- a/nui/src/nui/frontend/filesystem/file_dialog.cpp +++ b/nui/src/nui/frontend/filesystem/file_dialog.cpp @@ -62,7 +62,6 @@ namespace Nui::FileDialog Nui::val opts = Nui::val::object(); convertOptions(opts, options); const auto id = RpcClient::registerFunctionOnce([onResult = std::move(onResult)](Nui::val const& param) { - Console::log(param); if (param.typeOf().as() == "null") onResult(std::nullopt); else