Эксперт
-
Автор темы
- #1
Код:
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = ImGuiStyle::ImGuiStyle();
const float square_sz = GetFrameHeight();
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImVec2 pading = ImVec2(2, 2);
const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.x * 6, label_size.y + style.FramePadding.y / 2));
ItemSize(check_bb, style.FramePadding.y);
ImRect total_bb = check_bb;
if (label_size.x > 0)
SameLine(0, style.ItemInnerSpacing.x);
const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
if (label_size.x > 0)
{
ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
}
if (!ItemAdd(total_bb, id))
return false;
bool hovered, held;
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
if (pressed)
*v = !(*v);
const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
const float check_sz2 = check_sz / 2;
const float pad = ImMax(1.0f, (float)(int)(check_sz / 4.f));
//window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), GetColorU32(ImGuiCol_CheckMark), style.FrameRounding);
if (*v)
{
//window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32(ImVec4(0.34f, 1.0f, 0.54f, 1.0f)), 0);
//window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32(ImVec4(0.34f, 1.0f, 0.54f, 1.0f)), 0);
window->DrawList->AddCircle(ImVec2(check_bb.Min.x + 8, check_bb.Min.y + 10), 8, ImColor(10, 255, 0), 24);
window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 11, check_bb.Min.y + 4), ImVec2(check_bb.Min.x + 19, check_bb.Min.y + 9), ImColor(45, 48, 56));
RenderCheckMark(window->DrawList, check_bb.Min + ImVec2(pad, 0), ImColor(10, 255, 0), square_sz - pad * 2.0f);
}
else
{
window->DrawList->AddCircle(ImVec2(check_bb.Min.x + 8, check_bb.Min.y + 10), 8, ImColor(255, 255, 255), 24);
}
if (label_size.x > 0.0f)
RenderText(ImVec2(check_bb.Min.x + 24, check_bb.Min.y), label);
return pressed;