32 const void* p_step,
const void* p_step_fast,
33 const char* format,
float input_width,
34 ImGuiInputTextFlags flags,
bool no_step =
false) {
35 ImGuiWindow* window = ImGui::GetCurrentWindow();
36 if (window->SkipItems)
return false;
38 ImGuiContext& g = *GImGui;
39 ImGuiStyle& style = g.Style;
41 if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt;
44 DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, p_data, format);
46 if (g.ActiveId == 0 && (flags & (ImGuiInputTextFlags_CharsDecimal |
47 ImGuiInputTextFlags_CharsHexadecimal |
48 ImGuiInputTextFlags_CharsScientific)) == 0)
49 flags |= InputScalar_DefaultCharsFilter(data_type, format);
50 flags |= ImGuiInputTextFlags_AutoSelectAll;
52 bool value_changed =
false;
58 const float button_size = GetFrameHeight();
59 AlignTextToFramePadding();
65 SetNextItemWidth(ImMax(
66 1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2));
69 PushStyleVar(ImGuiStyleVar_ItemSpacing,
70 ImVec2{style.ItemSpacing.x, style.ItemSpacing.y});
71 PushStyleVar(ImGuiStyleVar_FramePadding,
72 ImVec2{style.FramePadding.x, style.FramePadding.y});
74 SetNextItemWidth(input_width);
75 if (InputText(
"", buf, IM_ARRAYSIZE(buf),
78 value_changed = DataTypeApplyFromText(buf, data_type, p_data, format);
79 IMGUI_TEST_ENGINE_ITEM_INFO(
80 g.LastItemData.ID, label,
81 g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Inputable);
84 if (IsItemHovered() && g.IO.MouseWheel != 0.0f) {
85 float scroll_amount = g.IO.MouseWheel;
86 float scroll_speed = 0.25f;
88 if (g.IO.KeyCtrl && p_step_fast)
89 scroll_amount *= *(
const float*)p_step_fast;
91 scroll_amount *= *(
const float*)p_step;
93 if (scroll_amount > 0.0f) {
94 scroll_amount *= scroll_speed;
95 DataTypeApplyOp(data_type,
'+', p_data, p_data, &scroll_amount);
97 }
else if (scroll_amount < 0.0f) {
98 scroll_amount *= -scroll_speed;
99 DataTypeApplyOp(data_type,
'-', p_data, p_data, &scroll_amount);
100 value_changed =
true;
106 const ImVec2 backup_frame_padding = style.FramePadding;
107 style.FramePadding.x = style.FramePadding.y;
108 ImGuiButtonFlags button_flags = ImGuiButtonFlags_PressedOnClick;
109 if (flags & ImGuiInputTextFlags_ReadOnly) BeginDisabled();
110 SameLine(0, style.ItemInnerSpacing.x);
111 if (ButtonEx(
"-", ImVec2(button_size, button_size), button_flags)) {
112 DataTypeApplyOp(data_type,
'-', p_data, p_data,
113 g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step);
114 value_changed =
true;
116 SameLine(0, style.ItemInnerSpacing.x);
117 if (ButtonEx(
"+", ImVec2(button_size, button_size), button_flags)) {
118 DataTypeApplyOp(data_type,
'+', p_data, p_data,
119 g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step);
120 value_changed =
true;
123 if (flags & ImGuiInputTextFlags_ReadOnly) EndDisabled();
125 style.FramePadding = backup_frame_padding;
129 ImGui::PopStyleVar(2);
131 if (value_changed) MarkItemEdited(g.LastItemData.ID);
133 return value_changed;