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

The way to prevent scalar input chars filtering #6810

Closed
Grantim opened this issue Sep 12, 2023 · 13 comments
Closed

The way to prevent scalar input chars filtering #6810

Grantim opened this issue Sep 12, 2023 · 13 comments

Comments

@Grantim
Copy link

Grantim commented Sep 12, 2023

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

I find out that there is

imgui/imgui_widgets.cpp

Lines 3390 to 3396 in 6eb2681

static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(ImGuiDataType data_type, const char* format)
{
if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double)
return ImGuiInputTextFlags_CharsScientific;
const char format_last_char = format[0] ? format[strlen(format) - 1] : 0;
return (format_last_char == 'x' || format_last_char == 'X') ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal;
}

function, that is forced here:
flags |= InputScalar_DefaultCharsFilter(data_type, format);

and here:

imgui/imgui_widgets.cpp

Lines 3460 to 3461 in 6eb2681

if (g.ActiveId == 0 && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0)
flags |= InputScalar_DefaultCharsFilter(data_type, format);

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?

@ocornut
Copy link
Owner

ocornut commented Sep 12, 2023

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

Could you explain why would you want to do that ?

@Grantim
Copy link
Author

Grantim commented Sep 12, 2023

We think of it like a possible option for better UX

@ocornut
Copy link
Owner

ocornut commented Sep 12, 2023

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
Copy link
Author

Grantim commented Sep 12, 2023

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
Copy link
Owner

ocornut commented Sep 12, 2023

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
Copy link
Author

Grantim commented Sep 12, 2023

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
Copy link
Owner

ocornut commented Sep 12, 2023

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

@Grantim
Copy link
Author

Grantim commented Sep 12, 2023

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
Copy link
Owner

ocornut commented Sep 12, 2023

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.

ocornut added a commit that referenced this issue Dec 22, 2023
@ocornut
Copy link
Owner

ocornut commented Dec 22, 2023

Did some soul searching and applied this change now :)
(This will also allow #7096)

@ocornut ocornut closed this as completed Dec 22, 2023
busti pushed a commit to ev1313/imgui that referenced this issue Dec 22, 2023
@Grantim
Copy link
Author

Grantim commented Dec 23, 2023

Thanks!

@Guillaume227
Copy link

I have also been coincidentally looking for a similar feature, so that change is very timely, thanks!

My motivation is that I want users to be able to enter NAN or INF which filtering on chars prevents.

I happen to be on the docking branch where those changes are not present yet.
So I have two questions @ocornut :

  1. what is the sync schedule between master and docking?
  2. docking has been around for a long time - is it still a feature branch that is meant to be merged to master at some point or is it going to live a separate life indefinitely (I did search but haven't been able to find that information in readme material)?

@ocornut
Copy link
Owner

ocornut commented Jan 3, 2024

what is the sync schedule between master and docking?

Roughly every week or two weeks, depending on commits contents.

s it still a feature branch that is meant to be merged to master at some point or is it going to live a separate life indefinitely (I did search but haven't been able to find that information in readme material)?

I am not happy with the code quality so I aim to rewrite it a third time first, see https://github.com/ocornut/imgui/wiki/Docking#why-is-not-merged-to-master

One of the reason for building the imgui test suite (https://github.com/ocornut/imgui_test_engine) was to get more coverage of docking features to facilitate the rewrite. Code is imho too brittle currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants