fix focus locking bug
This commit is contained in:
parent
458e56fb4c
commit
23fe07d3d3
9 changed files with 34 additions and 21 deletions
|
|
@ -87,6 +87,7 @@ namespace tp {
|
||||||
[[nodiscard]] halnf getPointerPressure() const;
|
[[nodiscard]] halnf getPointerPressure() const;
|
||||||
|
|
||||||
void setEnableKeyEvents(bool);
|
void setEnableKeyEvents(bool);
|
||||||
|
[[nodiscard]] bool isKeyEventsEnabled() const { return mEnableKeyEvents; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processEventUnguarded();
|
void processEventUnguarded();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ using namespace tp;
|
||||||
class Example : public WidgetApplication {
|
class Example : public WidgetApplication {
|
||||||
public:
|
public:
|
||||||
Example() {
|
Example() {
|
||||||
examplePopup();
|
exampleNestedMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exampleAll() {
|
void exampleAll() {
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,9 @@ void RootWidget::processFrame(EventHandler* events, const RectF& screenArea) {
|
||||||
updateAreaCache(&mRoot, false);
|
updateAreaCache(&mRoot, false);
|
||||||
|
|
||||||
// trigger some widgets by moise pointer
|
// trigger some widgets by moise pointer
|
||||||
mUpdateManager.handleFocusChanges(&mRoot, *events);
|
auto prevFocus = mUpdateManager.getFocusWidget();
|
||||||
|
auto newFocus = mUpdateManager.findFocusWidget(&mRoot, *events);
|
||||||
|
mUpdateManager.handleFocusChanges(newFocus, prevFocus);
|
||||||
|
|
||||||
// check triggered widgets for removal
|
// check triggered widgets for removal
|
||||||
mUpdateManager.clean();
|
mUpdateManager.clean();
|
||||||
|
|
|
||||||
|
|
@ -113,14 +113,17 @@ void DebugManager::recursiveDraw(Canvas& canvas, Widget* active, const Vec2F& po
|
||||||
canvas.text((active->mDebug.id + ":" + std::to_string(depthOrder)).c_str(), area, 22, Canvas::Align::LC, 2, color);
|
canvas.text((active->mDebug.id + ":" + std::to_string(depthOrder)).c_str(), area, 22, Canvas::Align::LC, 2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (active == mRootWidget->mUpdateManager.mFocusLockWidget) {
|
||||||
|
canvas.frame(area, { 0, 1, 0, 1 });
|
||||||
|
}
|
||||||
|
|
||||||
if (active->mFlags.get(Widget::IN_FOCUS)) {
|
if (active->mFlags.get(Widget::IN_FOCUS)) {
|
||||||
if (active->isUpdate()) {
|
if (active->isUpdate()) {
|
||||||
canvas.circle(pos + active->mDebug.pLocal, 5, active->mDebug.col);
|
canvas.circle(pos + active->mDebug.pLocal, 5, active->mDebug.col);
|
||||||
canvas.circle(active->mDebug.pGlobal, 15, active->mDebug.col);
|
canvas.circle(active->mDebug.pGlobal, 15, active->mDebug.col);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBA color = { 1, 0, 0, 0.3f };
|
canvas.debugCross(area, { 0, 1, 0, 1 });
|
||||||
canvas.debugCross(area, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int orderIdx = 0;
|
int orderIdx = 0;
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,11 @@ void UpdateManager::getWidgetPath(Widget* widget, std::vector<Widget*>& out) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
Widget* UpdateManager::findFocusWidget(Widget* root, EventHandler& events) {
|
||||||
auto prevFocus = mInFocusWidget;
|
|
||||||
|
|
||||||
events.setCursorOrigin({ 0, 0 });
|
events.setCursorOrigin({ 0, 0 });
|
||||||
|
|
||||||
mInFocusWidget = nullptr;
|
mInFocusWidget = nullptr;
|
||||||
|
findMouseFocusWidget(root, &mInFocusWidget, events.getPointer());
|
||||||
findFocusWidget(root, &mInFocusWidget, events.getPointer());
|
|
||||||
|
|
||||||
if (mFocusLockWidget) {
|
if (mFocusLockWidget) {
|
||||||
bool hasLockedWidget = false;
|
bool hasLockedWidget = false;
|
||||||
|
|
@ -91,13 +88,17 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (mInFocusWidget == prevFocus) return;
|
return mInFocusWidget;
|
||||||
if (mInFocusWidget) scheduleUpdate(mInFocusWidget, "focus entered");
|
}
|
||||||
|
|
||||||
if (!mInFocusWidget && !prevFocus) return;
|
void UpdateManager::handleFocusChanges(Widget* active, Widget* prevActive) {
|
||||||
|
// if (mInFocusWidget == prevFocus) return;
|
||||||
|
if (active) scheduleUpdate(active, "focus entered");
|
||||||
|
|
||||||
|
if (!active && !prevActive) return;
|
||||||
|
|
||||||
std::vector<Widget*> path2;
|
std::vector<Widget*> path2;
|
||||||
getWidgetPath(mInFocusWidget, path2);
|
getWidgetPath(active, path2);
|
||||||
size_t propLen2 = path2.size();
|
size_t propLen2 = path2.size();
|
||||||
for (auto i = 0; i < path2.size(); i++) {
|
for (auto i = 0; i < path2.size(); i++) {
|
||||||
if (!path2[i]->propagateEventsToChildren()) {
|
if (!path2[i]->propagateEventsToChildren()) {
|
||||||
|
|
@ -107,7 +108,7 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Widget*> path1;
|
std::vector<Widget*> path1;
|
||||||
getWidgetPath(prevFocus, path1);
|
getWidgetPath(prevActive, path1);
|
||||||
size_t propLen1 = path1.size();
|
size_t propLen1 = path1.size();
|
||||||
for (auto i = 0; i < path1.size(); i++) {
|
for (auto i = 0; i < path1.size(); i++) {
|
||||||
if (!path1[i]->propagateEventsToChildren()) {
|
if (!path1[i]->propagateEventsToChildren()) {
|
||||||
|
|
@ -135,7 +136,7 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateManager::findFocusWidget(Widget* iter, Widget** focus, const Vec2F& pointer) {
|
void UpdateManager::findMouseFocusWidget(Widget* iter, Widget** focus, const Vec2F& pointer) {
|
||||||
if (!iter->mArea.getTargetRect().isInside(pointer) || !iter->mFlags.get(Widget::ENABLED)) return;
|
if (!iter->mArea.getTargetRect().isInside(pointer) || !iter->mFlags.get(Widget::ENABLED)) return;
|
||||||
|
|
||||||
if (iter->processesEvents()) {
|
if (iter->processesEvents()) {
|
||||||
|
|
@ -143,7 +144,7 @@ void UpdateManager::findFocusWidget(Widget* iter, Widget** focus, const Vec2F& p
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto child = iter->mDepthOrder.lastNode(); child; child = child->prev) {
|
for (auto child = iter->mDepthOrder.lastNode(); child; child = child->prev) {
|
||||||
findFocusWidget(child->data, focus, pointer - iter->mArea.getTargetRect().pos);
|
findMouseFocusWidget(child->data, focus, pointer - iter->mArea.getTargetRect().pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,6 +216,6 @@ void UpdateManager::lockFocus(tp::Widget* widget) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateManager::freeFocus(tp::Widget* widget) {
|
void UpdateManager::freeFocus(tp::Widget* widget) {
|
||||||
// DEBUG_ASSERT(mFocusLockWidget == widget)
|
DEBUG_ASSERT(mFocusLockWidget == widget)
|
||||||
mFocusLockWidget = nullptr;
|
mFocusLockWidget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -7,9 +7,10 @@ using namespace tp;
|
||||||
void ScrollableBarWidget::process(const EventHandler& events) {
|
void ScrollableBarWidget::process(const EventHandler& events) {
|
||||||
// all content is visible no need to process anything
|
// all content is visible no need to process anything
|
||||||
if (mSizeFactor >= 1) {
|
if (mSizeFactor >= 1) {
|
||||||
|
if (mScrolling) freeFocus();
|
||||||
|
|
||||||
mScrolling = false;
|
mScrolling = false;
|
||||||
mPosFactor = mSizeFactor / 2.f;
|
mPosFactor = mSizeFactor / 2.f;
|
||||||
freeFocus();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ namespace tp {
|
||||||
|
|
||||||
using DFSAction = std::function<void(Widget*)>;
|
using DFSAction = std::function<void(Widget*)>;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
enum Flags : int1 {
|
enum Flags : int1 {
|
||||||
ENABLED = 0,
|
ENABLED = 0,
|
||||||
NEEDS_UPDATE,
|
NEEDS_UPDATE,
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ namespace tp {
|
||||||
bool mDebug = false;
|
bool mDebug = false;
|
||||||
bool mDebugStopProcessing = false;
|
bool mDebugStopProcessing = false;
|
||||||
bool mDebugRedrawAlways = false;
|
bool mDebugRedrawAlways = false;
|
||||||
bool mDetailed = false;
|
bool mDetailed = true;
|
||||||
|
|
||||||
std::set<Widget*> mProcBreakpoints;
|
std::set<Widget*> mProcBreakpoints;
|
||||||
std::set<Widget*> mLayBreakpoints;
|
std::set<Widget*> mLayBreakpoints;
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,16 @@ namespace tp {
|
||||||
void clean();
|
void clean();
|
||||||
|
|
||||||
void updateTreeToProcess(Widget* root);
|
void updateTreeToProcess(Widget* root);
|
||||||
void handleFocusChanges(Widget* root, EventHandler& events);
|
void handleFocusChanges(Widget* active, Widget* prevActive);
|
||||||
|
Widget* findFocusWidget(Widget* root, EventHandler& events);
|
||||||
|
|
||||||
void findFocusWidget(Widget* iter, Widget** focus, const Vec2F& pointer);
|
void findMouseFocusWidget(Widget* iter, Widget** focus, const Vec2F& pointer);
|
||||||
static void getWidgetPath(Widget* widget, std::vector<Widget*>& out);
|
static void getWidgetPath(Widget* widget, std::vector<Widget*>& out);
|
||||||
void processActiveTree(Widget* iter, EventHandler& events, Vec2F pos);
|
void processActiveTree(Widget* iter, EventHandler& events, Vec2F pos);
|
||||||
void processFocusItems(EventHandler& events);
|
void processFocusItems(EventHandler& events);
|
||||||
|
|
||||||
|
Widget* getFocusWidget() { return mInFocusWidget; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void procWidget(Widget* widget, EventHandler& events, bool withEvents = false);
|
static void procWidget(Widget* widget, EventHandler& events, bool withEvents = false);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue