Show user_id and gen

This commit is contained in:
Nikola Petrov 2025-02-03 22:04:27 +01:00
parent 207e930b1c
commit 9c3d550224
3 changed files with 81 additions and 11 deletions

View File

@ -1,4 +1,4 @@
#include <vector>
#include "sql.hpp" #include "sql.hpp"
class Vapp class Vapp
@ -10,6 +10,14 @@ public:
void deinit(); void deinit();
private: private:
bool showDemoWindow; bool showDemoWindow = false;
bool showSelection = false;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *get_gen_num;
std::vector<int64_t> ids;
int64_t gens = -1;
int selected_id = -1;
bool update_gen = false;
int selected_gen = -1;
bool enableAll = true;
}; };

View File

@ -1,4 +1,5 @@
#include <cinttypes> #include <cinttypes>
#include <cmath>
#include "Vapp.hpp" #include "Vapp.hpp"
#include "values/Dna.hpp" #include "values/Dna.hpp"
@ -7,14 +8,45 @@
#include <imgui.h> #include <imgui.h>
#include <raylib.h> #include <raylib.h>
const char select_user_id[] = "SELECT USER_ID FROM user_table GROUP BY USER_ID;";
void Vapp::init() void Vapp::init()
{ {
sql::init(); sql::init();
sql::open(DB_NAME, &db); sql::open(DB_NAME, &db);
sqlite3_stmt *stmt;
sql::prepare_v2(db, select_user_id, -1, &stmt, NULL);
while (sql::step(stmt) != SQL_DONE)
{
int type = sql::column_type(stmt, 0);
if (type != SQL_NULL)
{
int64_t user_id = sql::column_int64(stmt, 0);
ids.push_back(user_id);
}
}
sql::prepare_v2(db, max_gen, -1, &get_gen_num, nullptr);
} }
void Vapp::update() void Vapp::update()
{ {
if (update_gen && selected_id >= 0)
{
sql::bind_int64(get_gen_num, 1, ids[selected_id]);
while (sql::step(get_gen_num) != SQL_DONE)
{
int type = sql::column_type(get_gen_num, 0);
if (type != SQL_NULL)
{
gens = sql::column_int64(get_gen_num, 0);
}
}
sql::reset(get_gen_num);
update_gen = false;
}
} }
void Vapp::draw() void Vapp::draw()
@ -25,18 +57,48 @@ void Vapp::draw()
if (ImGui::BeginMainMenuBar()) if (ImGui::BeginMainMenuBar())
{ {
if (ImGui::BeginMenu("Window")) ImGui::MenuItem("Demo Window", nullptr, &showDemoWindow, enableAll);
{ ImGui::MenuItem("Selection", nullptr, &showSelection, enableAll);
if (ImGui::MenuItem("Demo Window", nullptr, showDemoWindow)) if(ImGui::MenuItem("Draw", nullptr, false, enableAll)){
showDemoWindow = !showDemoWindow; enableAll = false;
showSelection = false;
ImGui::EndMenu();
} }
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }
if (showDemoWindow) if (showDemoWindow)
ImGui::ShowDemoWindow(&showDemoWindow); ImGui::ShowDemoWindow(&showDemoWindow);
if (showSelection)
{
ImGui::Begin("Selection", &showSelection);
if (ImGui::BeginListBox("##list_id", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f, -FLT_MIN)))
{
for (int n = 0; n < ids.size(); n++)
{
const bool is_selected = (selected_id == n);
if (ImGui::Selectable(TextFormat("%d", ids[n]), is_selected))
{
selected_id = n;
gens = -1;
update_gen = true;
}
}
ImGui::EndListBox();
}
ImGui::SameLine();
if (ImGui::BeginListBox("##list_gen", ImVec2(-FLT_MIN, -FLT_MIN)))
{
for (int n = 0; n <= gens; n++)
{
const bool is_selected = (selected_gen == n);
if (ImGui::Selectable(TextFormat("%d", n), is_selected))
selected_gen = n;
}
ImGui::EndListBox();
}
ImGui::End();
}
} }
void Vapp::deinit() void Vapp::deinit()

View File

@ -5,11 +5,11 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int screenWidth = 800; int screenWidth = 1000;
int screenHeight = 800; int screenHeight = 1000;
Vapp app; Vapp app;
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "VIEW"); InitWindow(screenWidth, screenHeight, "VIEW");
SetTargetFPS(60); SetTargetFPS(60);
rlImGuiSetup(true); rlImGuiSetup(true);