Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_focused_item() to request the current nav focus #2258

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dearpygui/dearpygui.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/dearpygui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ PyInit__dearpygui(void)
MV_ADD_COMMAND(get_windows);
MV_ADD_COMMAND(get_all_items);
MV_ADD_COMMAND(get_active_window);
MV_ADD_COMMAND(get_focused_item);
MV_ADD_COMMAND(set_primary_window);
MV_ADD_COMMAND(push_container_stack);
MV_ADD_COMMAND(pop_container_stack);
Expand Down
10 changes: 9 additions & 1 deletion src/dearpygui_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +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->focusedItem);
}

static PyObject*
Expand Down
12 changes: 12 additions & 0 deletions src/dearpygui_parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,18 @@ InsertParser_Block2(std::map<std::string, mvPythonParser>& parsers)
parsers.insert({ "get_active_window", parser });
}

{
std::vector<mvPythonDataElement> args;

mvPythonParserSetup setup;
setup.about = "Returns the item currently having focus.";
setup.category = { "Item Registry" };
setup.returnType = mvPyDataType::UUID;

mvPythonParser parser = FinalizeParser(setup, args);
parsers.insert({ "get_focused_item", parser });
}

{
std::vector<mvPythonDataElement> args;
args.push_back({ mvPyDataType::UUID, "window" });
Expand Down
4 changes: 4 additions & 0 deletions src/mvAppItemState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ UpdateAppItemState(mvAppItemState& state)
state.hovered = ImGui::IsItemHovered();
state.active = ImGui::IsItemActive();
state.focused = ImGui::IsItemFocused();
if (state.focused)
{
GContext->focusedItem = state.parent->uuid;
}
state.leftclicked = ImGui::IsItemClicked();
state.rightclicked = ImGui::IsItemClicked(1);
state.middleclicked = ImGui::IsItemClicked(2);
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
1 change: 0 additions & 1 deletion src/mvItemRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +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;
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 @@ -523,9 +523,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
Loading