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

InputText() returns true every frame if internal buffer is different from buf passed to the function #4420

Open
squadack opened this issue Aug 11, 2021 · 0 comments

Comments

@squadack
Copy link

Version/Branch of Dear ImGui:

Version: 1.83
Branch: docking

My Issue/Question:

Sometimes I need to input some value that requires additional verification before storing it in the target variable (best example would be path to file - not every string is a path to an existing file - but example below checks if the string is lowercase as it is more portable than filepath) and I would prefer to do this verification only when user actually performs some change. However, contrary to my expectations(*), InputText() returns true when its internal buffer is different from buf argument which leads to checks being perfomed every frame instead of only when user actually changes the value.

I'm not sure if this behaviour is a bug or is it intended.

(*) Expectations based on:

  • Most widgets return true when the value has been changed or when pressed/selected (imgui.h:489)
  • InputTextEx() comment When active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while the InputText is active has no effect. (imgui_widgets.cpp:3865)

Standalone, minimal, complete and verifiable example:

    static char persistent_buf[100] = "someval";
    ImGui::Begin( "Some window" );
    char temporary_buf[100];
    memcpy( temporary_buf, persistent_buf, sizeof( temporary_buf ) );
    if( ImGui::InputText( "lowercase only", temporary_buf, sizeof( temporary_buf ) ) ) {

        LOGGING_FUNCTION( "this logs every frame if temporary_buf != internal buffer" );

        //// check if temporary_buf contains only lowercase letters
        bool is_lower = true;
        for( char* s = temporary_buf; *s != 0; s++ ) {
            if (!islower( *s )) {
                is_lower = false;
                break;
            }
        }
        ////
        if( is_lower )
            memcpy( persistent_buf, temporary_buf, sizeof( temporary_buf ) );
    }
    ImGui::End();
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

2 participants