SetKeyboardFocusHere() allow for an offset to access sub components + comments

docking
ocornut 10 years ago
parent f1ea630dd0
commit ce481ec702

@ -762,15 +762,15 @@ struct ImGuiWindow
float ItemWidthDefault;
ImGuiStorage StateStorage;
float FontWindowScale; // Scale multipler per-window
ImDrawList* DrawList;
// Focus
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;
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:
ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size);
@ -1022,12 +1022,12 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si
if (ImLength(Size) < 0.001f)
AutoFitFrames = 3;
DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
new(DrawList) ImDrawList();
FocusIdxAllCounter = FocusIdxTabCounter = -1;
FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
new(DrawList) ImDrawList();
}
ImGuiWindow::~ImGuiWindow()
@ -2106,17 +2106,15 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
else
window->ItemWidthDefault = 200.0f;
// Prepare for keyboard TAB focus requests
// Prepare for focus requests
if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
window->FocusIdxAllRequestCurrent = IM_INT_MAX;
else
window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
{
window->FocusIdxTabRequestCurrent = IM_INT_MAX;
}
else
{
const int mod = window->FocusIdxTabCounter+1;
window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + mod) % mod;
}
window->FocusIdxAllRequestCurrent = window->FocusIdxAllRequestNext;
window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
@ -2640,10 +2638,10 @@ void SetScrollPosHere()
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();
window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1;
window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
window->FocusIdxTabRequestNext = IM_INT_MAX;
}

@ -153,7 +153,7 @@ namespace ImGui
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 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).
ImGuiStorage* GetTreeStateStorage();
void PushItemWidth(float item_width);

Loading…
Cancel
Save