Skip to content

Commit

Permalink
refac: Moved focusedItem and activeWindow to mvContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
v-ein authored and hoffstadt committed Jan 31, 2024
1 parent e085503 commit 003efa9
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/dearpygui_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2988,15 +2988,15 @@ get_active_window(PyObject* self, PyObject* args, PyObject* kwargs)
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

return ToPyUUID(GContext->itemRegistry->activeWindow);
return ToPyUUID(GContext->activeWindow);
}

static PyObject*
get_focused_item(PyObject* self, PyObject* args, PyObject* kwargs)
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

return ToPyUUID(GContext->itemRegistry->focusedItem);
return ToPyUUID(GContext->focusedItem);
}

static PyObject*
Expand Down
3 changes: 1 addition & 2 deletions src/mvAppItemState.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "mvAppItemState.h"
#include <imgui.h>
#include "mvAppItem.h"
#include "mvItemRegistry.h"
#include "mvContext.h"
#include "mvPyUtils.h"

Expand Down Expand Up @@ -33,7 +32,7 @@ UpdateAppItemState(mvAppItemState& state)
state.focused = ImGui::IsItemFocused();
if (state.focused)
{
GContext->itemRegistry->focusedItem = state.parent->uuid;
GContext->focusedItem = state.parent->uuid;
}
state.leftclicked = ImGui::IsItemClicked();
state.rightclicked = ImGui::IsItemClicked(1);
Expand Down
9 changes: 3 additions & 6 deletions src/mvContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,7 @@ DearPyGui::draw_menu(ImDrawList* drawlist, mvAppItem& item, mvMenuConfig& config
GContext->input.mousePos.y = (int)y;


if (GContext->itemRegistry->activeWindow != item.uuid)
GContext->itemRegistry->activeWindow = item.uuid;
GContext->activeWindow = item.uuid;

}

Expand Down Expand Up @@ -977,8 +976,7 @@ DearPyGui::draw_child_window(ImDrawList* drawlist, mvAppItem& item, mvChildWindo
GContext->input.mousePos.x = (int)x;
GContext->input.mousePos.y = (int)y;

if (GContext->itemRegistry->activeWindow != item.uuid)
GContext->itemRegistry->activeWindow = item.uuid;
GContext->activeWindow = item.uuid;

}

Expand Down Expand Up @@ -1656,8 +1654,7 @@ DearPyGui::draw_window(ImDrawList* drawlist, mvAppItem& item, mvWindowAppItemCon
GContext->input.mousePos.x = (int)x;
GContext->input.mousePos.y = (int)y;

if (GContext->itemRegistry->activeWindow != item.uuid)
GContext->itemRegistry->activeWindow = item.uuid;
GContext->activeWindow = item.uuid;

}

Expand Down
2 changes: 2 additions & 0 deletions src/mvContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct mvContext
mvItemRegistry* itemRegistry = nullptr;
mvCallbackRegistry* callbackRegistry = nullptr;
mvInput input;
mvUUID activeWindow = 0;
mvUUID focusedItem = 0;

};

Expand Down
2 changes: 0 additions & 2 deletions src/mvItemRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ struct mvItemRegistry
// misc
std::stack<mvAppItem*> containers; // parent stack, top of stack becomes widget's parent
std::unordered_map<std::string, mvUUID> aliases;
mvUUID activeWindow = 0;
mvUUID focusedItem = 0;
std::vector<mvAppItem*> delayedSearch;
b8 showImGuiDebug = false;
b8 showImPlotDebug = false;
Expand Down
4 changes: 1 addition & 3 deletions src/mvPlotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,7 @@ DearPyGui::draw_plot(ImDrawList* drawlist, mvAppItem& item, mvPlotConfig& config
GContext->input.mousePos.x = (int)x;
GContext->input.mousePos.y = (int)y;


if (GContext->itemRegistry->activeWindow != item.uuid)
GContext->itemRegistry->activeWindow = item.uuid;
GContext->activeWindow = item.uuid;

}

Expand Down
3 changes: 1 addition & 2 deletions src/mvToolWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ void mvToolWindow::draw()

std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

if (GContext->itemRegistry->activeWindow != getUUID())
GContext->itemRegistry->activeWindow = getUUID();
GContext->activeWindow = getUUID();

}

Expand Down

0 comments on commit 003efa9

Please sign in to comment.