mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 15:11:05 +01:00 
			
		
		
		
	InputText: Simplify read-only code path.
This commit is contained in:
		@@ -3343,27 +3343,23 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
 | 
			
		||||
    if (g.ActiveId == id && io.MouseClicked[0] && !init_state && !init_make_active) //-V560
 | 
			
		||||
        clear_active_id = true;
 | 
			
		||||
 | 
			
		||||
    // Lock the decision of whether we are going to take the path displaying the cursor or selection
 | 
			
		||||
    const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active);
 | 
			
		||||
    bool render_selection = state && state->HasSelection() && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor);
 | 
			
		||||
    bool value_changed = false;
 | 
			
		||||
    bool enter_pressed = false;
 | 
			
		||||
 | 
			
		||||
    // When read-only we always use the live data passed to the function
 | 
			
		||||
    // FIXME-OPT: Because our selection/cursor code currently needs the wide text we need to convert it when active, which is not ideal :(
 | 
			
		||||
    if (is_readonly && state != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        const bool will_render_cursor = (g.ActiveId == id) || (user_scroll_active);
 | 
			
		||||
        const bool will_render_selection = state->HasSelection() && (RENDER_SELECTION_WHEN_INACTIVE || will_render_cursor);
 | 
			
		||||
        if (will_render_cursor || will_render_selection)
 | 
			
		||||
    if (is_readonly && state != NULL && (render_cursor || render_selection))
 | 
			
		||||
    {
 | 
			
		||||
        const char* buf_end = NULL;
 | 
			
		||||
        state->TextW.resize(buf_size + 1);
 | 
			
		||||
        state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, buf, NULL, &buf_end);
 | 
			
		||||
        state->CurLenA = (int)(buf_end - buf);
 | 
			
		||||
        state->CursorClamp();
 | 
			
		||||
        render_selection &= state->HasSelection();
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Lock the decision of whether we are going to take the path displaying the cursor or selection
 | 
			
		||||
    const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active);
 | 
			
		||||
    const bool render_selection = state && state->HasSelection() && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor);
 | 
			
		||||
    bool value_changed = false;
 | 
			
		||||
    bool enter_pressed = false;
 | 
			
		||||
 | 
			
		||||
    // Select the buffer to render.
 | 
			
		||||
    const bool buf_display_from_state = (render_cursor || render_selection || g.ActiveId == id) && !is_readonly && state && state->TextAIsValid;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user