Add a parameter to disable +/- buttons for gui input hex
This commit is contained in:
@@ -20,7 +20,7 @@ static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(
|
|||||||
bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
||||||
const void* p_step, const void* p_step_fast,
|
const void* p_step, const void* p_step_fast,
|
||||||
const char* format, float input_width,
|
const char* format, float input_width,
|
||||||
ImGuiInputTextFlags flags) {
|
ImGuiInputTextFlags flags, bool no_step = false) {
|
||||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||||
if (window->SkipItems) return false;
|
if (window->SkipItems) return false;
|
||||||
|
|
||||||
@@ -39,11 +39,11 @@ bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
|||||||
flags |= ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited;
|
flags |= ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited;
|
||||||
|
|
||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
if (p_step == NULL) {
|
// if (p_step == NULL) {
|
||||||
ImGui::SetNextItemWidth(input_width);
|
// ImGui::SetNextItemWidth(input_width);
|
||||||
if (InputText(label, buf, IM_ARRAYSIZE(buf), flags))
|
// if (InputText("", buf, IM_ARRAYSIZE(buf), flags))
|
||||||
value_changed = DataTypeApplyFromText(buf, data_type, p_data, format);
|
// value_changed = DataTypeApplyFromText(buf, data_type, p_data, format);
|
||||||
} else {
|
// } else {
|
||||||
const float button_size = GetFrameHeight();
|
const float button_size = GetFrameHeight();
|
||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
ImGui::Text("%s", label);
|
ImGui::Text("%s", label);
|
||||||
@@ -91,6 +91,7 @@ bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step buttons
|
// Step buttons
|
||||||
|
if (!no_step) {
|
||||||
const ImVec2 backup_frame_padding = style.FramePadding;
|
const ImVec2 backup_frame_padding = style.FramePadding;
|
||||||
style.FramePadding.x = style.FramePadding.y;
|
style.FramePadding.x = style.FramePadding.y;
|
||||||
ImGuiButtonFlags button_flags =
|
ImGuiButtonFlags button_flags =
|
||||||
@@ -108,14 +109,15 @@ bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
|||||||
g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step);
|
g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step);
|
||||||
value_changed = true;
|
value_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & ImGuiInputTextFlags_ReadOnly) EndDisabled();
|
if (flags & ImGuiInputTextFlags_ReadOnly) EndDisabled();
|
||||||
|
|
||||||
style.FramePadding = backup_frame_padding;
|
style.FramePadding = backup_frame_padding;
|
||||||
|
}
|
||||||
PopID();
|
PopID();
|
||||||
EndGroup();
|
EndGroup();
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(2);
|
||||||
}
|
|
||||||
if (value_changed) MarkItemEdited(g.LastItemData.ID);
|
if (value_changed) MarkItemEdited(g.LastItemData.ID);
|
||||||
|
|
||||||
return value_changed;
|
return value_changed;
|
||||||
@@ -148,17 +150,25 @@ bool InputHexShort(const char* label, uint32_t* data) {
|
|||||||
ImGuiInputTextFlags_CharsHexadecimal);
|
ImGuiInputTextFlags_CharsHexadecimal);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputHexWord(const char* label, uint16_t* data, float input_width) {
|
bool InputHexWord(const char* label, uint16_t* data, float input_width,
|
||||||
|
bool no_step) {
|
||||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U16, data, &kStepOneHex,
|
return ImGui::InputScalarLeft(label, ImGuiDataType_U16, data, &kStepOneHex,
|
||||||
&kStepFastHex, "%04X", input_width,
|
&kStepFastHex, "%04X", input_width,
|
||||||
ImGuiInputTextFlags_CharsHexadecimal);
|
ImGuiInputTextFlags_CharsHexadecimal, no_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputHexByte(const char* label, uint8_t* data, uint8_t step,
|
bool InputHexWord(const char* label, int16_t* data, float input_width,
|
||||||
float input_width) {
|
bool no_step) {
|
||||||
|
return ImGui::InputScalarLeft(label, ImGuiDataType_S16, data, &kStepOneHex,
|
||||||
|
&kStepFastHex, "%04X", input_width,
|
||||||
|
ImGuiInputTextFlags_CharsHexadecimal, no_step);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputHexByte(const char* label, uint8_t* data, float input_width,
|
||||||
|
bool no_step) {
|
||||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &kStepOneHex,
|
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &kStepOneHex,
|
||||||
&kStepFastHex, "%02X", input_width,
|
&kStepFastHex, "%02X", input_width,
|
||||||
ImGuiInputTextFlags_CharsHexadecimal);
|
ImGuiInputTextFlags_CharsHexadecimal, no_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLabel(absl::string_view title, ItemLabelFlags flags) {
|
void ItemLabel(absl::string_view title, ItemLabelFlags flags) {
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ IMGUI_API bool InputHex(const char* label, int* data, int num_digits = 4,
|
|||||||
float input_width = 50.f);
|
float input_width = 50.f);
|
||||||
IMGUI_API bool InputHexShort(const char* label, uint32_t* data);
|
IMGUI_API bool InputHexShort(const char* label, uint32_t* data);
|
||||||
IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
|
IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
|
||||||
float input_width = 50.f);
|
float input_width = 50.f, bool no_step = false);
|
||||||
|
IMGUI_API bool InputHexWord(const char* label, int16_t* data,
|
||||||
|
float input_width = 50.f, bool no_step = false);
|
||||||
IMGUI_API bool InputHexByte(const char* label, uint8_t* data,
|
IMGUI_API bool InputHexByte(const char* label, uint8_t* data,
|
||||||
uint8_t step = 0x01, float input_width = 50.f);
|
float input_width = 50.f, bool no_step = false);
|
||||||
|
|
||||||
IMGUI_API bool ListBox(const char* label, int* current_item,
|
IMGUI_API bool ListBox(const char* label, int* current_item,
|
||||||
const std::vector<std::string>& items,
|
const std::vector<std::string>& items,
|
||||||
|
|||||||
Reference in New Issue
Block a user