sandbox.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include <algorithm>
  2. #include <cstddef>
  3. #include <cstring>
  4. #include <fmt/format.h>
  5. #include <iterator>
  6. #include <memory>
  7. #include <span>
  8. #include <sstream>
  9. #include <string>
  10. #include <vector>
  11. #include "saura/core/base/types.hpp"
  12. #include "saura/core/memory/arena.hpp"
  13. #include <saura/core/app_base/app_base.hpp>
  14. #include <saura/core/os/os.hpp>
  15. #include <imgui.h>
  16. #include <imgui_internal.h>
  17. #include <spdlog/spdlog.h>
  18. namespace saura {
  19. struct SandboxApp : AppBase {
  20. std::unique_ptr<MemoryArena> def_mem_arena;
  21. std::unique_ptr<MemoryArenaTemp> mem_arena_temp;
  22. void start() override {
  23. spdlog::info("Sandbox start!");
  24. spdlog::info("DPI scale: {}", os_ctx->get_dpi_scale());
  25. this->def_mem_arena = std::make_unique<MemoryArena>();
  26. this->mem_arena_temp = std::make_unique<MemoryArenaTemp>();
  27. }
  28. void update(double dt) override {}
  29. void draw() override {
  30. ImGui::SetNextWindowPos({0.0f, 0.0f});
  31. ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
  32. ImGui::Begin("Demo", 0,
  33. ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
  34. ImGuiWindowFlags_NoFocusOnAppearing |
  35. ImGuiWindowFlags_NoSavedSettings);
  36. ImGuiTableFlags flags =
  37. ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
  38. ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_ScrollY;
  39. ImGui::Text("Маркировка товаров");
  40. // ===== Layout =====
  41. struct FormLayout {
  42. float label_w;
  43. float field_w;
  44. };
  45. FormLayout layout{
  46. .label_w = 130.0f,
  47. .field_w = 260.0f,
  48. };
  49. // ===== Helpers =====
  50. auto form_row = [&](const char *label, auto draw_field) {
  51. ImGui::TextUnformatted(label);
  52. ImGui::SameLine();
  53. ImGui::SetCursorPosX(layout.label_w);
  54. ImGui::SetNextItemWidth(layout.field_w);
  55. draw_field();
  56. };
  57. // ===== Sizes =====
  58. float row_h = ImGui::GetFrameHeightWithSpacing();
  59. float top_height = row_h * 6.0f;
  60. // ===== Top Left =====
  61. ImGui::BeginChild("TopLeft", ImVec2(400, top_height), true);
  62. {
  63. form_row("Организация:", [&] {
  64. if (ImGui::BeginCombo("##org", "Фламинго ООО"))
  65. ImGui::EndCombo();
  66. });
  67. form_row("Продукция:", [&] {
  68. if (ImGui::BeginCombo("##prod", "Basic Premium - M 30 шт/уп"))
  69. ImGui::EndCombo();
  70. });
  71. form_row("Серия:", [&] {
  72. if (ImGui::BeginCombo("##series", "53698677 до 11.01.31"))
  73. ImGui::EndCombo();
  74. });
  75. static char series_num[128] = "A-08";
  76. form_row("Номер серии:", [&] {
  77. ImGui::InputText("##series_num", series_num, sizeof(series_num));
  78. });
  79. static char batch_num[128] = "A-08";
  80. form_row("Номер партии:", [&] {
  81. ImGui::InputText("##batch_num", batch_num, sizeof(batch_num));
  82. });
  83. }
  84. ImGui::EndChild();
  85. // ===== Top Right =====
  86. ImGui::SameLine();
  87. ImGui::BeginChild("TopRight", ImVec2(0, top_height), true);
  88. {
  89. static int box_count = 4;
  90. form_row("Кол-во в коробке:",
  91. [&] { ImGui::InputInt("##box", &box_count); });
  92. static int pallet_count = 18;
  93. form_row("Кол-во в паллете:",
  94. [&] { ImGui::InputInt("##pallet", &pallet_count); });
  95. static char prod_date[64] = "11.01.2026";
  96. form_row("Дата произв.:", [&] {
  97. ImGui::InputText("##prod_date", prod_date, sizeof(prod_date));
  98. });
  99. static char exp_date[64] = "11.01.2031";
  100. form_row("Срок годн.:", [&] {
  101. ImGui::InputText("##exp_date", exp_date, sizeof(exp_date));
  102. });
  103. }
  104. ImGui::EndChild();
  105. if (ImGui::BeginTabBar("Tabs")) {
  106. if (ImGui::BeginTabItem("Сканирование")) {
  107. if (ImGui::BeginTable("DataTable", 2, flags)) {
  108. ImGui::TableSetupColumn("#");
  109. ImGui::TableSetupColumn("Упаковка");
  110. ImGui::TableHeadersRow();
  111. int32_t selected_row_idx = -1;
  112. for (size_t idx = 0; idx < 3; idx++) {
  113. ImGui::TableNextRow();
  114. ImGui::TableNextColumn();
  115. ImGui::Text("%03d", (int)idx + 1);
  116. ImGui::TableNextColumn();
  117. ImGui::Text(
  118. "0104650098830926215Roc(yep49_q291EE1192NB7hBGPH9j2lRWm57z2+"
  119. "YygvLInYURU8/6I/luU1Xj0=");
  120. }
  121. ImGui::EndTable();
  122. }
  123. ImGui::EndTabItem();
  124. }
  125. if (ImGui::BeginTabItem("Упаковки")) {
  126. ImGui::EndTabItem();
  127. }
  128. if (ImGui::BeginTabItem("Коробки")) {
  129. ImGui::EndTabItem();
  130. }
  131. if (ImGui::BeginTabItem("Паллеты")) {
  132. ImGui::EndTabItem();
  133. }
  134. ImGui::EndTabBar();
  135. }
  136. ImGui::End();
  137. // ImGui::ShowDemoWindow();
  138. }
  139. void stop() override { spdlog::info("Sandbox stop!"); }
  140. };
  141. } // namespace saura
  142. int main() {
  143. auto app = std::make_unique<saura::SandboxApp>();
  144. app->run();
  145. return 0;
  146. }