Added first frame (data tables) to the test application.
This commit is contained in:
parent
b38fa1b68b
commit
5ebd609507
@ -5,6 +5,7 @@ src_files = Split("""
|
||||
main.cpp
|
||||
|
||||
application.cpp
|
||||
frames/data_table.cpp
|
||||
""")
|
||||
|
||||
prog_app = env.UnityProgram(
|
||||
|
@ -13,6 +13,7 @@ bool Application::init()
|
||||
setMainWindowFlags(raid::DEFAULT_MAIN_WINDOW_FLAGS | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking);
|
||||
setMainWindowStyle(ImGuiStyleVar_WindowPadding, ImVec2());
|
||||
setMainWindowStyle(ImGuiStyleVar_WindowBorderSize, 0.f);
|
||||
std::ranges::fill(mFrameOpen, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -35,14 +36,35 @@ void Application::render()
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Frames"))
|
||||
{
|
||||
for (std::size_t idx = 0; idx < NUM_FRAMES; ++idx) {
|
||||
ImGui::MenuItem(FRAMES[idx].title, nullptr, &mFrameOpen[idx]);
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Debug"))
|
||||
{
|
||||
ImGui::MenuItem("ImGui Metrics", nullptr, &mShowMetrics);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::Text("hi");
|
||||
|
||||
ImGui::ShowMetricsWindow();
|
||||
ImGui::Begin("Test");
|
||||
ImGui::Text("Test Content");
|
||||
ImGui::End();
|
||||
const ImGuiID dockID = ImGui::GetID(this);
|
||||
ImGui::DockSpace(dockID);
|
||||
|
||||
if (mShowMetrics) {
|
||||
ImGui::ShowMetricsWindow(&mShowMetrics);
|
||||
}
|
||||
|
||||
for (std::size_t idx = 0; idx < NUM_FRAMES; ++idx)
|
||||
{
|
||||
ImGui::SetNextWindowDockID(dockID, ImGuiCond_FirstUseEver);
|
||||
if (mFrameOpen[idx]) {
|
||||
FRAMES[idx].render(mFrameOpen[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Application::getFolderName()
|
||||
|
@ -4,12 +4,28 @@
|
||||
#if !defined(RAID_TEST_APPLICATION_HPP_INCLUDED)
|
||||
#define RAID_TEST_APPLICATION_HPP_INCLUDED 1
|
||||
|
||||
#include <array>
|
||||
#include "raid/raid.hpp"
|
||||
#include "./frames/data_table.hpp"
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
class Application : public raid::Application
|
||||
{
|
||||
private:
|
||||
struct Frame
|
||||
{
|
||||
using render_fn_t = void (*)(bool& open);
|
||||
const char* title;
|
||||
render_fn_t render;
|
||||
};
|
||||
static constexpr Frame FRAMES[] = {
|
||||
{.title = DATA_TABLE_TITLE, .render = &renderDataTable}
|
||||
};
|
||||
static constexpr std::size_t NUM_FRAMES = sizeof(FRAMES) / sizeof(FRAMES[0]);
|
||||
|
||||
bool mShowMetrics = false;
|
||||
std::array<bool, NUM_FRAMES> mFrameOpen{};
|
||||
protected:
|
||||
bool init() override;
|
||||
void configureImgui() override;
|
||||
|
89
private/raid_test/frames/data_table.cpp
Normal file
89
private/raid_test/frames/data_table.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
|
||||
#include "raid_test/frames/data_table.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include <imgui.h>
|
||||
#include "raid/imraid.hpp"
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const std::array FIRST_NAMES = {
|
||||
"Emma", "Hannah", "Mia", "Leonie", "Lina", "Marie", "Sophia", "Charlotte", "Paula", "Greta", "Frieda", "Ella", "Freia",
|
||||
"Leon", "Paul", "Maximilian", "Ben", "Lukas", "Finn", "Fiete", "Felix", "Moritz", "Jakob", "Tim", "Emil", "Theo",
|
||||
"James", "Mary", "Michael", "Patricia", "John", "Jennifer", "Robert", "Linda", "David", "Elizabeth", "William",
|
||||
"Barbara", "Richard", "Susan", "Joseph", "Jessica", "Thomas", "Karen", "Christopher", "Sarah"
|
||||
};
|
||||
const std::array LAST_NAMES = {
|
||||
"Müller", "Schmidt", "Schneider", "Fischer", "Meyer", "Weber", "Hofmann", "Wagner", "Becker", "Schulz", "Schäfer",
|
||||
"Koch", "Bauer", "Richter", "Klein", "Schröder", "Wolf", "Neumann", "Schwarz", "Schmitz", "Smith", "Johnson",
|
||||
"Williams", "Brown", "Jones", "Garcia", "Miller", "Davis", "Rodríguez", "Martínez", "Hernández", "López", "Gonzalez",
|
||||
"Wilson", "Anderson", "Thomas", "Taylor", "Moore", "Jackson", "Martin"
|
||||
};
|
||||
|
||||
constexpr int MIN_AGE = 18;
|
||||
constexpr int MAX_AGE = 120;
|
||||
constexpr double HEIGHT_MEAN = 1.75;
|
||||
constexpr double HEIGHT_STDDEV = 0.1;
|
||||
constexpr std::size_t NUM_PEOPLE = 5000;
|
||||
|
||||
struct Person
|
||||
{
|
||||
const char* firstName;
|
||||
const char* lastName;
|
||||
int age;
|
||||
double height;
|
||||
};
|
||||
|
||||
using rand_int_t = std::mt19937::result_type;
|
||||
|
||||
std::mt19937 gRandom(std::random_device{}());
|
||||
std::uniform_int_distribution<rand_int_t> gFirstNameDistribution(0, static_cast<rand_int_t>(FIRST_NAMES.size()-1));
|
||||
std::uniform_int_distribution<rand_int_t> gLastNameDistribution(0, static_cast<rand_int_t>(LAST_NAMES.size()-1));
|
||||
std::uniform_int_distribution<rand_int_t> gAgeDistribution(static_cast<rand_int_t>(MIN_AGE), static_cast<rand_int_t>(MAX_AGE));
|
||||
std::normal_distribution gHeightDistribution(HEIGHT_MEAN, HEIGHT_STDDEV);
|
||||
|
||||
[[nodiscard]]
|
||||
Person randomPerson()
|
||||
{
|
||||
return {
|
||||
.firstName = FIRST_NAMES[gFirstNameDistribution(gRandom)],
|
||||
.lastName = LAST_NAMES[gLastNameDistribution(gRandom)],
|
||||
.age = static_cast<int>(gAgeDistribution(gRandom)),
|
||||
.height = gHeightDistribution(gRandom)
|
||||
};
|
||||
}
|
||||
|
||||
const std::array<Person, NUM_PEOPLE> PEOPLE = []()
|
||||
{
|
||||
std::array<Person, NUM_PEOPLE> result;
|
||||
std::ranges::generate(result, randomPerson);
|
||||
return result;
|
||||
}();
|
||||
|
||||
const std::array DATA_TABLE_COLUMNS = {
|
||||
ImRaid::MakeStringColumn("First Name", &Person::firstName),
|
||||
ImRaid::MakeStringColumn("Last Name", &Person::lastName),
|
||||
ImRaid::MakeColumn("Age", "%d years", &Person::age),
|
||||
ImRaid::MakeColumn("Height", "%.2f m", &Person::height)
|
||||
};
|
||||
const ImRaid::DataTableOptions<Person> DATA_TABLE_OPTIONS = {
|
||||
.columns = DATA_TABLE_COLUMNS
|
||||
};
|
||||
ImRaid::DataTableState gDataTableState;
|
||||
}
|
||||
void renderDataTable(bool& open)
|
||||
{
|
||||
if (!ImGui::Begin(DATA_TABLE_TITLE, &open))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
ImRaid::DataTable("people", DATA_TABLE_OPTIONS, PEOPLE, gDataTableState);
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
} // namespace raid_test
|
14
private/raid_test/frames/data_table.hpp
Normal file
14
private/raid_test/frames/data_table.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(RAID_TEST_FRAMES_DATA_TABLE_HPP_INCLUDED)
|
||||
#define RAID_TEST_FRAMES_DATA_TABLE_HPP_INCLUDED 1
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
inline constexpr const char* DATA_TABLE_TITLE = "Data Table";
|
||||
|
||||
void renderDataTable(bool& open);
|
||||
} // namespace raid_test
|
||||
|
||||
#endif // !defined(RAID_TEST_FRAMES_DATA_TABLE_HPP_INCLUDED)
|
Loading…
x
Reference in New Issue
Block a user