Add table handling functions: implement AddTableColumn and DrawTable for improved GUI layout
This commit is contained in:
@@ -6,14 +6,9 @@
|
|||||||
|
|
||||||
#include "ImGuiFileDialog/ImGuiFileDialog.h"
|
#include "ImGuiFileDialog/ImGuiFileDialog.h"
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "app/gfx/bitmap.h"
|
|
||||||
#include "app/gfx/snes_palette.h"
|
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "app/gui/canvas.h"
|
|
||||||
#include "app/gui/color.h"
|
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/imgui_internal.h"
|
#include "imgui/imgui_internal.h"
|
||||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
|
||||||
|
|
||||||
namespace ImGui {
|
namespace ImGui {
|
||||||
|
|
||||||
@@ -279,7 +274,30 @@ void FileDialogPipeline(absl::string_view display_key,
|
|||||||
ImGuiFileDialog::Instance()->Close();
|
ImGuiFileDialog::Instance()->Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void AddTableColumn(Table &table, const std::string &label, GuiElement element) {
|
||||||
|
table.column_labels.push_back(label);
|
||||||
|
table.column_contents.push_back(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawTable(Table& params) {
|
||||||
|
if (ImGui::BeginTable(params.id, params.num_columns, params.flags, params.size)) {
|
||||||
|
for (int i = 0; i < params.num_columns; ++i)
|
||||||
|
ImGui::TableSetupColumn(params.column_labels[i].c_str());
|
||||||
|
|
||||||
|
for (int i = 0; i < params.num_columns; ++i) {
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
switch (params.column_contents[i].index()) {
|
||||||
|
case 0:
|
||||||
|
std::get<0>(params.column_contents[i])();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ImGui::Text("%s", std::get<1>(params.column_contents[i]).c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -11,14 +11,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "app/gfx/bitmap.h"
|
|
||||||
#include "app/gfx/snes_palette.h"
|
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "app/gui/canvas.h"
|
|
||||||
#include "app/gui/color.h"
|
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
|
||||||
#include "imgui_memory_editor.h"
|
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@@ -62,8 +56,22 @@ void FileDialogPipeline(absl::string_view display_key,
|
|||||||
std::optional<absl::string_view> button_text,
|
std::optional<absl::string_view> button_text,
|
||||||
std::function<void()> callback);
|
std::function<void()> callback);
|
||||||
|
|
||||||
} // namespace gui
|
using GuiElement = std::variant<std::function<void()>, std::string>;
|
||||||
|
|
||||||
|
struct Table {
|
||||||
|
const char *id;
|
||||||
|
int num_columns;
|
||||||
|
ImGuiTableFlags flags;
|
||||||
|
ImVec2 size;
|
||||||
|
std::vector<std::string> column_labels;
|
||||||
|
std::vector<GuiElement> column_contents;
|
||||||
|
};
|
||||||
|
|
||||||
|
void AddTableColumn(Table &table, const std::string &label, GuiElement element);
|
||||||
|
|
||||||
|
void DrawTable(Table ¶ms);
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user