mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-03 22:51:06 +01:00 
			
		
		
		
	InputText: Moving some code in anticipation of supporting hint display with password. This commit is aimed at having no visible side effect. (#2400)
This commit is contained in:
		@@ -3252,23 +3252,6 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
 | 
			
		||||
    if (hovered)
 | 
			
		||||
        g.MouseCursor = ImGuiMouseCursor_TextInput;
 | 
			
		||||
 | 
			
		||||
    // Password pushes a temporary font with only a fallback glyph
 | 
			
		||||
    if (is_password)
 | 
			
		||||
    {
 | 
			
		||||
        const ImFontGlyph* glyph = g.Font->FindGlyph('*');
 | 
			
		||||
        ImFont* password_font = &g.InputTextPasswordFont;
 | 
			
		||||
        password_font->FontSize = g.Font->FontSize;
 | 
			
		||||
        password_font->Scale = g.Font->Scale;
 | 
			
		||||
        password_font->DisplayOffset = g.Font->DisplayOffset;
 | 
			
		||||
        password_font->Ascent = g.Font->Ascent;
 | 
			
		||||
        password_font->Descent = g.Font->Descent;
 | 
			
		||||
        password_font->ContainerAtlas = g.Font->ContainerAtlas;
 | 
			
		||||
        password_font->FallbackGlyph = glyph;
 | 
			
		||||
        password_font->FallbackAdvanceX = glyph->AdvanceX;
 | 
			
		||||
        IM_ASSERT(password_font->Glyphs.empty() && password_font->IndexAdvanceX.empty() && password_font->IndexLookup.empty());
 | 
			
		||||
        PushFont(password_font);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // NB: we are only allowed to access 'edit_state' if we are the active widget.
 | 
			
		||||
    ImGuiInputTextState* state = NULL;
 | 
			
		||||
    if (g.InputTextState.ID == id)
 | 
			
		||||
@@ -3353,10 +3336,6 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
 | 
			
		||||
    if (g.ActiveId == id && io.MouseClicked[0] && !init_state && !init_make_active) //-V560
 | 
			
		||||
        clear_active_id = true;
 | 
			
		||||
 | 
			
		||||
    bool value_changed = false;
 | 
			
		||||
    bool enter_pressed = false;
 | 
			
		||||
    int backup_current_text_length = 0;
 | 
			
		||||
 | 
			
		||||
    // 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)
 | 
			
		||||
@@ -3373,7 +3352,31 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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;
 | 
			
		||||
 | 
			
		||||
    // Password pushes a temporary font with only a fallback glyph
 | 
			
		||||
    if (is_password)
 | 
			
		||||
    {
 | 
			
		||||
        const ImFontGlyph* glyph = g.Font->FindGlyph('*');
 | 
			
		||||
        ImFont* password_font = &g.InputTextPasswordFont;
 | 
			
		||||
        password_font->FontSize = g.Font->FontSize;
 | 
			
		||||
        password_font->Scale = g.Font->Scale;
 | 
			
		||||
        password_font->DisplayOffset = g.Font->DisplayOffset;
 | 
			
		||||
        password_font->Ascent = g.Font->Ascent;
 | 
			
		||||
        password_font->Descent = g.Font->Descent;
 | 
			
		||||
        password_font->ContainerAtlas = g.Font->ContainerAtlas;
 | 
			
		||||
        password_font->FallbackGlyph = glyph;
 | 
			
		||||
        password_font->FallbackAdvanceX = glyph->AdvanceX;
 | 
			
		||||
        IM_ASSERT(password_font->Glyphs.empty() && password_font->IndexAdvanceX.empty() && password_font->IndexLookup.empty());
 | 
			
		||||
        PushFont(password_font);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Process mouse inputs and character inputs
 | 
			
		||||
    int backup_current_text_length = 0;
 | 
			
		||||
    if (g.ActiveId == id)
 | 
			
		||||
    {
 | 
			
		||||
        IM_ASSERT(state != NULL);
 | 
			
		||||
@@ -3725,8 +3728,6 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
 | 
			
		||||
 | 
			
		||||
    // Render text. We currently only render selection when the widget is active or while scrolling.
 | 
			
		||||
    // FIXME: We could remove the '&& render_cursor' to keep rendering selection when inactive.
 | 
			
		||||
    const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active);
 | 
			
		||||
    const bool render_selection = state && state->HasSelection() && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor);
 | 
			
		||||
    if (render_cursor || render_selection)
 | 
			
		||||
    {
 | 
			
		||||
        // Render text (with cursor and selection)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user