Skip to content

Commit

Permalink
Internals: Moved the FocusableItemUnregister() outside of InputScalar…
Browse files Browse the repository at this point in the history
…AsWidgetReplacement(), it should not be here and doesn't facilitate reusing InputScalarAsWidgetReplacement(). (cc #2155)
  • Loading branch information
ocornut committed Oct 30, 2018
1 parent e6db078 commit 7fa3e71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Other Changes:
in particular, points_count==0 could lead to a memory stomp if the draw list was previously empty.
- Examples: DirectX10, DirectX11: Removed seemingly unnecessary calls to invalidate and recreate device objects
in the WM_SIZE handler. (#2088) [@ice1000]
- Examples: OpenGL3+GLFW: Fixed error condition when using the GLAD loader. (#2157) [@blackball]


-----------------------------------------------------------------------
Expand All @@ -99,7 +100,7 @@ Other Changes:
Although it is not perfect and will keep being improved, it is fairly functional and used by many. (#787)
- Fixed a build issue with non-Cygwin GCC under Windows.
- Demo: Added a "Configuration" block to make io.ConfigFlags/io.BackendFlags more prominent.
- Examples: OpenGL3: Fixed error condition when using the GLAD loader. (#2059, #2002) [@jiri]
- Examples: OpenGL3+SDL2: Fixed error condition when using the GLAD loader. (#2059, #2002) [@jiri]


-----------------------------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float


//-------------------------------------------------------------------------
// [SECTION] Widgets: Combo Box
// [SECTION] Widgets: ComboBox
//-------------------------------------------------------------------------
// - BeginCombo()
// - EndCombo()
Expand Down Expand Up @@ -1882,7 +1882,10 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
}
}
if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id))
{
FocusableItemUnregister(window);
return InputScalarAsWidgetReplacement(frame_bb, id, label, data_type, v, format);
}

// Actual drag behavior
ItemSize(total_bb, style.FramePadding.y);
Expand Down Expand Up @@ -2313,7 +2316,10 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co
}
}
if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id))
{
FocusableItemUnregister(window);
return InputScalarAsWidgetReplacement(frame_bb, id, label, data_type, v, format);
}

ItemSize(total_bb, style.FramePadding.y);

Expand Down Expand Up @@ -2584,8 +2590,8 @@ int ImParseFormatPrecision(const char* fmt, int default_precision)
return (precision == INT_MAX) ? default_precision : precision;
}

// Create text input in place of a slider (when CTRL+Clicking on slider)
// FIXME: Logic is messy and confusing.
// 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.
bool ImGui::InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* data_ptr, const char* format)
{
ImGuiContext& g = *GImGui;
Expand All @@ -2594,9 +2600,8 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const c
// 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);
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
SetHoveredID(0);
FocusableItemUnregister(window);
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);

char fmt_buf[32];
char data_buf[32];
Expand Down

0 comments on commit 7fa3e71

Please sign in to comment.