Skip to content

Instantly share code, notes, and snippets.

@amuTBKT
amuTBKT / imgui_customnav_test.cpp
Last active January 2, 2026 04:08
Tying out shortcuts + auto focus items for a ImGui widget.
// code for: https://x.com/amu_mhr/status/2006940064711053355?s=20
extern int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
// dubious function to focus `InputText` widgets with nav cursor, this avoid having to press enter to edit them
// NOTE: `ImGui::Shortcut` handles focusing but not sure how to replicate that when using arrow keys (i.e no shortcut just navigation)
// This has a downside that items to the left/right of the input box cannot be reached using arrow keys (only up/down nav will work!)
auto AutoFocusNextItem = [](const char* item_label)
{
const ImGuiID item_id = ImGui::GetCurrentWindow()->GetID(item_label);