Added first frame (data tables) to the test application.
This commit is contained in:
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)
|
||||
Reference in New Issue
Block a user