mirror of
https://github.com/XITRIX/NXKit.git
synced 2026-05-30 11:46:52 +00:00
46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include <UIPress.h>
|
|
#include <UIWindow.h>
|
|
#include <UIViewController.h>
|
|
|
|
namespace NXKit {
|
|
|
|
UIPress::UIPress(Timer timestamp):
|
|
_timestamp(timestamp)
|
|
{ }
|
|
|
|
void UIPress::setForWindow(const std::shared_ptr<UIWindow>& window) {
|
|
_window = window;
|
|
|
|
if (!window || !window->rootViewController()) {
|
|
_responder = window;
|
|
return;
|
|
}
|
|
|
|
// auto weakFocus = window->focusSystem()->focusedItem();
|
|
// if (!weakFocus.expired()) {
|
|
// auto focus = std::dynamic_pointer_cast<UIResponder>(weakFocus.lock());
|
|
// if (focus) {
|
|
// _responder = focus;
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
auto vc = window->rootViewController();
|
|
while (!vc->children().empty()) {
|
|
vc = vc->children().front();
|
|
}
|
|
|
|
_responder = vc->view();
|
|
}
|
|
|
|
void UIPress::runPressActionOnRecognizerHierachy(const std::function<void(std::shared_ptr<UIGestureRecognizer>)>& action) {
|
|
for (const auto& recognizer: _gestureRecognizers) {
|
|
if (_hasBeenCancelledByAGestureRecognizer) return;
|
|
if (recognizer.expired() || !recognizer.lock()->isEnabled()) continue;
|
|
action(recognizer.lock());
|
|
}
|
|
}
|
|
|
|
}
|
|
|