MCPcopy Create free account
hub / github.com/SatDump/SatDump / ToggleButton

Function ToggleButton

src-core/common/widgets/switch.cpp:6–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "switch.h"
5
6void 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
34void FancySlider(const char * str_id, const char * label, float* v, int width){
35 ImGui::BeginGroup();

Callers 2

drawProjectionPanelMethod · 0.85
drawMenuMethod · 0.85

Calls 4

ImVec2Function · 0.85
ImSaturateFunction · 0.85
GetIDMethod · 0.80
AddRectFilledMethod · 0.80

Tested by

no test coverage detected