30 const void* p_step,
const void* p_step_fast,
31 const char* format,
float input_width,
32 ImGuiInputTextFlags flags,
bool no_step =
false) {
33 ImGuiWindow* window = ImGui::GetCurrentWindow();
34 if (window->SkipItems)
return false;
36 ImGuiContext& g = *GImGui;
37 ImGuiStyle& style = g.Style;
39 if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt;
42 DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, p_data, format);
44 if (g.ActiveId == 0 && (flags & (ImGuiInputTextFlags_CharsDecimal |
45 ImGuiInputTextFlags_CharsHexadecimal |
46 ImGuiInputTextFlags_CharsScientific)) == 0)
47 flags |= InputScalar_DefaultCharsFilter(data_type, format);
48 flags |= ImGuiInputTextFlags_AutoSelectAll;
50 bool value_changed =
false;
56 const float button_size = GetFrameHeight();
57 AlignTextToFramePadding();
63 SetNextItemWidth(ImMax(
64 1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2));
67 PushStyleVar(ImGuiStyleVar_ItemSpacing,
68 ImVec2{style.ItemSpacing.x, style.ItemSpacing.y});
69 PushStyleVar(ImGuiStyleVar_FramePadding,
70 ImVec2{style.FramePadding.x, style.FramePadding.y});
72 SetNextItemWidth(input_width);
73 if (InputText(
"", buf, IM_ARRAYSIZE(buf),
76 value_changed = DataTypeApplyFromText(buf, data_type, p_data, format);
77 IMGUI_TEST_ENGINE_ITEM_INFO(
78 g.LastItemData.ID, label,
79 g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Inputable);
82 if (IsItemHovered() && g.IO.MouseWheel != 0.0f) {
83 float scroll_amount = g.IO.MouseWheel;
84 float scroll_speed = 0.25f;
86 if (g.IO.KeyCtrl && p_step_fast)
87 scroll_amount *= *(
const float*)p_step_fast;
89 scroll_amount *= *(
const float*)p_step;
91 if (scroll_amount > 0.0f) {
92 scroll_amount *= scroll_speed;
93 DataTypeApplyOp(data_type,
'+', p_data, p_data, &scroll_amount);
95 }
else if (scroll_amount < 0.0f) {
96 scroll_amount *= -scroll_speed;
97 DataTypeApplyOp(data_type,
'-', p_data, p_data, &scroll_amount);
104 const ImVec2 backup_frame_padding = style.FramePadding;
105 style.FramePadding.x = style.FramePadding.y;
106 ImGuiButtonFlags button_flags = ImGuiButtonFlags_PressedOnClick;
107 if (flags & ImGuiInputTextFlags_ReadOnly) BeginDisabled();
108 SameLine(0, style.ItemInnerSpacing.x);
109 if (ButtonEx(
"-", ImVec2(button_size, button_size), button_flags)) {
110 DataTypeApplyOp(data_type,
'-', p_data, p_data,
111 g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step);
112 value_changed =
true;
114 SameLine(0, style.ItemInnerSpacing.x);
115 if (ButtonEx(
"+", ImVec2(button_size, button_size), button_flags)) {
116 DataTypeApplyOp(data_type,
'+', p_data, p_data,
117 g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step);
118 value_changed =
true;
121 if (flags & ImGuiInputTextFlags_ReadOnly) EndDisabled();
123 style.FramePadding = backup_frame_padding;
127 ImGui::PopStyleVar(2);
129 if (value_changed) MarkItemEdited(g.LastItemData.ID);
131 return value_changed;