item_views.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*******************************************************************************************
  2. *
  3. * raylib-extras [ImGui] example - asset browser
  4. *
  5. * This is a more complex ImGui Integration
  6. * It shows how to build windows on top of 2d and 3d views using a render texture
  7. *
  8. * Copyright (c) 2024 Jeffery Myers
  9. *
  10. ********************************************************************************************/
  11. #include "item_view.h"
  12. #include "imgui.h"
  13. #include "imgui_utils.h"
  14. #include "rlImGuiColors.h"
  15. #include "raylib.h"
  16. extern ImFont* IconFont;
  17. ViewableItem* ListItemView::Show(ViewableItemContainer& container)
  18. {
  19. ViewableItem* item = container.Reset();
  20. ViewableItem* selected = nullptr;
  21. while (item)
  22. {
  23. float x = ImGui::GetCursorPosX();
  24. const char* name = TextFormat("###%s", item->Name.c_str());
  25. if (item->Tint.a > 0)
  26. ImGui::TextColored(rlImGuiColors::Convert(item->Tint), " %s", item->Icon.c_str());
  27. else
  28. ImGui::Text(" %s", item->Icon.c_str());
  29. ImGui::SameLine(0, 0);
  30. ImGui::Text(" %s", item->Name.c_str());
  31. ImGui::SameLine(0, 0);
  32. ImGui::SetCursorPosX(x);
  33. //ImGui::SetItemAllowOverlap();
  34. ImGui::Selectable(name);
  35. if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0))
  36. {
  37. selected = item;
  38. }
  39. item = container.Next();
  40. }
  41. return selected;
  42. }