fix focus locking
This commit is contained in:
parent
fcd5eb2d2a
commit
f68f91f7d5
2 changed files with 26 additions and 8 deletions
|
|
@ -13,7 +13,7 @@ using namespace tp;
|
||||||
class Example : public WidgetApplication {
|
class Example : public WidgetApplication {
|
||||||
public:
|
public:
|
||||||
Example() {
|
Example() {
|
||||||
exampleScrolling();
|
examplePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exampleAll() {
|
void exampleAll() {
|
||||||
|
|
@ -71,19 +71,28 @@ public:
|
||||||
|
|
||||||
void examplePopup() {
|
void examplePopup() {
|
||||||
static Widget root;
|
static Widget root;
|
||||||
|
static Widget popup;
|
||||||
|
|
||||||
static ButtonWidget closeButton;
|
static ButtonWidget closeButton;
|
||||||
static ButtonWidget openButton;
|
static ButtonWidget openButton;
|
||||||
|
static ButtonWidget buttons[3];
|
||||||
|
|
||||||
|
for (auto& button : buttons) {
|
||||||
|
popup.addChild(&button);
|
||||||
|
}
|
||||||
|
|
||||||
|
popup.addChild(&closeButton);
|
||||||
|
|
||||||
root.addChild(&openButton);
|
root.addChild(&openButton);
|
||||||
((BasicLayout*)root.getLayout())->setLayoutPolicy(LayoutPolicy::Passive);
|
((BasicLayout*)root.getLayout())->setLayoutPolicy(LayoutPolicy::Passive);
|
||||||
|
|
||||||
openButton.setAction([&](){
|
openButton.setAction([&](){
|
||||||
closeButton.setArea({ 50, 50, 100, 100 });
|
popup.setArea({ 50, 50, 300, 300 });
|
||||||
openButton.openPopup(&closeButton);
|
openButton.openPopup(&popup);
|
||||||
});
|
});
|
||||||
|
|
||||||
closeButton.setAction([&](){
|
closeButton.setAction([&](){
|
||||||
closeButton.closePopup(&closeButton);
|
closeButton.closePopup(&popup);
|
||||||
});
|
});
|
||||||
|
|
||||||
openButton.setText("open");
|
openButton.setText("open");
|
||||||
|
|
|
||||||
|
|
@ -76,10 +76,19 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
||||||
|
|
||||||
mInFocusWidget = nullptr;
|
mInFocusWidget = nullptr;
|
||||||
|
|
||||||
if (!mFocusLockWidget) {
|
findFocusWidget(root, &mInFocusWidget, events.getPointer());
|
||||||
findFocusWidget(root, &mInFocusWidget, events.getPointer());
|
|
||||||
} else {
|
if (mFocusLockWidget) {
|
||||||
mInFocusWidget = mFocusLockWidget;
|
bool hasLockedWidget = false;
|
||||||
|
for (auto iter = mInFocusWidget; iter; iter = iter->mParent) {
|
||||||
|
if (iter == mFocusLockWidget) {
|
||||||
|
hasLockedWidget = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasLockedWidget) {
|
||||||
|
mInFocusWidget = mFocusLockWidget;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (mInFocusWidget == prevFocus) return;
|
// if (mInFocusWidget == prevFocus) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue