mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
InputText: Simplify read-only code path.
This commit is contained in:
parent
d9f6ba3035
commit
abb7d7b18a
@ -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
|
if (g.ActiveId == id && io.MouseClicked[0] && !init_state && !init_make_active) //-V560
|
||||||
clear_active_id = true;
|
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
|
// 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 :(
|
// 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)
|
if (is_readonly && state != NULL && (render_cursor || render_selection))
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
const char* buf_end = NULL;
|
const char* buf_end = NULL;
|
||||||
state->TextW.resize(buf_size + 1);
|
state->TextW.resize(buf_size + 1);
|
||||||
state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, buf, NULL, &buf_end);
|
state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, buf, NULL, &buf_end);
|
||||||
state->CurLenA = (int)(buf_end - buf);
|
state->CurLenA = (int)(buf_end - buf);
|
||||||
state->CursorClamp();
|
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.
|
// Select the buffer to render.
|
||||||
const bool buf_display_from_state = (render_cursor || render_selection || g.ActiveId == id) && !is_readonly && state && state->TextAIsValid;
|
const bool buf_display_from_state = (render_cursor || render_selection || g.ActiveId == id) && !is_readonly && state && state->TextAIsValid;
|
||||||
|
Loading…
Reference in New Issue
Block a user