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

Is there a way for block navigation for custom widgets ? #3712

Closed
aiekick opened this issue Jan 12, 2021 · 4 comments
Closed

Is there a way for block navigation for custom widgets ? #3712

aiekick opened this issue Jan 12, 2021 · 4 comments
Labels
nav keyboard/gamepad navigation

Comments

@aiekick
Copy link
Contributor

aiekick commented Jan 12, 2021

its not an issue.

in ImGuiFileDialog, i have implemented up/down return/backspace navigation for explore file/directory list

you navigation system work like a charm for select widgets.

but when the file list is focused i would like to have a way for block your navigation.
for have mine only working. like i can explore the list with my navigation system only when the file lsit is focused.

here you see my navigation work in parrallel of your and its annoying.
d6RQXsQ2aQ

by ex i would like to press ctrl key when the file list is focused. and with ctrl key pressed navigate with my system

if i implement the imgui nav system in my filelist, it can be annoying when we have big file list

i not found a way in the src files for doing that. but maybe i miss something.

@ocornut ocornut added the nav keyboard/gamepad navigation label Jan 12, 2021
@ocornut ocornut changed the title Is there a way for block KbdNavigation for custom widgets ? Is there a way for block navigation for custom widgets ? Jan 12, 2021
@ocornut
Copy link
Owner

ocornut commented Jan 12, 2021

For a specific window you can use the ImGuiWindowFlags_NoNav or ImGuiWindowFlags_NoNavInputs flag.

For specific widget there are internals facilities such as ActiveIdUsingNavDirMask, ActiveIdUsingNavInputMask but they are only partially supported and need to be improved on a per-need basis.

@aiekick
Copy link
Contributor Author

aiekick commented Jan 12, 2021

thanks, will try that btw i not want to disable this feature for the whole window, just when my widget is focused for let him explore it

@aiekick
Copy link
Contributor Author

aiekick commented Feb 20, 2021

hello,

Finally i got a solution to my problem,
but its like a hack (no imgui modification, but playing with some vars who are maybe not made for that :) )

when the NavId is the listview id, if i hit the enter key i active my list view nav system
if i hit the escape key i go back to the imgui navigation

oIg7An1Fcb

but not sure if its robust enough
because i read and write directly g.LastActiveId

is there a better (more robust in time) way ?

i activate the item with both ImGui::ActivateItem and ImGui::SetActiveID.
at first i was using only ImGui::SetActiveID, but the nav highlight was disapearing, and i would like to keep it

here my code :

bool canWeExplore = false;
bool hasNav = (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard);
			
ImGuiContext& g = *GImGui;
if (!hasNav && !g.ActiveId) // no nav and no activated inputs
    canWeExplore = true;

if (g.NavId && g.NavId == vListViewID)
{
    if (ImGui::IsKeyPressedMap(ImGuiKey_Enter) ||
        ImGui::IsKeyPressedMap(ImGuiKey_KeyPadEnter))
    {
        ImGui::ActivateItem(vListViewID);
        ImGui::SetActiveID(vListViewID, g.CurrentWindow);
    }
}
			
if (vListViewID == g.LastActiveId-1) // if listview id is the last acticated nav id (ImGui::ActivateItem(vListViewID);)
    canWeExplore = true;

if (canWeExplore)
{
    if (ImGui::IsKeyPressedMap(ImGuiKey_Escape))
    {
        ImGui::ClearActiveID();
        g.LastActiveId = 0;
    }

    // actions
}

what do you think about it ?

@ocornut
Copy link
Owner

ocornut commented Mar 10, 2023

See general answer in #3560 (comment)
And examples in the demo of that temporary branch (will be merged in public demo when the API becomes public)
https://github.com/ocornut/imgui/compare/features/demo_input_owner_and_routing

You can claim ownership of a key ahead of time and Nav system won't use that key.

@ocornut ocornut closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

2 participants