mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Internals: InputScalarAsWidgetReplacement: Fixed seemingly unnecessary calling of SetActiveID/SetHoveredID every frame, which in turns allow us to remove the g.ActiveIdAllow/Block settings duplicated.
This commit is contained in:
parent
fb4f1ff7f6
commit
1fb57c97c6
@ -2617,18 +2617,15 @@ int ImParseFormatPrecision(const char* fmt, int default_precision)
|
||||
}
|
||||
|
||||
// Create text input in place of an active drag/slider (used when doing a CTRL+Click on drag/slider widgets)
|
||||
// FIXME: Logic is awkward and confusing. This should be reworked to facilitate using in other situations.
|
||||
// FIXME: Facilitate using this in variety of other situations.
|
||||
bool ImGui::InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* data_ptr, const char* format)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
|
||||
// Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
|
||||
// On the first frame, g.ScalarAsInputTextId == 0, then on subsequent frames it becomes == id
|
||||
SetActiveID(g.ScalarAsInputTextId, window);
|
||||
SetHoveredID(0);
|
||||
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
|
||||
g.ActiveIdBlockNavInputFlags = (1 << ImGuiNavInput_Cancel);
|
||||
// On the first frame, g.ScalarAsInputTextId == 0, then on subsequent frames it becomes == id.
|
||||
// We clear ActiveID on the first frame to allow the InputText() taking it back.
|
||||
if (g.ScalarAsInputTextId == 0)
|
||||
ClearActiveID();
|
||||
|
||||
char fmt_buf[32];
|
||||
char data_buf[32];
|
||||
@ -2637,11 +2634,11 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const c
|
||||
ImStrTrimBlanks(data_buf);
|
||||
ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | ((data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImGuiInputTextFlags_CharsScientific : ImGuiInputTextFlags_CharsDecimal);
|
||||
bool value_changed = InputTextEx(label, data_buf, IM_ARRAYSIZE(data_buf), bb.GetSize(), flags);
|
||||
if (g.ScalarAsInputTextId == 0) // First frame we started displaying the InputText widget
|
||||
if (g.ScalarAsInputTextId == 0)
|
||||
{
|
||||
IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID
|
||||
// First frame we started displaying the InputText widget, we expect it to take the active id.
|
||||
IM_ASSERT(g.ActiveId == id);
|
||||
g.ScalarAsInputTextId = g.ActiveId;
|
||||
SetHoveredID(id);
|
||||
}
|
||||
if (value_changed)
|
||||
return DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialText.Data, data_type, data_ptr, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user