Lines Matching refs:state
441 // See the series of events below and the corresponding state reported by dear imgui:
3766 static void stb_textedit_replace(ImGuiInputTextState* str, STB_TexteditState* state, const STB_TEXTEDIT_CHARTYPE* text, int text_len)
3768 stb_text_makeundo_replace(str, state, 0, str->CurLenW, text_len);
3774 state->cursor = text_len;
3775 state->has_preferred_x = 0;
4024 // We are only allowed to access the state if we are already the active widget.
4025 ImGuiInputTextState* state = GetInputTextState(id);
4031 const bool user_scroll_finish = is_multiline && state != NULL && g.ActiveId == 0 && g.ActiveIdPreviousFrame == GetWindowScrollbarID(draw_window, ImGuiAxis_Y);
4032 const bool user_scroll_active = is_multiline && state != NULL && g.ActiveId == GetWindowScrollbarID(draw_window, ImGuiAxis_Y);
4038 const bool init_changed_specs = (state != NULL && state->Stb.single_line != !is_multiline);
4043 // Access state even if we don't own it yet.
4044 state = &g.InputTextState;
4045 state->CursorAnimReset();
4050 state->InitialTextA.resize(buf_len + 1); // UTF-8. we use +1 to make sure that .Data is always pointing to at least an empty string.
4051 memcpy(state->InitialTextA.Data, buf, buf_len + 1);
4055 state->TextW.resize(buf_size + 1); // wchar count <= UTF-8 count. we use +1 to make sure that .Data is always pointing to at least an empty string.
4056 state->TextA.resize(0);
4057 state->TextAIsValid = false; // TextA is not valid yet (we will display buf until then)
4058 state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, buf_size, buf, NULL, &buf_end);
4059 state->CurLenA = (int)(buf_end - buf); // We can't get the result from ImStrncpy() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8.
4063 const bool recycle_state = (state->ID == id && !init_changed_specs);
4068 state->CursorClamp();
4072 state->ID = id;
4073 state->ScrollX = 0.0f;
4074 stb_textedit_initialize_state(&state->Stb, !is_multiline);
4088 state->Stb.insert_mode = 1; // stb field name is indeed incorrect (see #2863)
4093 IM_ASSERT(state && state->ID == id);
4112 if (g.ActiveId == id && state == NULL)
4120 const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active);
4121 bool render_selection = state && (state->HasSelection() || select_all) && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor);
4127 if (is_readonly && state != NULL && (render_cursor || render_selection))
4130 state->TextW.resize(buf_size + 1);
4131 state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, buf, NULL, &buf_end);
4132 state->CurLenA = (int)(buf_end - buf);
4133 state->CursorClamp();
4134 render_selection &= state->HasSelection();
4138 const bool buf_display_from_state = (render_cursor || render_selection || g.ActiveId == id) && !is_readonly && state && state->TextAIsValid;
4139 const bool is_displaying_hint = (hint != NULL && (buf_display_from_state ? state->TextA.Data : buf)[0] == 0);
4161 IM_ASSERT(state != NULL);
4162 backup_current_text_length = state->CurLenA;
4163 state->Edited = false;
4164 state->BufCapacityA = buf_size;
4165 state->Flags = flags;
4166 state->UserCallback = callback;
4167 state->UserCallbackData = callback_user_data;
4175 const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + state->ScrollX;
4181 state->SelectAll();
4182 state->SelectedAllMouseLock = true;
4187 state->OnKeyPressed(STB_TEXTEDIT_K_WORDLEFT);
4188 state->OnKeyPressed(STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT);
4190 else if (io.MouseClicked[0] && !state->SelectedAllMouseLock)
4194 stb_textedit_click(state, &state->Stb, mouse_x, mouse_y);
4195 state->CursorAnimReset();
4198 else if (io.MouseDown[0] && !state->SelectedAllMouseLock && (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f))
4200 stb_textedit_drag(state, &state->Stb, mouse_x, mouse_y);
4201 state->CursorAnimReset();
4202 state->CursorFollow = true;
4204 if (state->SelectedAllMouseLock && !io.MouseDown[0])
4205 state->SelectedAllMouseLock = false;
4215 state->OnKeyPressed((int)c);
4230 state->OnKeyPressed((int)c);
4242 IM_ASSERT(state != NULL);
4246 state->Stb.row_count_per_page = row_count_per_page;
4257 const bool is_cut = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressedMap(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection());
4258 const bool is_copy = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_C)) || (is_ctrl_key_only && IsKeyPressedMap(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection());
4268 if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); }
4269 else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); }
4270 else if (IsKeyPressedMap(ImGuiKey_UpArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMax(draw_window->Scroll.y - g.FontSize, 0.0f)); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTSTART : STB_TEXTEDIT_K_UP) | k_mask); }
4271 else if (IsKeyPressedMap(ImGuiKey_DownArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMin(draw_window->Scroll.y + g.FontSize, GetScrollMaxY())); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTEND : STB_TEXTEDIT_K_DOWN) | k_mask); }
4272 else if (IsKeyPressedMap(ImGuiKey_PageUp) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGUP | k_mask); scroll_y -= row_count_per_page * g.FontSize; }
4273 else if (IsKeyPressedMap(ImGuiKey_PageDown) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGDOWN | k_mask); scroll_y += row_count_per_page * g.FontSize; }
4274 else if (IsKeyPressedMap(ImGuiKey_Home)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
4275 else if (IsKeyPressedMap(ImGuiKey_End)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
4276 else if (IsKeyPressedMap(ImGuiKey_Delete) && !is_readonly) { state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
4279 if (!state->HasSelection())
4282 state->OnKeyPressed(STB_TEXTEDIT_K_WORDLEFT | STB_TEXTEDIT_K_SHIFT);
4284 state->OnKeyPressed(STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_SHIFT);
4286 state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask);
4299 state->OnKeyPressed((int)c);
4313 state->OnKeyPressed(is_undo ? STB_TEXTEDIT_K_UNDO : STB_TEXTEDIT_K_REDO);
4314 state->ClearSelection();
4318 state->SelectAll();
4319 state->CursorFollow = true;
4326 const int ib = state->HasSelection() ? ImMin(state->Stb.select_start, state->Stb.select_end) : 0;
4327 const int ie = state->HasSelection() ? ImMax(state->Stb.select_start, state->Stb.select_end) : state->CurLenW;
4328 const int clipboard_data_len = ImTextCountUtf8BytesFromStr(state->TextW.Data + ib, state->TextW.Data + ie) + 1;
4330 ImTextStrToUtf8(clipboard_data, clipboard_data_len, state->TextW.Data + ib, state->TextW.Data + ie);
4336 if (!state->HasSelection())
4337 state->SelectAll();
4338 state->CursorFollow = true;
4339 stb_textedit_cut(state, &state->Stb);
4363 stb_textedit_paste(state, &state->Stb, clipboard_filtered, clipboard_filtered_len);
4364 state->CursorFollow = true;
4371 render_selection |= state->HasSelection() && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor);
4377 IM_ASSERT(state != NULL);
4383 if (!is_readonly && strcmp(buf, state->InitialTextA.Data) != 0)
4386 apply_new_text = state->InitialTextA.Data;
4387 apply_new_text_length = state->InitialTextA.Size - 1;
4394 stb_textedit_replace(state, &state->Stb, w_text.Data, (apply_new_text_length > 0) ? (w_text.Size - 1) : 0);
4407 // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks.
4410 state->TextAIsValid = true;
4411 state->TextA.resize(state->TextW.Size * 4 + 1);
4412 ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL);
4438 else if ((flags & ImGuiInputTextFlags_CallbackEdit) && state->Edited)
4456 callback_data.Buf = state->TextA.Data;
4457 callback_data.BufTextLen = state->CurLenA;
4458 callback_data.BufSize = state->BufCapacityA;
4462 ImWchar* text = state->TextW.Data;
4463 const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(text, text + state->Stb.cursor);
4464 const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(text, text + state->Stb.select_start);
4465 const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(text, text + state->Stb.select_end);
4471 IM_ASSERT(callback_data.Buf == state->TextA.Data); // Invalid to modify those fields
4472 IM_ASSERT(callback_data.BufSize == state->BufCapacityA);
4475 if (callback_data.CursorPos != utf8_cursor_pos || buf_dirty) { state->Stb.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos); state->CursorFollow = true; }
4476 if (callback_data.SelectionStart != utf8_selection_start || buf_dirty) { state->Stb.select_start = (callback_data.SelectionStart == callback_data.CursorPos) ? state->Stb.cursor : ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart); }
4477 if (callback_data.SelectionEnd != utf8_selection_end || buf_dirty) { state->Stb.select_end = (callback_data.SelectionEnd == callback_data.SelectionStart) ? state->Stb.select_start : ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd); }
4482 state->TextW.resize(state->TextW.Size + (callback_data.BufTextLen - backup_current_text_length));
4483 state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, callback_data.Buf, NULL);
4484 state->CurLenA = callback_data.BufTextLen; // Assume correct length and valid UTF-8 from user, saves us an extra strlen()
4485 state->CursorAnimReset();
4491 if (!is_readonly && strcmp(state->TextA.Data, buf) != 0)
4493 apply_new_text = state->TextA.Data;
4494 apply_new_text_length = state->CurLenA;
4528 state->Flags = ImGuiInputTextFlags_None;
4529 state->UserCallback = NULL;
4530 state->UserCallbackData = NULL;
4552 const char* buf_display = buf_display_from_state ? state->TextA.Data : buf; //-V595
4564 IM_ASSERT(state != NULL);
4566 buf_display_end = buf_display + state->CurLenA;
4575 const ImWchar* text_begin = state->TextW.Data;
4585 searches_input_ptr[0] = text_begin + state->Stb.cursor;
4591 searches_input_ptr[1] = text_begin + ImMin(state->Stb.select_start, state->Stb.select_end);
4629 if (render_cursor && state->CursorFollow)
4636 if (cursor_offset.x < state->ScrollX)
4637 state->ScrollX = IM_FLOOR(ImMax(0.0f, cursor_offset.x - scroll_increment_x));
4638 else if (cursor_offset.x - visible_width >= state->ScrollX)
4639 state->ScrollX = IM_FLOOR(cursor_offset.x - visible_width + scroll_increment_x);
4643 state->ScrollX = 0.0f;
4660 state->CursorFollow = false;
4664 const ImVec2 draw_scroll = ImVec2(state->ScrollX, 0.0f);
4667 const ImWchar* text_selected_begin = text_begin + ImMin(state->Stb.select_start, state->Stb.select_end);
4668 const ImWchar* text_selected_end = text_begin + ImMax(state->Stb.select_start, state->Stb.select_end);
4710 state->CursorAnim += io.DeltaTime;
4711 bool cursor_is_visible = (!g.IO.ConfigInputTextCursorBlink) || (state->CursorAnim <= 0.0f) || ImFmod(state->CursorAnim, 1.20f) <= 0.80f;
4728 buf_display_end = buf_display + state->CurLenA;
5790 // We treat ImGuiCond_Once and ImGuiCond_FirstUseEver the same because tree node state are not saved persistently.
6057 // Set next TreeNode/CollapsingHeader open state.
6082 // Do not mistake this with the Open state of the header itself, which you can adjust with SetNextItemOpen() or ImGuiTreeNodeFlags_DefaultOpen.
8142 // In Style V2 we'll have full override of all colors per state (e.g. focused, selected)
8154 // Return clipped state ignoring the close button