mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Tracking ActiveIdWindow along with ActiveId
This commit is contained in:
parent
938528e5ee
commit
f8b7d5c76d
24
imgui.cpp
24
imgui.cpp
@ -1250,8 +1250,9 @@ struct ImGuiState
|
|||||||
ImGuiID ActiveId; // Active widget
|
ImGuiID ActiveId; // Active widget
|
||||||
ImGuiID ActiveIdPreviousFrame;
|
ImGuiID ActiveIdPreviousFrame;
|
||||||
bool ActiveIdIsAlive;
|
bool ActiveIdIsAlive;
|
||||||
bool ActiveIdIsJustActivated; // Set when
|
bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
|
||||||
bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction.
|
bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction
|
||||||
|
ImGuiWindow* ActiveIdWindow;
|
||||||
ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window.
|
ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window.
|
||||||
float SettingsDirtyTimer;
|
float SettingsDirtyTimer;
|
||||||
ImVector<ImGuiIniData> Settings;
|
ImVector<ImGuiIniData> Settings;
|
||||||
@ -1466,12 +1467,13 @@ static inline ImGuiWindow* GetParentWindow()
|
|||||||
return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2];
|
return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetActiveId(ImGuiID id)
|
static void SetActiveId(ImGuiID id, ImGuiWindow* window = NULL)
|
||||||
{
|
{
|
||||||
ImGuiState& g = *GImGui;
|
ImGuiState& g = *GImGui;
|
||||||
g.ActiveId = id;
|
g.ActiveId = id;
|
||||||
g.ActiveIdIsFocusedOnly = false;
|
g.ActiveIdIsFocusedOnly = false;
|
||||||
g.ActiveIdIsJustActivated = true;
|
g.ActiveIdIsJustActivated = true;
|
||||||
|
g.ActiveIdWindow = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RegisterAliveId(ImGuiID id)
|
static void RegisterAliveId(ImGuiID id)
|
||||||
@ -2379,7 +2381,7 @@ void ImGui::Render()
|
|||||||
{
|
{
|
||||||
IM_ASSERT(g.MovedWindow == NULL);
|
IM_ASSERT(g.MovedWindow == NULL);
|
||||||
g.MovedWindow = g.HoveredWindow;
|
g.MovedWindow = g.HoveredWindow;
|
||||||
SetActiveId(g.HoveredRootWindow->MoveID);
|
SetActiveId(g.HoveredRootWindow->MoveID, g.HoveredRootWindow);
|
||||||
}
|
}
|
||||||
else if (g.FocusedWindow != NULL)
|
else if (g.FocusedWindow != NULL)
|
||||||
{
|
{
|
||||||
@ -4887,7 +4889,7 @@ static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetActiveId(id);
|
SetActiveId(id, window);
|
||||||
}
|
}
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
}
|
}
|
||||||
@ -5537,7 +5539,7 @@ static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int
|
|||||||
char text_buf[64];
|
char text_buf[64];
|
||||||
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
|
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
|
||||||
|
|
||||||
SetActiveId(g.ScalarAsInputTextId);
|
SetActiveId(g.ScalarAsInputTextId, window);
|
||||||
g.HoveredId = 0;
|
g.HoveredId = 0;
|
||||||
|
|
||||||
// Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
|
// Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
|
||||||
@ -5767,7 +5769,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
|||||||
const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
|
const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
|
||||||
if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
|
if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
|
||||||
{
|
{
|
||||||
SetActiveId(id);
|
SetActiveId(id, window);
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
|
|
||||||
const bool is_ctrl_down = g.IO.KeyCtrl;
|
const bool is_ctrl_down = g.IO.KeyCtrl;
|
||||||
@ -5825,7 +5827,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
|
|||||||
|
|
||||||
if (hovered && g.IO.MouseClicked[0])
|
if (hovered && g.IO.MouseClicked[0])
|
||||||
{
|
{
|
||||||
SetActiveId(id);
|
SetActiveId(id, window);
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6071,7 +6073,7 @@ bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, f
|
|||||||
const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
|
const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
|
||||||
if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0])))
|
if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0])))
|
||||||
{
|
{
|
||||||
SetActiveId(id);
|
SetActiveId(id, window);
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
|
|
||||||
if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0])
|
if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0])
|
||||||
@ -6855,17 +6857,15 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT
|
|||||||
if (focus_requested_by_tab || (user_clicked && is_ctrl_down))
|
if (focus_requested_by_tab || (user_clicked && is_ctrl_down))
|
||||||
select_all = true;
|
select_all = true;
|
||||||
}
|
}
|
||||||
SetActiveId(id);
|
SetActiveId(id, window);
|
||||||
FocusWindow(window);
|
FocusWindow(window);
|
||||||
}
|
}
|
||||||
else if (io.MouseClicked[0])
|
else if (io.MouseClicked[0])
|
||||||
{
|
{
|
||||||
// Release focus when we click outside
|
// Release focus when we click outside
|
||||||
if (g.ActiveId == id)
|
if (g.ActiveId == id)
|
||||||
{
|
|
||||||
SetActiveId(0);
|
SetActiveId(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
|
// Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
|
||||||
// Down the line we should have a cleaner concept of focused vs active in the library.
|
// Down the line we should have a cleaner concept of focused vs active in the library.
|
||||||
|
Loading…
Reference in New Issue
Block a user