mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Having a InputText() active doesn't steal mouse inputs (relate to #134)
This commit is contained in:
parent
87a3522eb2
commit
185744e697
29
imgui.cpp
29
imgui.cpp
@ -992,6 +992,7 @@ struct ImGuiState
|
|||||||
ImGuiID ActiveId;
|
ImGuiID ActiveId;
|
||||||
ImGuiID ActiveIdPreviousFrame;
|
ImGuiID ActiveIdPreviousFrame;
|
||||||
bool ActiveIdIsAlive;
|
bool ActiveIdIsAlive;
|
||||||
|
bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction.
|
||||||
float SettingsDirtyTimer;
|
float SettingsDirtyTimer;
|
||||||
ImVector<ImGuiIniData*> Settings;
|
ImVector<ImGuiIniData*> Settings;
|
||||||
ImVector<ImGuiColMod> ColorModifiers;
|
ImVector<ImGuiColMod> ColorModifiers;
|
||||||
@ -1046,6 +1047,7 @@ struct ImGuiState
|
|||||||
ActiveId = 0;
|
ActiveId = 0;
|
||||||
ActiveIdPreviousFrame = 0;
|
ActiveIdPreviousFrame = 0;
|
||||||
ActiveIdIsAlive = false;
|
ActiveIdIsAlive = false;
|
||||||
|
ActiveIdIsFocusedOnly = false;
|
||||||
SettingsDirtyTimer = 0.0f;
|
SettingsDirtyTimer = 0.0f;
|
||||||
SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
|
SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
|
||||||
SetNextWindowPosCond = 0;
|
SetNextWindowPosCond = 0;
|
||||||
@ -1149,6 +1151,7 @@ static void SetActiveId(ImGuiID id)
|
|||||||
{
|
{
|
||||||
ImGuiState& g = *GImGui;
|
ImGuiState& g = *GImGui;
|
||||||
g.ActiveId = id;
|
g.ActiveId = id;
|
||||||
|
g.ActiveIdIsFocusedOnly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RegisterAliveId(const ImGuiID& id)
|
static void RegisterAliveId(const ImGuiID& id)
|
||||||
@ -3791,8 +3794,11 @@ static bool IsHovered(const ImGuiAabb& bb, const ImGuiID& id)
|
|||||||
if (g.HoveredId == 0)
|
if (g.HoveredId == 0)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb);
|
if (g.HoveredRootWindow == window->RootWindow)
|
||||||
return hovered;
|
{
|
||||||
|
bool hovered = (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb);
|
||||||
|
return hovered;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -4516,20 +4522,14 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
|||||||
if (g.SliderAsInputTextId == 0)
|
if (g.SliderAsInputTextId == 0)
|
||||||
{
|
{
|
||||||
// First frame
|
// First frame
|
||||||
IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both which is also possible)
|
IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible)
|
||||||
g.SliderAsInputTextId = g.ActiveId;
|
g.SliderAsInputTextId = g.ActiveId;
|
||||||
SetActiveId(id);
|
|
||||||
g.HoveredId = id;
|
g.HoveredId = id;
|
||||||
}
|
}
|
||||||
else
|
else if (g.ActiveId != g.SliderAsInputTextId)
|
||||||
{
|
{
|
||||||
if (g.ActiveId == g.SliderAsInputTextId)
|
// Release
|
||||||
SetActiveId(id);
|
g.SliderAsInputTextId = 0;
|
||||||
else
|
|
||||||
{
|
|
||||||
SetActiveId(0);
|
|
||||||
g.SliderAsInputTextId = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (value_changed)
|
if (value_changed)
|
||||||
{
|
{
|
||||||
@ -5379,6 +5379,11 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
if (g.ActiveId == id)
|
||||||
|
g.ActiveIdIsFocusedOnly = !io.MouseDown[0];
|
||||||
|
|
||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
bool cancel_edit = false;
|
bool cancel_edit = false;
|
||||||
bool enter_pressed = false;
|
bool enter_pressed = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user