The way to prevent scalar input chars filtering #6810

Closed
opened 2023-09-12 09:01:13 +00:00 by Grantim · 9 comments
Grantim commented 2023-09-12 09:01:13 +00:00 (Migrated from github.com)

Is there a way to prevent alphabet characters filtering in input/drag scalar?

I find out that there is
ocornut/imgui@6eb2681c09/imgui_widgets.cpp (L3390-L3396)
function, that is forced here:
ocornut/imgui@6eb2681c09/imgui_widgets.cpp (L3415)
and here:
ocornut/imgui@6eb2681c09/imgui_widgets.cpp (L3460-L3461)

one way to hack this behaviour is to define custom function in IMGUI_USER_CONFIG like this:

typedef int ImGuiInputTextFlags;
typedef int ImGuiDataType;
namespace ImGui
{
static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter( ImGuiDataType, const char* )
{
    return 0;
}
}

so it is used before original one is found.

Is there a native way to it?

Is there a way to prevent alphabet characters filtering in input/drag scalar? I find out that there is https://github.com/ocornut/imgui/blob/6eb2681c0988d8ccd82be5f0a6581a0e577bea86/imgui_widgets.cpp#L3390-L3396 function, that is forced here: https://github.com/ocornut/imgui/blob/6eb2681c0988d8ccd82be5f0a6581a0e577bea86/imgui_widgets.cpp#L3415 and here: https://github.com/ocornut/imgui/blob/6eb2681c0988d8ccd82be5f0a6581a0e577bea86/imgui_widgets.cpp#L3460-L3461 one way to hack this behaviour is to define custom function in `IMGUI_USER_CONFIG` like this: ```c++ typedef int ImGuiInputTextFlags; typedef int ImGuiDataType; namespace ImGui { static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter( ImGuiDataType, const char* ) { return 0; } } ``` so it is used before original one is found. Is there a native way to it?
ocornut commented 2023-09-12 09:08:23 +00:00 (Migrated from github.com)

Is there a way to prevent alphabet characters filtering in input/drag scalar?

Could you explain why would you want to do that ?

> Is there a way to prevent alphabet characters filtering in input/drag scalar? Could you explain why would you want to do that ?
Grantim commented 2023-09-12 09:10:00 +00:00 (Migrated from github.com)

We think of it like a possible option for better UX

We think of it like a possible option for better UX
ocornut commented 2023-09-12 09:14:18 +00:00 (Migrated from github.com)

You are not answering the question.
Why do you want to input eg arbitrary alphabetical letter in a scalar input field? Why not using InputText() ?

We can’t provide you with a right answer if you don’t explain your use case.

You are not answering the question. Why do you want to input eg arbitrary alphabetical letter in a scalar input field? Why not using InputText() ? We can’t provide you with a right answer if you don’t explain your use case.
Grantim commented 2023-09-12 09:33:15 +00:00 (Migrated from github.com)

I want it to have drag behaviour and to have numerical argiments, but also I want it not to "ignore" user writing alphabet symbols (accidentaly or specialy)

I want it to have drag behaviour and to have numerical argiments, but also I want it not to "ignore" user writing alphabet symbols (accidentaly or specialy)
ocornut commented 2023-09-12 09:39:46 +00:00 (Migrated from github.com)

You are not answering the question which is WHY do you want that?

What do you expect to happen with the DragFloat() when text character are entered, value set to 0.0f ?
Pressing Enter would entirely lose the textual content.

You are not answering the question which is WHY do you want that? What do you expect to happen with the DragFloat() when text character are entered, value set to 0.0f ? Pressing Enter would entirely lose the textual content.
Grantim commented 2023-09-12 09:44:46 +00:00 (Migrated from github.com)

I think it should hold last valid value, at least with the hack I use it works this way, it would be nice to have ability to check explicitly if input is valid or not

I think it should hold last valid value, at least with the hack I use it works this way, it would be nice to have ability to check explicitly if input is valid or not
ocornut commented 2023-09-12 09:57:45 +00:00 (Migrated from github.com)

You have not answered the question yet. I would appreciate if you did, at least if you expect an answer.

You have not answered the question yet. I would appreciate if you did, at least if you expect an answer.
Grantim commented 2023-09-12 10:09:51 +00:00 (Migrated from github.com)

Our users complain that our Dear ImGui based application behaves not like other applications in numeric edit boxes. When they by mistake enter not digits (e.g. due to special language settings on their keybords), nothing appears on the screen, and it looks to them that the appliation does not respond at all. That is why we want to show all entered text in numeric edit fields even if it is invalid

Our users complain that our Dear ImGui based application behaves not like other applications in numeric edit boxes. When they by mistake enter not digits (e.g. due to special language settings on their keybords), nothing appears on the screen, and it looks to them that the appliation does not respond at all. That is why we want to show all entered text in numeric edit fields even if it is invalid
ocornut commented 2023-09-12 10:28:56 +00:00 (Migrated from github.com)

Thank you. I understand better.
Will need to think about this and ask some users. It should be doable to provide a global setting for that but it also seems interesting to reconsider the current behavior completely.

Thank you. I understand better. Will need to think about this and ask some users. It should be doable to provide a global setting for that but it also seems interesting to reconsider the current behavior completely.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6810
No description provided.