mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
imgui: Add igToggleButton function
This commit is contained in:
parent
f843c59c37
commit
82ea385c6d
|
@ -20,6 +20,8 @@ void igPlotTimings(const char *label,
|
||||||
bool center_reference_timing, float range, const char *unit,
|
bool center_reference_timing, float range, const char *unit,
|
||||||
bool dynamic_rescale);
|
bool dynamic_rescale);
|
||||||
|
|
||||||
|
void igToggleButton(const char *str_id, bool *v);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
40
src/external/imgui/imgui_monado/imgui_monado.cpp
vendored
40
src/external/imgui/imgui_monado/imgui_monado.cpp
vendored
|
@ -235,3 +235,43 @@ void igPlotTimings(const char *label,
|
||||||
center_reference_timing, range, unit, dynamic_rescale);
|
center_reference_timing, range, unit, dynamic_rescale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
void igToggleButton(const char *str_id, bool *v) {
|
||||||
|
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
|
ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
float height = ImGui::GetFrameHeight();
|
||||||
|
float width = height * 1.55f;
|
||||||
|
float radius = height * 0.50f;
|
||||||
|
|
||||||
|
ImGui::InvisibleButton(str_id, ImVec2(width, height));
|
||||||
|
if (ImGui::IsItemClicked())
|
||||||
|
*v = !*v;
|
||||||
|
|
||||||
|
float t = *v ? 1.0f : 0.0f;
|
||||||
|
|
||||||
|
ImGuiContext &g = *GImGui;
|
||||||
|
float ANIM_SPEED = 0.08f;
|
||||||
|
if (g.LastActiveId ==
|
||||||
|
g.CurrentWindow->GetID(str_id)) // && g.LastActiveIdTimer < ANIM_SPEED)
|
||||||
|
{
|
||||||
|
float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED);
|
||||||
|
t = *v ? (t_anim) : (1.0f - t_anim);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImU32 col_bg;
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.78f, 0.78f, 0.78f, 1.0f),
|
||||||
|
ImVec4(0.64f, 0.83f, 0.34f, 1.0f), t));
|
||||||
|
else
|
||||||
|
col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.85f, 0.85f, 0.85f, 1.0f),
|
||||||
|
ImVec4(0.56f, 0.83f, 0.26f, 1.0f), t));
|
||||||
|
|
||||||
|
draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg,
|
||||||
|
height * 0.5f);
|
||||||
|
draw_list->AddCircleFilled(
|
||||||
|
ImVec2(p.x + radius + t * (width - radius * 2.0f), p.y + radius),
|
||||||
|
radius - 1.5f, IM_COL32(255, 255, 255, 255));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue