MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / _Draw_Impl

Method _Draw_Impl

Sources/OvUI/src/OvUI/Widgets/Buttons/Toggle.cpp:15–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13{}
14
15void OvUI::Widgets::Buttons::Toggle::_Draw_Impl()
16{
17 const float rounding = ImGui::GetStyle().FrameRounding;
18 const float padX = ImGui::GetStyle().FramePadding.x;
19 const float padY = ImGui::GetStyle().FramePadding.y;
20 const float height = ImGui::GetFrameHeight();
21 const float widthA = ImGui::CalcTextSize(labelA.c_str()).x + padX * 2.0f;
22 const float widthB = ImGui::CalcTextSize(labelB.c_str()).x + padX * 2.0f;
23 constexpr float kSep = 1.0f;
24
25 const ImVec2 origin = ImGui::GetCursorScreenPos();
26 const ImVec2 posB = { origin.x + widthA + kSep, origin.y };
27
28 // Single interaction area covering the entire pill
29 const bool clicked = ImGui::InvisibleButton(m_widgetID.c_str(), { widthA + kSep + widthB, height });
30 const bool hovered = ImGui::IsItemHovered();
31 const bool pressed = ImGui::IsItemActive();
32
33 auto pickColor = [&](bool isActive) -> ImU32 {
34 const Types::ColorEffector& effector = pressed ? (isActive ? activePressedColor : inactivePressedColor)
35 : hovered ? (isActive ? activeHoveredColor : inactiveHoveredColor)
36 : (isActive ? activeColor : inactiveColor);
37 const Types::Color c = effector.Resolve();
38 return ImGui::ColorConvertFloat4ToU32({ c.r, c.g, c.b, c.a });
39 };
40
41 ImDrawList* dl = ImGui::GetWindowDrawList();
42
43 // Left half — rounded left corners only
44 dl->AddRectFilled(
45 origin,
46 { origin.x + widthA, origin.y + height },
47 pickColor(!state),
48 rounding,
49 ImDrawFlags_RoundCornersLeft);
50
51 // Right half — rounded right corners only
52 dl->AddRectFilled(
53 posB,
54 { posB.x + widthB, posB.y + height },
55 pickColor(state),
56 rounding,
57 ImDrawFlags_RoundCornersRight);
58
59 const ImU32 textColor = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]);
60 dl->AddText({ origin.x + padX, origin.y + padY }, textColor, labelA.c_str());
61 dl->AddText({ posB.x + padX, posB.y + padY }, textColor, labelB.c_str());
62
63 if (clicked)
64 {
65 state = !state;
66 StateChangedEvent.Invoke(state);
67 }
68}

Callers

nothing calls this directly

Calls 4

c_strMethod · 0.80
ResolveMethod · 0.80
AddRectFilledMethod · 0.80
AddTextMethod · 0.80

Tested by

no test coverage detected