Skip to content

Commit 038d1e4

Browse files
committed
addons/imguivariouscontrols/imguivariouscontrols.h/.cpp: Added a pair of new widgets.
addons/imguistyleserializer/imguistyleserializer.h/.cpp: Added DafaultDark style.
1 parent 939ede8 commit 038d1e4

File tree

13 files changed

+279
-84
lines changed

13 files changed

+279
-84
lines changed

addons/imguibindings/imguibindings.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,16 +1639,26 @@ void ImImpl_RenderDrawLists(ImDrawData* draw_data)
16391639
#endif// IMGUI_USE_DIRECT3D9_BINDING
16401640

16411641
void ImImpl_NewFramePaused() {
1642+
// We use this method when ImGui is paused (= not displayed),
1643+
// so that we can still process input using ImGui calls
1644+
16421645
ImGuiContext& g = *GImGui;
16431646
g.Time += g.IO.DeltaTime;
16441647

1645-
// Update inputs state
1646-
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
1647-
g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
1648+
// Update keyboard input state
1649+
memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
1650+
for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
1651+
g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
1652+
1653+
// Update mouse inputs state
1654+
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX component, but in reality we test for -256000.0f) we cancel out movement in MouseDelta
1655+
if (ImGui::IsMousePosValid(&g.IO.MousePos) && ImGui::IsMousePosValid(&g.IO.MousePosPrev)) g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
1656+
else g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
1657+
/* Old code:
1658+
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
16481659
if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePosPrev.x < 0 && g.IO.MousePosPrev.y < 0)) // if mouse just appeared or disappeared (negative coordinate) we cancel out movement in MouseDelta
16491660
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
1650-
else
1651-
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
1661+
else g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;*/
16521662
g.IO.MousePosPrev = g.IO.MousePos;
16531663
for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
16541664
{
@@ -1670,16 +1680,17 @@ void ImImpl_NewFramePaused() {
16701680
g.IO.MouseClickedTime[i] = g.Time;
16711681
}
16721682
g.IO.MouseClickedPos[i] = g.IO.MousePos;
1683+
g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f);
16731684
g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
16741685
}
16751686
else if (g.IO.MouseDown[i])
16761687
{
1677-
g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]));
1688+
ImVec2 mouse_delta = g.IO.MousePos - g.IO.MouseClickedPos[i];
1689+
g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, mouse_delta.x < 0.0f ? -mouse_delta.x : mouse_delta.x);
1690+
g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, mouse_delta.y < 0.0f ? -mouse_delta.y : mouse_delta.y);
1691+
g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(mouse_delta));
16781692
}
16791693
}
1680-
memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
1681-
for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
1682-
g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
16831694

16841695
// Calculate frame-rate for the user, as a purely luxurious feature
16851696
g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
@@ -1689,11 +1700,12 @@ void ImImpl_NewFramePaused() {
16891700

16901701
g.IO.WantCaptureKeyboard = g.IO.WantCaptureMouse = g.IO.WantTextInput = false;
16911702

1692-
// New:
16931703
g.IO.WantTextInput = 0;
16941704
g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1;
16951705

1696-
1706+
// New
1707+
g.MovingWindow = NULL;
1708+
g.MovingWindowMoveId = 0;
16971709
}
16981710

16991711

addons/imguipanelmanager/imguipanelmanager.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,13 @@ static bool DockWindowBegin(const char* name, bool* p_opened,bool* p_undocked, c
415415
if (!(flags & ImGuiWindowFlags_NoSavedSettings))
416416
MarkIniSettingsDirty(window);
417417
}
418-
IM_ASSERT(g.MovedWindow != NULL);
419-
FocusWindow(g.MovedWindow);
418+
IM_ASSERT(g.MovingWindow != NULL);
419+
FocusWindow(g.MovingWindow);
420420
}
421421
else
422422
{
423423
ClearActiveID();
424-
g.MovedWindow = NULL; // Not strictly necessary but doing it for sanity.
424+
g.MovingWindow = NULL; // Not strictly necessary but doing it for sanity.
425425
}
426426
}
427427

@@ -703,22 +703,6 @@ static bool DockWindowBegin(const char* name, bool* p_opened,bool* p_undocked, c
703703
if (!(flags & ImGuiWindowFlags_NoCollapse))
704704
RenderTriangle(window->Pos + style.FramePadding, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f);
705705

706-
707-
/*
708-
ImVec2 text_min = window->Pos + style.FramePadding;
709-
//ImVec2 text_max = window->Pos + ImVec2(window->Size.x - style.FramePadding.x, style.FramePadding.y*2 + text_size.y);
710-
//ImVec2 clip_max = ImVec2(window->Pos.x + window->Size.x - (p_opened ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton()
711-
ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_rect.GetHeight()-3) : style.FramePadding.x) - (p_undocked ? (title_bar_rect.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y*2 + text_size.y);
712-
ImVec2 clip_max = ImVec2(window->Pos.x + window->Size.x - (p_opened ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x) - (p_undocked ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton()
713-
714-
bool pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0;
715-
bool pad_right = (p_opened != NULL);
716-
if (style.WindowTitleAlign & ImGuiAlign_Center) pad_right = pad_left;
717-
if (pad_left) text_min.x += g.FontSize + style.ItemInnerSpacing.x;
718-
if (pad_right) text_max.x -= g.FontSize + style.ItemInnerSpacing.x;
719-
RenderTextClipped(text_min, text_max, name, NULL, &text_size, style.WindowTitleAlign, NULL, &clip_max);
720-
*/
721-
722706
ImVec2 text_min = window->Pos;
723707
ImVec2 text_max = window->Pos + ImVec2(window->Size.x, style.FramePadding.y*2 + text_size.y);
724708
ImRect clip_rect;
@@ -747,25 +731,34 @@ static bool DockWindowBegin(const char* name, bool* p_opened,bool* p_undocked, c
747731
if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C))
748732
ImGui::LogToClipboard();
749733
*/
734+
735+
// Inner rectangle
736+
// We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
737+
// Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior.
738+
window->InnerRect.Min.x = title_bar_rect.Min.x;
739+
window->InnerRect.Min.y = title_bar_rect.Max.y + window->MenuBarHeight();
740+
window->InnerRect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x;
741+
window->InnerRect.Max.y = window->Pos.y + window->Size.y - window->ScrollbarSizes.y;
742+
//window->DrawList->AddRect(window->InnerRect.Min, window->InnerRect.Max, IM_COL32_WHITE);
743+
750744
}
751745

752746
// Inner clipping rectangle
753-
// We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
754-
// Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior.
755-
const ImRect title_bar_rect = window->TitleBarRect();
747+
// Force round operator last to ensure that e.g. (int)(max.x-min.x) in user's render code produce correct result.
756748
const float border_size = ((flags & ImGuiWindowFlags_ShowBorders) || gImGuiDockPanelManagerAlwaysDrawExternalBorders) ? 1.0f : 0.0f;
757749
ImRect clip_rect;
758-
clip_rect.Min.x = title_bar_rect.Min.x + 0.5f + ImMax(border_size, window->WindowPadding.x*0.5f);
759-
clip_rect.Min.y = title_bar_rect.Max.y + window->MenuBarHeight() + 0.5f + border_size;
760-
clip_rect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x - ImMax(border_size, window->WindowPadding.x*0.5f);
761-
clip_rect.Max.y = window->Pos.y + window->Size.y - border_size - window->ScrollbarSizes.y;
762-
750+
clip_rect.Min.x = ImFloor(0.5f + window->InnerRect.Min.x + ImMax(border_size, ImFloor(window->WindowPadding.x*0.5f)));
751+
clip_rect.Min.y = ImFloor(0.5f + window->InnerRect.Min.y + border_size);
752+
clip_rect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(border_size, ImFloor(window->WindowPadding.x*0.5f)));
753+
clip_rect.Max.y = ImFloor(0.5f + window->InnerRect.Max.y - border_size);
763754
PushClipRect(clip_rect.Min, clip_rect.Max, true);
764755

765756
// Clear 'accessed' flag last thing
766757
if (first_begin_of_the_frame)
767758
window->Accessed = false;
759+
768760
window->BeginCount++;
761+
g.SetNextWindowSizeConstraint = false;
769762

770763
// Child window can be out of sight and have "negative" clip windows.
771764
// Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).

addons/imguistyleserializer/imguistyleserializer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ bool ResetStyle(int styleEnum,ImGuiStyle& style) {
369369
if (styleEnum<0 || styleEnum>=ImGuiStyle_Count) return false;
370370
style = ImGuiStyle();
371371
switch (styleEnum) {
372+
case ImGuiStyle_DefaultDark:
373+
ImGui::StyleColorsDark(&style);
374+
break;
372375
case ImGuiStyle_DefaultInverse:
373376
InvertStyleColors(style);
374377
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.79f, 0.76f, 0.725f, 0.875f);
@@ -928,7 +931,7 @@ bool ResetStyle(int styleEnum,ImGuiStyle& style) {
928931

929932
return true;
930933
}
931-
static const char* DefaultStyleNames[ImGuiStyle_Count]={"Default","Gray","Light","OSX","OSXOpaque","DarkOpaque","Soft","EdinBlack","EdinWhite","Maya","DefaultInverse","OSXInverse","OSXOpaqueInverse","DarkOpaqueInverse"};
934+
static const char* DefaultStyleNames[ImGuiStyle_Count]={"Default","DefaultDark","Gray","Light","OSX","OSXOpaque","DarkOpaque","Soft","EdinBlack","EdinWhite","Maya","DefaultInverse","OSXInverse","OSXOpaqueInverse","DarkOpaqueInverse"};
932935
const char** GetDefaultStyleNames() {return &DefaultStyleNames[0];}
933936

934937
} // namespace ImGui

addons/imguistyleserializer/imguistyleserializer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
enum ImGuiStyleEnum {
99
ImGuiStyle_Default=0,
10+
ImGuiStyle_DefaultDark,
1011
ImGuiStyle_Gray, // This is the default theme of my main.cpp demo.
1112
ImGuiStyle_Light,
1213
ImGuiStyle_OSX, // Posted by @itamago here: https://github.com/ocornut/imgui/pull/511 (hope I can use it)

addons/imguivariouscontrols/imguivariouscontrols.cpp

Lines changed: 153 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,10 +3953,9 @@ bool PasswordDrawer(char *password, int passwordSize,ImGuiPasswordDrawerFlags fl
39533953
unsigned int CheckboxFlags(const char* label,unsigned int* flags,int numFlags,int numRows,int numColumns,unsigned int flagAnnotations,int* itemHoveredOut,const unsigned int* pFlagsValues)
39543954
{
39553955
unsigned int itemPressed = 0;
3956-
if (itemHoveredOut) *itemHoveredOut=0;
3956+
if (itemHoveredOut) *itemHoveredOut=-1;
39573957
if (numRows*numColumns*numFlags==0) return itemPressed;
39583958

3959-
39603959
ImGuiWindow* window = GetCurrentWindow();
39613960
if (window->SkipItems) return itemPressed;
39623961

@@ -3968,7 +3967,6 @@ unsigned int CheckboxFlags(const char* label,unsigned int* flags,int numFlags,in
39683967
int numItemsPerGroup = numItemsPerRow/numColumns;if (numItemsPerRow%numColumns) ++numItemsPerGroup;
39693968
numItemsPerRow = numItemsPerGroup * numColumns;
39703969

3971-
39723970
ImGui::BeginGroup();
39733971
const ImVec2 startCurPos = window->DC.CursorPos;
39743972
ImVec2 curPos = startCurPos, maxPos = startCurPos;
@@ -4005,6 +4003,7 @@ unsigned int CheckboxFlags(const char* label,unsigned int* flags,int numFlags,in
40054003
hovered = ItemHoverable(bb, itemID);pressed = buttonPressed && hovered; // Way faster
40064004
if (pressed) {
40074005
v = !v;
4006+
if (!ImGui::GetIO().KeyShift) *flags=0;
40084007
if (v) *flags |= j;
40094008
else *flags &= ~j;
40104009
itemPressed = j;
@@ -4056,12 +4055,161 @@ unsigned int CheckboxFlags(const char* label,unsigned int* flags,int numFlags,in
40564055
ImGuiID itemID = window->GetID(label);
40574056
ItemSize(text_bb, style.FramePadding.y*numRows);
40584057
if (ItemAdd(text_bb, itemID)) RenderText(text_bb.Min, label);
4059-
4060-
40614058
}
40624059

40634060
return itemPressed;
40644061
}
40654062
// End CheckboxFlags =================================================================================================
40664063

4064+
// Start CheckBoxStyled ==============================================================================================
4065+
bool CheckboxStyled(const char* label, bool* v)
4066+
{
4067+
ImGuiWindow* window = GetCurrentWindow();
4068+
if (window->SkipItems)
4069+
return false;
4070+
4071+
ImGuiContext& g = *GImGui;
4072+
const ImGuiStyle& style = g.Style;
4073+
const ImGuiID id = window->GetID(label);
4074+
const ImVec2 label_size = CalcTextSize(label, NULL, true);
4075+
const ImVec2 check_size(label_size.y*2.5f,label_size.y);
4076+
4077+
const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(check_size.x + style.FramePadding.x*2, check_size.y + style.FramePadding.y*2)); // We want a square shape to we use Y twice
4078+
ItemSize(check_bb, style.FramePadding.y);
4079+
4080+
ImRect total_bb = check_bb;
4081+
if (label_size.x > 0) SameLine(0, style.ItemInnerSpacing.x);
4082+
const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
4083+
if (label_size.x > 0)
4084+
{
4085+
ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
4086+
total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
4087+
}
4088+
4089+
if (!ItemAdd(total_bb, id))
4090+
return false;
4091+
4092+
bool hovered, held;
4093+
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
4094+
static float timeBegin = -1.f;
4095+
static ImGuiID timeID = 0;
4096+
if (pressed) {
4097+
*v = !(*v);
4098+
timeID = id;
4099+
timeBegin = ImGui::GetTime();
4100+
}
4101+
4102+
// Widget Look Here ================================================================
4103+
float t = 0.f; // In (0,1) 0 = OFF 1 = ON
4104+
if (timeID==id) {
4105+
const float actionTime = 0.25f;
4106+
float elapsedTime = ImGui::GetTime()-timeBegin;
4107+
if (elapsedTime>actionTime) {timeBegin=-1;timeID=0;}
4108+
else t = 1.f-elapsedTime/actionTime;
4109+
}
4110+
if (*v) t = 1.f-t;
4111+
if (t<0) t=0;
4112+
else if (t>1) t=1;
4113+
const float check_bb_height = check_bb.GetHeight();
4114+
const float innerFrameHeight = check_bb_height*0.5f;
4115+
const float heightDelta = (check_bb_height-innerFrameHeight)*0.5f;
4116+
const float check_bb_width = check_bb.GetWidth();
4117+
float widthFraction = check_bb_width*t;
4118+
ImU32 baseColor = GetColorU32((held || hovered) ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
4119+
const float rounding = style.WindowRounding;//style.FrameRounding;
4120+
ImRect innerFrame0(ImVec2(check_bb.Min.x,check_bb.Min.y+heightDelta),ImVec2(check_bb.Min.x+widthFraction,check_bb.Max.y-heightDelta));
4121+
ImRect innerFrame1(ImVec2(check_bb.Min.x+widthFraction,check_bb.Min.y+heightDelta),ImVec2(check_bb.Max.x,check_bb.Max.y-heightDelta));
4122+
if (t>0) {
4123+
ImU32 fillColor0 = GetColorU32((held || hovered) ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
4124+
window->DrawList->AddRectFilled(innerFrame0.Min, innerFrame0.Max, fillColor0, rounding, t<1 ? 9 : 15);
4125+
}
4126+
if (t<1) {
4127+
ImU32 fillColor1 = baseColor;//GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
4128+
window->DrawList->AddRectFilled(innerFrame1.Min, innerFrame1.Max, fillColor1, rounding, t>0 ? 6 : 15);
4129+
}
4130+
if (window->Flags & ImGuiWindowFlags_ShowBorders) {
4131+
ImRect innerFrame(innerFrame0.Min,innerFrame1.Max);
4132+
window->DrawList->AddRect(innerFrame.Min+ImVec2(1,1), innerFrame.Max+ImVec2(1,1), GetColorU32(ImGuiCol_BorderShadow), rounding);
4133+
window->DrawList->AddRect(innerFrame.Min, innerFrame.Max, GetColorU32(ImGuiCol_Border), rounding);
4134+
}
4135+
// Ideally we need an opaque color here:
4136+
ImU32 circleColor = GetColorU32((held || hovered) ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
4137+
// GetColorU32(ImGuiCol_CheckMark);
4138+
int numSegments = (int)(check_bb_height*0.8f);if (numSegments<3) numSegments=3;else if (numSegments>24) numSegments = 24;
4139+
float radius = check_bb_height*0.5f;
4140+
if (widthFraction<radius) widthFraction=radius;
4141+
else if (widthFraction>check_bb_width-radius) widthFraction=check_bb_width-radius;
4142+
ImVec2 center(check_bb.Min.x+widthFraction,check_bb.Min.y+check_bb_height*0.5f);
4143+
window->DrawList->AddCircleFilled(center,radius,circleColor,numSegments);
4144+
// ==================================================================================
4145+
4146+
//if (g.LogEnabled) LogRenderedText(&text_bb.Min, *v ? "[x]" : "[ ]");
4147+
if (label_size.x > 0.0f) RenderText(text_bb.Min, label);
4148+
4149+
return pressed;
4150+
}
4151+
bool CheckboxStyledFlags(const char* label, unsigned int* flags, unsigned int flags_value) {
4152+
bool v = ((*flags & flags_value) == flags_value);
4153+
bool pressed = CheckboxStyled(label, &v);
4154+
if (pressed) {
4155+
if (v) *flags |= flags_value;
4156+
else *flags &= ~flags_value;
4157+
}
4158+
return pressed;
4159+
}
4160+
// End CheckBoxStyled ================================================================================================
4161+
4162+
// KnobFloat Starts Here =============================================================================================
4163+
bool KnobFloat(const char* label, float* p_value, float v_min, float v_max,float v_step) {
4164+
//@ocornut https://github.com/ocornut/imgui/issues/942
4165+
ImGuiIO& io = ImGui::GetIO();
4166+
ImGuiStyle& style = ImGui::GetStyle();
4167+
4168+
float radius_outer = 20.0f;
4169+
ImVec2 pos = ImGui::GetCursorScreenPos();
4170+
ImVec2 center = ImVec2(pos.x + radius_outer, pos.y + radius_outer);
4171+
float line_height = ImGui::GetTextLineHeight();
4172+
ImDrawList* draw_list = ImGui::GetWindowDrawList();
4173+
4174+
float ANGLE_MIN = 3.141592f * 0.75f;
4175+
float ANGLE_MAX = 3.141592f * 2.25f;
4176+
4177+
ImGui::InvisibleButton(label, ImVec2(radius_outer*2, radius_outer*2 + line_height + style.ItemInnerSpacing.y));
4178+
bool value_changed = false;
4179+
bool is_active = ImGui::IsItemActive();
4180+
bool is_hovered = ImGui::IsItemHovered();
4181+
if (is_active && io.MouseDelta.x != 0.0f) {
4182+
if (v_step<=0) v_step=50.f;
4183+
float step = (v_max - v_min) / v_step;
4184+
*p_value += io.MouseDelta.x * step;
4185+
4186+
if (*p_value < v_min) *p_value = v_min;
4187+
if (*p_value > v_max) *p_value = v_max;
4188+
value_changed = true;
4189+
}
4190+
else if (is_hovered && (io.MouseDoubleClicked[0] || io.MouseClicked[2])) {
4191+
*p_value = (v_max + v_min) * 0.5f; // reset value
4192+
value_changed = true;
4193+
}
4194+
4195+
float t = (*p_value - v_min) / (v_max - v_min);
4196+
float angle = ANGLE_MIN + (ANGLE_MAX - ANGLE_MIN) * t;
4197+
float angle_cos = cosf(angle), angle_sin = sinf(angle);
4198+
float radius_inner = radius_outer*0.40f;
4199+
draw_list->AddCircleFilled(center, radius_outer, ImGui::GetColorU32(ImGuiCol_FrameBg), 16);
4200+
draw_list->AddLine(ImVec2(center.x + angle_cos*radius_inner, center.y + angle_sin*radius_inner), ImVec2(center.x + angle_cos*(radius_outer-2), center.y + angle_sin*(radius_outer-2)), ImGui::GetColorU32(ImGuiCol_SliderGrabActive), 2.0f);
4201+
draw_list->AddCircleFilled(center, radius_inner, ImGui::GetColorU32(is_active ? ImGuiCol_FrameBgActive : is_hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
4202+
draw_list->AddText(ImVec2(pos.x, pos.y + radius_outer * 2 + style.ItemInnerSpacing.y), ImGui::GetColorU32(ImGuiCol_Text), label);
4203+
4204+
if (is_active || is_hovered) {
4205+
ImGui::SetNextWindowPos(ImVec2(pos.x - style.WindowPadding.x, pos.y - line_height - style.ItemInnerSpacing.y - style.WindowPadding.y));
4206+
ImGui::BeginTooltip();
4207+
ImGui::Text("%.3f", *p_value);
4208+
ImGui::EndTooltip();
4209+
}
4210+
4211+
return value_changed;
4212+
}
4213+
// ===================================================================================================================
4214+
40674215
} // namespace ImGui

0 commit comments

Comments
 (0)