mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internals: Moved some of the SliderBehaviorT code into SliderBehavior to reduce the amount of instanciated code.
This commit is contained in:
parent
a1ec7723ef
commit
9d67d18d86
19
imgui.cpp
19
imgui.cpp
@ -9073,14 +9073,9 @@ template<typename TYPE, typename SIGNEDTYPE, typename FLOATTYPE>
|
|||||||
static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const char* format, float power, ImGuiSliderFlags flags)
|
static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const char* format, float power, ImGuiSliderFlags flags)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
const ImGuiStyle& style = g.Style;
|
const ImGuiStyle& style = g.Style;
|
||||||
|
|
||||||
// Draw frame
|
|
||||||
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
|
|
||||||
RenderNavHighlight(bb, id);
|
|
||||||
RenderFrame(bb.Min, bb.Max, frame_col, true, style.FrameRounding);
|
|
||||||
|
|
||||||
const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0;
|
const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0;
|
||||||
const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
|
const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
|
||||||
const bool is_power = (power != 1.0f) && is_decimal;
|
const bool is_power = (power != 1.0f) && is_decimal;
|
||||||
@ -9241,10 +9236,16 @@ static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For 32-bits and larger types, slider bounds are limited to half the natural type range.
|
// For 32-bits and larger types, slider bounds are limited to half the natural type range.
|
||||||
// So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2.
|
// So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2 will be ok.
|
||||||
// It would be possible to life that limitation with some work but it doesn't seem to be work it for sliders.
|
// It would be possible to lift that limitation with some work but it doesn't seem to be worth it for sliders.
|
||||||
bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags)
|
bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags)
|
||||||
{
|
{
|
||||||
|
// Draw frame
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
|
||||||
|
RenderNavHighlight(bb, id);
|
||||||
|
RenderFrame(bb.Min, bb.Max, frame_col, true, g.Style.FrameRounding);
|
||||||
|
|
||||||
switch (data_type)
|
switch (data_type)
|
||||||
{
|
{
|
||||||
case ImGuiDataType_S32:
|
case ImGuiDataType_S32:
|
||||||
@ -9520,7 +9521,7 @@ static bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed
|
|||||||
if (g.IO.KeyShift)
|
if (g.IO.KeyShift)
|
||||||
adjust_delta *= 10.0f;
|
adjust_delta *= 10.0f;
|
||||||
}
|
}
|
||||||
if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
else if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
||||||
{
|
{
|
||||||
int decimal_precision = (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImParseFormatPrecision(format, 3) : 0;
|
int decimal_precision = (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImParseFormatPrecision(format, 3) : 0;
|
||||||
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
||||||
|
Loading…
Reference in New Issue
Block a user