Advertisement
Anti-hide

Красивые чекбоксы для индиго

Oct 29th, 2017
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. заходим в imgui.cpp, идем на 7285 строку, заменяем
  2. https://i.imgur.com/AoRFRTt.png
  3.  
  4. на
  5. bool ImGui::Checkbox(const char* label, bool* v)
  6. {
  7.     ImGuiWindow* window = GetCurrentWindow();
  8.  
  9.     if (window->SkipItems)
  10.         return false;
  11.  
  12.     ImGuiContext& g = *GImGui;
  13.     const ImGuiStyle& style = ImGuiStyle::ImGuiStyle();
  14.     const ImGuiID id = window->GetID(label);
  15.     const ImVec2 label_size = CalcTextSize(label, NULL, true);
  16.     const ImVec2 pading = ImVec2(2, 2);
  17.  
  18.     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));
  19.     ItemSize(check_bb, style.FramePadding.y);
  20.  
  21.     ImRect total_bb = check_bb;
  22.     if (label_size.x > 0)
  23.         SameLine(0, style.ItemInnerSpacing.x);
  24.  
  25.     const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
  26.  
  27.     if (label_size.x > 0)
  28.     {
  29.         ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  30.         total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  31.     }
  32.  
  33.     if (!ItemAdd(total_bb, &id))
  34.         return false;
  35.  
  36.     bool hovered, held;
  37.     bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
  38.  
  39.     if (pressed)
  40.         *v = !(*v);
  41.  
  42.     const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  43.     const float check_sz2 = check_sz / 2;
  44.     const float pad = ImMax(1.0f, (float)(int)(check_sz / 4.f));
  45.     RenderFrame(check_bb.Min, check_bb.Max, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
  46.  
  47.     //window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), GetColorU32(ImGuiCol_CheckMark), style.FrameRounding);
  48.     if (*v)//отрисовка галочки
  49.     {
  50.         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(ImGuiCol_CheckMark), 0);
  51.         window->DrawList->AddRect(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32(ImGuiCol_Border), 0, -1, 2);
  52.     }
  53.     else
  54.     {
  55.         //window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x, check_bb.Min.y), ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Max.y), GetColorU32(ImGuiCol_FrameBgHovered), 0);
  56.         window->DrawList->AddRect(ImVec2(check_bb.Min.x, check_bb.Min.y), ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Max.y), GetColorU32(ImGuiCol_Border), 0);
  57.     }
  58.  
  59.     if (label_size.x > 0.0f)
  60.         RenderText(text_bb.GetTL(), label);
  61.  
  62.     return pressed;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement