mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-25 21:17:01 +00:00
InputText: added ImGuiInputTextFlags_NoHorizontalScroll flag. Added HasSelection() helper in ImGuiTextEditCallbackData as a clarification.
This commit is contained in:
parent
f2bed00d80
commit
d2701727b9
17
imgui.cpp
17
imgui.cpp
@ -7419,11 +7419,18 @@ static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
if (edit_state.CursorFollow)
|
||||
{
|
||||
// Horizontal scroll in chunks of quarter width
|
||||
const float scroll_increment_x = size.x * 0.25f;
|
||||
if (cursor_offset.x < edit_state.ScrollX)
|
||||
edit_state.ScrollX = ImMax(0.0f, cursor_offset.x - scroll_increment_x);
|
||||
else if (cursor_offset.x - size.x >= edit_state.ScrollX)
|
||||
edit_state.ScrollX = cursor_offset.x - size.x + scroll_increment_x;
|
||||
if (!(flags & ImGuiInputTextFlags_NoHorizontalScroll))
|
||||
{
|
||||
const float scroll_increment_x = size.x * 0.25f;
|
||||
if (cursor_offset.x < edit_state.ScrollX)
|
||||
edit_state.ScrollX = ImMax(0.0f, cursor_offset.x - scroll_increment_x);
|
||||
else if (cursor_offset.x - size.x >= edit_state.ScrollX)
|
||||
edit_state.ScrollX = cursor_offset.x - size.x + scroll_increment_x;
|
||||
}
|
||||
else
|
||||
{
|
||||
edit_state.ScrollX = 0.0f;
|
||||
}
|
||||
|
||||
// Vertical scroll
|
||||
if (is_multiline)
|
||||
|
2
imgui.h
2
imgui.h
@ -461,6 +461,7 @@ enum ImGuiInputTextFlags_
|
||||
ImGuiInputTextFlags_CallbackCharFilter = 1 << 9, // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character.
|
||||
ImGuiInputTextFlags_AllowTabInput = 1 << 10, // Pressing TAB input a '\t' character into the text field
|
||||
ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11, // In multi-line mode, allow exiting edition by pressing Enter. Ctrl+Enter to add new line (by default adds new lines with Enter).
|
||||
ImGuiInputTextFlags_NoHorizontalScroll = 1 << 12, // Disable following the cursor horizontally
|
||||
// [Internal]
|
||||
ImGuiInputTextFlags_Multiline = 1 << 20 // For internal use by InputTextMultiline()
|
||||
};
|
||||
@ -919,6 +920,7 @@ struct ImGuiTextEditCallbackData
|
||||
// NB: calling those function loses selection.
|
||||
void DeleteChars(int pos, int bytes_count);
|
||||
void InsertChars(int pos, const char* text, const char* text_end = NULL);
|
||||
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
||||
};
|
||||
|
||||
// ImColor() is just a helper that implicity converts to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
|
||||
|
Loading…
Reference in New Issue
Block a user