mirror of
https://github.com/ocornut/imgui.git
synced 2025-02-06 22:34:24 +01:00
SetKeyboardFocusHere() allow for an offset to access sub components + comments
This commit is contained in:
parent
f1ea630dd0
commit
ce481ec702
60
imgui.cpp
60
imgui.cpp
@ -762,16 +762,16 @@ struct ImGuiWindow
|
|||||||
float ItemWidthDefault;
|
float ItemWidthDefault;
|
||||||
ImGuiStorage StateStorage;
|
ImGuiStorage StateStorage;
|
||||||
float FontWindowScale; // Scale multipler per-window
|
float FontWindowScale; // Scale multipler per-window
|
||||||
|
|
||||||
int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
|
|
||||||
int FocusIdxTabCounter; // (same, but only include widgets which you can Tab through)
|
|
||||||
int FocusIdxAllRequestCurrent; // Item being requested for focus, rely on layout to be stable between the frame pressing TAB and the next frame
|
|
||||||
int FocusIdxTabRequestCurrent;
|
|
||||||
int FocusIdxAllRequestNext; // Item being requested for focus, for next update
|
|
||||||
int FocusIdxTabRequestNext;
|
|
||||||
|
|
||||||
ImDrawList* DrawList;
|
ImDrawList* DrawList;
|
||||||
|
|
||||||
|
// Focus
|
||||||
|
int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
|
||||||
|
int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
|
||||||
|
int FocusIdxAllRequestCurrent; // Item being requested for focus
|
||||||
|
int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
|
||||||
|
int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
|
||||||
|
int FocusIdxTabRequestNext; // "
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size);
|
ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size);
|
||||||
~ImGuiWindow();
|
~ImGuiWindow();
|
||||||
@ -1022,12 +1022,12 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si
|
|||||||
if (ImLength(Size) < 0.001f)
|
if (ImLength(Size) < 0.001f)
|
||||||
AutoFitFrames = 3;
|
AutoFitFrames = 3;
|
||||||
|
|
||||||
|
DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
|
||||||
|
new(DrawList) ImDrawList();
|
||||||
|
|
||||||
FocusIdxAllCounter = FocusIdxTabCounter = -1;
|
FocusIdxAllCounter = FocusIdxTabCounter = -1;
|
||||||
FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
|
FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
|
||||||
FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
|
FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
|
||||||
|
|
||||||
DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
|
|
||||||
new(DrawList) ImDrawList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiWindow::~ImGuiWindow()
|
ImGuiWindow::~ImGuiWindow()
|
||||||
@ -1061,7 +1061,7 @@ bool ImGuiWindow::FocusItemRegister(bool is_active)
|
|||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
|
const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
|
||||||
FocusIdxAllCounter++;
|
FocusIdxAllCounter++;
|
||||||
if (allow_keyboard_focus)
|
if (allow_keyboard_focus)
|
||||||
FocusIdxTabCounter++;
|
FocusIdxTabCounter++;
|
||||||
|
|
||||||
@ -1073,19 +1073,19 @@ bool ImGuiWindow::FocusItemRegister(bool is_active)
|
|||||||
FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
|
FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
|
if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (allow_keyboard_focus)
|
if (allow_keyboard_focus)
|
||||||
if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
|
if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiWindow::FocusItemUnregister()
|
void ImGuiWindow::FocusItemUnregister()
|
||||||
{
|
{
|
||||||
FocusIdxAllCounter--;
|
FocusIdxAllCounter--;
|
||||||
FocusIdxTabCounter--;
|
FocusIdxTabCounter--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2106,18 +2106,16 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
|
|||||||
else
|
else
|
||||||
window->ItemWidthDefault = 200.0f;
|
window->ItemWidthDefault = 200.0f;
|
||||||
|
|
||||||
// Prepare for keyboard TAB focus requests
|
// Prepare for focus requests
|
||||||
if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
|
if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
|
||||||
{
|
window->FocusIdxAllRequestCurrent = IM_INT_MAX;
|
||||||
window->FocusIdxTabRequestCurrent = IM_INT_MAX;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
|
||||||
const int mod = window->FocusIdxTabCounter+1;
|
if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
|
||||||
window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + mod) % mod;
|
window->FocusIdxTabRequestCurrent = IM_INT_MAX;
|
||||||
}
|
else
|
||||||
window->FocusIdxAllRequestCurrent = window->FocusIdxAllRequestNext;
|
window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
|
||||||
window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
|
window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
|
||||||
window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
|
window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
|
||||||
|
|
||||||
ImGuiAabb title_bar_aabb = window->TitleBarAabb();
|
ImGuiAabb title_bar_aabb = window->TitleBarAabb();
|
||||||
@ -2640,11 +2638,11 @@ void SetScrollPosHere()
|
|||||||
window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
|
window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetKeyboardFocusHere()
|
void SetKeyboardFocusHere(int offset)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1;
|
window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
|
||||||
window->FocusIdxTabRequestNext = IM_INT_MAX;
|
window->FocusIdxTabRequestNext = IM_INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTreeStateStorage(ImGuiStorage* tree)
|
void SetTreeStateStorage(ImGuiStorage* tree)
|
||||||
|
2
imgui.h
2
imgui.h
@ -153,7 +153,7 @@ namespace ImGui
|
|||||||
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
|
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
|
||||||
void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
|
void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
|
||||||
void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
|
void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
|
||||||
void SetKeyboardFocusHere(); // focus keyboard on the next widget
|
void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget.
|
||||||
void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
|
void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
|
||||||
ImGuiStorage* GetTreeStateStorage();
|
ImGuiStorage* GetTreeStateStorage();
|
||||||
void PushItemWidth(float item_width);
|
void PushItemWidth(float item_width);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user