mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-27 16:29:02 +08:00
InputText: Internals: store Scroll.y as it seems sane to (internally) expose it in a way that's agnostic of our use of a child window (#7913, #383)
This commit is contained in:
parent
d15da2c47d
commit
d474ed7f78
2
imgui.h
2
imgui.h
@ -29,7 +29,7 @@
|
||||
// Library Version
|
||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
|
||||
#define IMGUI_VERSION "1.91.1 WIP"
|
||||
#define IMGUI_VERSION_NUM 19103
|
||||
#define IMGUI_VERSION_NUM 19104
|
||||
#define IMGUI_HAS_TABLE
|
||||
|
||||
/*
|
||||
|
@ -1121,7 +1121,7 @@ struct IMGUI_API ImGuiInputTextState
|
||||
ImVector<char> InitialTextA; // value to revert to when pressing Escape = backup of end-user buffer at the time of focus (in UTF-8, unaltered)
|
||||
bool TextAIsValid; // temporary UTF8 buffer is not initially valid before we make the widget active (until then we pull the data from user argument)
|
||||
int BufCapacityA; // end-user buffer capacity
|
||||
float ScrollX; // horizontal scrolling/offset
|
||||
ImVec2 Scroll; // horizontal offset (managed manually) + vertical scrolling (pulled from child window's own Scroll.y)
|
||||
ImStb::STB_TexteditState Stb; // state for stb_textedit.h
|
||||
float CursorAnim; // timer for cursor blink, reset on every user action so the cursor reappears immediately
|
||||
bool CursorFollow; // set when we want scrolling to follow the current cursor position (not always!)
|
||||
|
@ -4407,7 +4407,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
}
|
||||
else
|
||||
{
|
||||
state->ScrollX = 0.0f;
|
||||
state->Scroll = ImVec2(0.0f, 0.0f);
|
||||
stb_textedit_initialize_state(&state->Stb, !is_multiline);
|
||||
}
|
||||
|
||||
@ -4459,6 +4459,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
// FIXME: May be a problem to always steal Alt on OSX, would ideally still allow an uninterrupted Alt down-up to toggle menu
|
||||
if (is_osx)
|
||||
SetKeyOwner(ImGuiMod_Alt, id);
|
||||
|
||||
// Expose scroll in a manner that is agnostic to us using a child window
|
||||
if (is_multiline)
|
||||
state->Scroll.y = draw_window->Scroll.y;
|
||||
}
|
||||
|
||||
// We have an edge case if ActiveId was set through another widget (e.g. widget being swapped), clear id immediately (don't wait until the end of the function)
|
||||
@ -4522,7 +4526,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
g.ActiveIdAllowOverlap = !io.MouseDown[0];
|
||||
|
||||
// Edit in progress
|
||||
const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + state->ScrollX;
|
||||
const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + state->Scroll.x;
|
||||
const float mouse_y = (is_multiline ? (io.MousePos.y - draw_window->DC.CursorPos.y) : (g.FontSize * 0.5f));
|
||||
|
||||
if (select_all)
|
||||
@ -5078,14 +5082,14 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
{
|
||||
const float scroll_increment_x = inner_size.x * 0.25f;
|
||||
const float visible_width = inner_size.x - style.FramePadding.x;
|
||||
if (cursor_offset.x < state->ScrollX)
|
||||
state->ScrollX = IM_TRUNC(ImMax(0.0f, cursor_offset.x - scroll_increment_x));
|
||||
else if (cursor_offset.x - visible_width >= state->ScrollX)
|
||||
state->ScrollX = IM_TRUNC(cursor_offset.x - visible_width + scroll_increment_x);
|
||||
if (cursor_offset.x < state->Scroll.x)
|
||||
state->Scroll.x = IM_TRUNC(ImMax(0.0f, cursor_offset.x - scroll_increment_x));
|
||||
else if (cursor_offset.x - visible_width >= state->Scroll.x)
|
||||
state->Scroll.x = IM_TRUNC(cursor_offset.x - visible_width + scroll_increment_x);
|
||||
}
|
||||
else
|
||||
{
|
||||
state->ScrollX = 0.0f;
|
||||
state->Scroll.y = 0.0f;
|
||||
}
|
||||
|
||||
// Vertical scroll
|
||||
@ -5106,7 +5110,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
}
|
||||
|
||||
// Draw selection
|
||||
const ImVec2 draw_scroll = ImVec2(state->ScrollX, 0.0f);
|
||||
const ImVec2 draw_scroll = ImVec2(state->Scroll.x, 0.0f);
|
||||
if (render_selection)
|
||||
{
|
||||
const ImWchar* text_selected_begin = text_begin + ImMin(state->Stb.select_start, state->Stb.select_end);
|
||||
|
Loading…
Reference in New Issue
Block a user