mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Added DragFloatRange2() DragIntRange2() helpers (#76)
This commit is contained in:
parent
a33810d652
commit
d76bc3434e
65
imgui.cpp
65
imgui.cpp
@ -719,8 +719,10 @@ void ImGuiIO::AddInputCharacter(ImWchar c)
|
|||||||
const float IM_PI = 3.14159265358979323846f;
|
const float IM_PI = 3.14159265358979323846f;
|
||||||
|
|
||||||
#ifdef INT_MAX
|
#ifdef INT_MAX
|
||||||
|
#define IM_INT_MIN INT_MIN
|
||||||
#define IM_INT_MAX INT_MAX
|
#define IM_INT_MAX INT_MAX
|
||||||
#else
|
#else
|
||||||
|
#define IM_INT_MIN (-2147483647-1)
|
||||||
#define IM_INT_MAX (2147483647)
|
#define IM_INT_MAX (2147483647)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -6406,6 +6408,31 @@ bool ImGui::DragFloat4(const char* label, float v[2], float v_speed, float v_min
|
|||||||
return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power);
|
return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed, float v_min, float v_max, const char* display_format, const char* display_format_max, float power)
|
||||||
|
{
|
||||||
|
ImGuiState& g = *GImGui;
|
||||||
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
if (window->SkipItems)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ImGui::PushID(label);
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
PushMultiItemsWidths(2);
|
||||||
|
|
||||||
|
bool value_changed = ImGui::DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format, power);
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
|
||||||
|
value_changed |= ImGui::DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, display_format_max ? display_format_max : display_format, power);
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
|
||||||
|
|
||||||
|
ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
|
||||||
|
ImGui::EndGroup();
|
||||||
|
ImGui::PopID();
|
||||||
|
|
||||||
|
return value_changed;
|
||||||
|
}
|
||||||
|
|
||||||
// NB: v_speed is float to allow adjusting the drag speed with more precision
|
// NB: v_speed is float to allow adjusting the drag speed with more precision
|
||||||
bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format)
|
bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format)
|
||||||
{
|
{
|
||||||
@ -6459,6 +6486,31 @@ bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int
|
|||||||
return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format);
|
return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed, int v_min, int v_max, const char* display_format, const char* display_format_max)
|
||||||
|
{
|
||||||
|
ImGuiState& g = *GImGui;
|
||||||
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
if (window->SkipItems)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ImGui::PushID(label);
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
PushMultiItemsWidths(2);
|
||||||
|
|
||||||
|
bool value_changed = ImGui::DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? IM_INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format);
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
|
||||||
|
value_changed |= ImGui::DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? IM_INT_MAX : v_max, display_format_max ? display_format_max : display_format);
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
|
||||||
|
|
||||||
|
ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
|
||||||
|
ImGui::EndGroup();
|
||||||
|
ImGui::PopID();
|
||||||
|
|
||||||
|
return value_changed;
|
||||||
|
}
|
||||||
|
|
||||||
enum ImGuiPlotType
|
enum ImGuiPlotType
|
||||||
{
|
{
|
||||||
ImGuiPlotType_Lines,
|
ImGuiPlotType_Lines,
|
||||||
@ -11171,6 +11223,19 @@ void ImGui::ShowTestWindow(bool* opened)
|
|||||||
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
||||||
//ImGui::PopItemWidth();
|
//ImGui::PopItemWidth();
|
||||||
|
|
||||||
|
if (ImGui::TreeNode("Ranges"))
|
||||||
|
{
|
||||||
|
ImGui::Unindent();
|
||||||
|
|
||||||
|
static float begin = 10, end = 90;
|
||||||
|
static int begin_i = 100, end_i = 1000;
|
||||||
|
ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
|
||||||
|
ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units");
|
||||||
|
|
||||||
|
ImGui::Indent();
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::TreeNode("Multi-component Widgets"))
|
if (ImGui::TreeNode("Multi-component Widgets"))
|
||||||
{
|
{
|
||||||
ImGui::Unindent();
|
ImGui::Unindent();
|
||||||
|
2
imgui.h
2
imgui.h
@ -250,10 +250,12 @@ namespace ImGui
|
|||||||
IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
|
IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
|
||||||
IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
|
IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
|
||||||
IMGUI_API bool DragFloat4(const char* label, float v[4], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
|
IMGUI_API bool DragFloat4(const char* label, float v[4], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
|
||||||
|
IMGUI_API bool DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", const char* display_format_max = NULL, float power = 1.0f);
|
||||||
IMGUI_API bool DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); // If v_min >= v_max we have no bound
|
IMGUI_API bool DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); // If v_min >= v_max we have no bound
|
||||||
IMGUI_API bool DragInt2(const char* label, int v[2], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
|
IMGUI_API bool DragInt2(const char* label, int v[2], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
|
||||||
IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
|
IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
|
||||||
IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
|
IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
|
||||||
|
IMGUI_API bool DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f", const char* display_format_max = NULL);
|
||||||
|
|
||||||
// Widgets: Input
|
// Widgets: Input
|
||||||
IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
|
IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user