Focus locking and popups
This commit is contained in:
parent
54dcbcb46b
commit
03b2b5d038
13 changed files with 296 additions and 145 deletions
|
|
@ -15,9 +15,9 @@ bool DebugManager::update(RootWidget* rootWidget, EventHandler& events) {
|
|||
mRootWidget = rootWidget;
|
||||
|
||||
if (mDebug) {
|
||||
auto area = rootWidget->mRoot->getAreaT();
|
||||
auto area = rootWidget->mRoot.getAreaT();
|
||||
area.size -= { 400, 0 };
|
||||
rootWidget->mRoot->setArea(area);
|
||||
rootWidget->mRoot.setArea(area);
|
||||
|
||||
events.setEnableKeyEvents(true);
|
||||
if (events.isPressed(InputID::K)) mDebugStopProcessing = !mDebugStopProcessing;
|
||||
|
|
@ -63,7 +63,7 @@ void DebugManager::drawDebug(RootWidget* rootWidget, Canvas& canvas) {
|
|||
|
||||
auto& upd = rootWidget->mUpdateManager;
|
||||
|
||||
recursiveDraw(canvas, rootWidget->mRoot, { 0, 0 }, 0);
|
||||
recursiveDraw(canvas, &rootWidget->mRoot, { 0, 0 }, 0);
|
||||
|
||||
ImGui::Text("Triggered: %i", (int) upd.mTriggeredWidgets.size());
|
||||
ImGui::SameLine(); ImGui::Text("Processing: %i", upd.mDebugWidgetsToProcess);
|
||||
|
|
@ -140,10 +140,9 @@ void DebugManager::widgetMenu(Widget* widget) {
|
|||
ImGui::InputFloat2("min size", &layout->mMinSize.x);
|
||||
ImGui::InputFloat2("max size", &layout->mMaxSize.x);
|
||||
|
||||
if (auto pBasicLayout = dynamic_cast<BasicLayout*>(widget->getLayout())) {
|
||||
int sizePolicyX = int(pBasicLayout->mSizePolicy.x);
|
||||
int sizePolicyY = int(pBasicLayout->mSizePolicy.y);
|
||||
int policy = int(pBasicLayout->mLayoutPolicy);
|
||||
{
|
||||
int sizePolicyX = int(widget->getLayout()->getSizePolicy().x);
|
||||
int sizePolicyY = int(widget->getLayout()->getSizePolicy().y);
|
||||
|
||||
if (ImGui::Combo("Size Policy X", &sizePolicyX, "Fixed\0Expanding\0Minimal\0")) {
|
||||
widget->setSizePolicy(SizePolicy(sizePolicyX), SizePolicy(sizePolicyY));
|
||||
|
|
@ -152,7 +151,10 @@ void DebugManager::widgetMenu(Widget* widget) {
|
|||
if (ImGui::Combo("Size Policy Y", &sizePolicyY, "Fixed\0Expanding\0Minimal\0")) {
|
||||
widget->setSizePolicy(SizePolicy(sizePolicyX), SizePolicy(sizePolicyY));
|
||||
}
|
||||
}
|
||||
|
||||
if (auto pBasicLayout = dynamic_cast<BasicLayout*>(widget->getLayout())) {
|
||||
int policy = int(pBasicLayout->mLayoutPolicy);
|
||||
if (ImGui::Combo("Layout", &policy, "Passive\0Vertical\0Horizontal\0")) {
|
||||
pBasicLayout->mLayoutPolicy = LayoutPolicy(policy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,11 +74,19 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
|||
|
||||
events.setCursorOrigin({ 0, 0 });
|
||||
|
||||
findFocusWidget(root, &mInFocusWidget, events.getPointer());
|
||||
mInFocusWidget = nullptr;
|
||||
|
||||
if (!mFocusLockWidget) {
|
||||
findFocusWidget(root, &mInFocusWidget, events.getPointer());
|
||||
} else {
|
||||
mInFocusWidget = mFocusLockWidget;
|
||||
}
|
||||
|
||||
// if (mInFocusWidget == prevFocus) return;
|
||||
if (mInFocusWidget) scheduleUpdate(mInFocusWidget, "focus entered");
|
||||
|
||||
if (!mInFocusWidget && !prevFocus) return;
|
||||
|
||||
std::vector<Widget*> path2;
|
||||
getWidgetPath(mInFocusWidget, path2);
|
||||
size_t propLen2 = path2.size();
|
||||
|
|
@ -99,7 +107,7 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
|||
}
|
||||
}
|
||||
|
||||
size_t mostCommonIdx = 0;
|
||||
int mostCommonIdx = 0;
|
||||
if (!(path1.empty() || path2.empty())) {
|
||||
while (path1[mostCommonIdx] == path2[mostCommonIdx] && mostCommonIdx < min(path1.size(), path2.size())) {
|
||||
mostCommonIdx++;
|
||||
|
|
@ -121,7 +129,9 @@ void UpdateManager::handleFocusChanges(Widget* root, EventHandler& events) {
|
|||
void UpdateManager::findFocusWidget(Widget* iter, Widget** focus, const Vec2F& pointer) {
|
||||
if (!iter->mArea.getTargetRect().isInside(pointer) || !iter->mFlags.get(Widget::ENABLED)) return;
|
||||
|
||||
*focus = iter;
|
||||
if (iter->processesEvents()) {
|
||||
*focus = iter;
|
||||
}
|
||||
|
||||
for (auto child = iter->mDepthOrder.lastNode(); child; child = child->prev) {
|
||||
findFocusWidget(child->data, focus, pointer - iter->mArea.getTargetRect().pos);
|
||||
|
|
@ -148,8 +158,6 @@ void UpdateManager::processActiveTree(Widget* iter, EventHandler& events, Vec2F
|
|||
void UpdateManager::processFocusItems(EventHandler& events) {
|
||||
if (!mInFocusWidget) return;
|
||||
|
||||
// FIXME : cringe
|
||||
|
||||
std::vector<Widget*> path;
|
||||
getWidgetPath(mInFocusWidget, path);
|
||||
|
||||
|
|
@ -191,4 +199,13 @@ void UpdateManager::procWidget(Widget* widget, EventHandler& events, bool withEv
|
|||
events.setEnableKeyEvents(withEvents);
|
||||
gDebugWidget.checkProcBreakPoints(widget);
|
||||
widget->process(events);
|
||||
}
|
||||
|
||||
void UpdateManager::lockFocus(tp::Widget* widget) {
|
||||
mFocusLockWidget = widget;
|
||||
}
|
||||
|
||||
void UpdateManager::freeFocus(tp::Widget* widget) {
|
||||
DEBUG_ASSERT(mFocusLockWidget == widget)
|
||||
mFocusLockWidget = nullptr;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue