Skip to content

Commit

Permalink
InputText: Moving some code in anticipation of supporting hint displa…
Browse files Browse the repository at this point in the history
…y with password. This commit is aimed at having no visible side effect. (#2400)
  • Loading branch information
ocornut committed Mar 6, 2019
1 parent 3441400 commit fe48368
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fe48368

Please sign in to comment.