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

Feature/keyboard navigation #2144

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 6 additions & 4 deletions dearpygui/dearpygui.py

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

3 changes: 3 additions & 0 deletions src/dearpygui_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,8 @@ configure_app(PyObject* self, PyObject* args, PyObject* kwargs)
if (PyObject* item = PyDict_GetItemString(kwargs, "device_name")) GContext->IO.info_device_name = ToString(item);
if (PyObject* item = PyDict_GetItemString(kwargs, "device")) GContext->IO.info_device = ToInt(item);

if (PyObject* item = PyDict_GetItemString(kwargs, "keyboard_navigation")) GContext->IO.kbdNavigation = ToBool(item);

return GetPyNone();
}

Expand Down Expand Up @@ -2656,6 +2658,7 @@ get_app_configuration(PyObject* self, PyObject* args, PyObject* kwargs)
PyDict_SetItemString(pdict, "auto_save_init_file", mvPyObject(ToPyBool(GContext->IO.autoSaveIniFile)));
PyDict_SetItemString(pdict, "wait_for_input", mvPyObject(ToPyBool(GContext->IO.waitForInput)));
PyDict_SetItemString(pdict, "manual_callback_management", mvPyObject(ToPyBool(GContext->IO.manualCallbacks)));
PyDict_SetItemString(pdict, "keyboard_navigation", mvPyObject(ToPyBool(GContext->IO.kbdNavigation)));
return pdict;
}

Expand Down
1 change: 1 addition & 0 deletions src/dearpygui_parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ InsertParser_Block1(std::map<std::string, mvPythonParser>& parsers)
args.push_back({ mvPyDataType::Bool, "skip_keyword_args", mvArgType::KEYWORD_ARG, "False" });
args.push_back({ mvPyDataType::Bool, "wait_for_input", mvArgType::KEYWORD_ARG, "False", "New in 1.1. Only update when user input occurs" });
args.push_back({ mvPyDataType::Bool, "manual_callback_management", mvArgType::KEYWORD_ARG, "False", "New in 1.2"});
args.push_back({ mvPyDataType::Bool, "keyboard_navigation", mvArgType::KEYWORD_ARG, "False", "Keyboard navigation using arrow keys" });

mvPythonParserSetup setup;
setup.about = "Configures app.";
Expand Down
1 change: 1 addition & 0 deletions src/mvAppItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,7 @@ DearPyGui::GetEntityParser(mvAppItemType type)
args.push_back({ mvPyDataType::Bool, "horizontal_scrollbar", mvArgType::KEYWORD_ARG, "False", "Allow horizontal scrollbar to appear (off by default)." });
args.push_back({ mvPyDataType::Bool, "menubar", mvArgType::KEYWORD_ARG, "False", "Shows/Hides the menubar at the top." });
args.push_back({ mvPyDataType::Bool, "no_scroll_with_mouse", mvArgType::KEYWORD_ARG, "False", "Disable user vertically scrolling with mouse wheel." });
args.push_back({ mvPyDataType::Bool, "flattened_navigation", mvArgType::KEYWORD_ARG, "True", "Allow gamepad/keyboard navigation to cross over parent border to this child (only use on child that have no scrolling!)" });

setup.about = "Adds an embedded child window. Will show scrollbars when items do not fit.";
setup.category = { "Containers", "Widgets" };
Expand Down
2 changes: 2 additions & 0 deletions src/mvContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ DearPyGui::fill_configuration_dict(const mvChildWindowConfig& inConfig, PyObject
checkbitset("horizontal_scrollbar", ImGuiWindowFlags_HorizontalScrollbar, inConfig.windowflags);
checkbitset("menubar", ImGuiWindowFlags_MenuBar, inConfig.windowflags);
checkbitset("no_scroll_with_mouse", ImGuiWindowFlags_NoScrollWithMouse, inConfig.windowflags);
checkbitset("flattened_navigation", ImGuiWindowFlags_NavFlattened, inConfig.windowflags);
}

void
Expand Down Expand Up @@ -274,6 +275,7 @@ DearPyGui::set_configuration(PyObject* inDict, mvChildWindowConfig& outConfig)
flagop("horizontal_scrollbar", ImGuiWindowFlags_HorizontalScrollbar, outConfig.windowflags);
flagop("menubar", ImGuiWindowFlags_MenuBar, outConfig.windowflags);
flagop("no_scroll_with_mouse", ImGuiWindowFlags_NoScrollWithMouse, outConfig.windowflags);
flagop("flattened_navigation", ImGuiWindowFlags_NavFlattened, outConfig.windowflags);

}

Expand Down
2 changes: 1 addition & 1 deletion src/mvContainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct mvChildWindowConfig
bool border = true;
bool autosize_x = false;
bool autosize_y = false;
ImGuiWindowFlags windowflags = ImGuiWindowFlags_NoSavedSettings;
ImGuiWindowFlags windowflags = ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_NavFlattened;
float scrollX = 0.0f;
float scrollY = 0.0f;
float scrollMaxX = 0.0f;
Expand Down
2 changes: 2 additions & 0 deletions src/mvContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct mvIO
bool docking = false;
bool dockingViewport = false;

bool kbdNavigation = false;

std::string iniFile;
bool loadIniFile = false;
bool autoSaveIniFile = false;
Expand Down
5 changes: 4 additions & 1 deletion src/mvViewport_apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@
}

(void) io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls

if(GContext->IO.kbdNavigation)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls

//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls

if(GContext->IO.docking)
Expand Down
3 changes: 3 additions & 0 deletions src/mvViewport_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ mvShowViewport(mvViewport& viewport, bool minimized, bool maximized)
io.IniFilename = GContext->IO.iniFile.c_str();
}

if(GContext->IO.kbdNavigation)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls

if (GContext->IO.docking)
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

Expand Down
3 changes: 3 additions & 0 deletions src/mvViewport_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ mvShowViewport(mvViewport& viewport, bool minimized, bool maximized)
io.IniFilename = GContext->IO.iniFile.c_str();
}

if(GContext->IO.kbdNavigation)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls

if (GContext->IO.docking)
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

Expand Down