| 4 | #include "switch.h" |
| 5 | |
| 6 | void ToggleButton(const char* str_id, int* v) |
| 7 | { |
| 8 | ImVec2 p = ImGui::GetCursorScreenPos(); |
| 9 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 10 | |
| 11 | float height = ImGui::GetFrameHeight() * 0.75f; |
| 12 | float width = height * 2.0f; |
| 13 | |
| 14 | ImGui::InvisibleButton(str_id, ImVec2(width, height)); |
| 15 | if (ImGui::IsItemClicked()) |
| 16 | *v = !*v; |
| 17 | |
| 18 | float t = *v ? 1.0f : 0.0f; |
| 19 | |
| 20 | ImGuiContext& g = *GImGui; |
| 21 | float ANIM_SPEED = 0.04f; |
| 22 | if (g.LastActiveId == g.CurrentWindow->GetID(str_id))// && g.LastActiveIdTimer < ANIM_SPEED) |
| 23 | { |
| 24 | float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED); |
| 25 | t = *v ? (t_anim) : (1.0f - t_anim); |
| 26 | } |
| 27 | int off = 2; |
| 28 | |
| 29 | draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_FrameBg]), 2); |
| 30 | draw_list->AddRectFilled(ImVec2(p.x + t * height + off, p.y + off), ImVec2(p.x + (t + 1) * height - off, p.y + height - off), |
| 31 | ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_SliderGrab]), 2); |
| 32 | } |
| 33 | |
| 34 | void FancySlider(const char * str_id, const char * label, float* v, int width){ |
| 35 | ImGui::BeginGroup(); |
no test coverage detected