From b239c0aaff715e51a2d5433cb8e30c4a7c3fd691 Mon Sep 17 00:00:00 2001 From: Houssem Date: Fri, 10 May 2024 15:19:22 +0200 Subject: [PATCH] adding dynamic number input and reading in matrix --- src/gui/PivotGui.cpp | 37 ++++++++++++++++++++----------------- src/gui/PivotGui.h | 5 ++++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/gui/PivotGui.cpp b/src/gui/PivotGui.cpp index d106069..bcd056f 100644 --- a/src/gui/PivotGui.cpp +++ b/src/gui/PivotGui.cpp @@ -2,6 +2,10 @@ #include +std::vector> PivotGui::matrixValues; +int PivotGui::matrixSizeX = 4; +int PivotGui::matrixSizeY = 4; + void PivotGui::Init() {} void PivotGui::Render() { @@ -22,11 +26,6 @@ void PivotGui::Render() { ImGui::Text("Matrice initiale:"); - // taille matrice - static int matrixSizeX = 4; - static int matrixSizeY = 4; - - ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY); ImGui::SameLine(); ImGui::Text("Lignes"); @@ -36,18 +35,22 @@ void PivotGui::Render() { ImGui::SameLine(); ImGui::Text("Colonnes"); - // Draw matrix - ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false); + ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false); - for (int y = 0; y < matrixSizeY; y++) { - for (int x = 0; x < matrixSizeX; x++) { - if (x > 0) - ImGui::SameLine(); - ImGui::PushID(y * matrixSizeX + x); - ImGui::Selectable("?", false, 0, ImVec2(50, 50)); - ImGui::PopID(); - } - } + // Resize matrixValues + matrixValues.resize(matrixSizeY, std::vector(matrixSizeX, 0)); + + for (int y = 0; y < matrixSizeY; y++) { + for (int x = 0; x < matrixSizeX; x++) { + if (x > 0) + ImGui::SameLine(); + ImGui::PushID(y * matrixSizeX + x); + ImGui::PushItemWidth(30); // Adjust this value to change the cell size + ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal); + ImGui::PopItemWidth(); + ImGui::PopID(); + } + } ImGui::Text("Matrice finale:"); @@ -78,7 +81,7 @@ void PivotGui::Render() { // Code de calcul } ImGui::SameLine(); // Align buttons horizontally - if (ImGui::Button("Calcul inverse")) { + if (ImGui::Button("Calcul image")) { // Code de calcul } diff --git a/src/gui/PivotGui.h b/src/gui/PivotGui.h index fac84c6..d02b907 100644 --- a/src/gui/PivotGui.h +++ b/src/gui/PivotGui.h @@ -1,9 +1,12 @@ #pragma once +#include namespace PivotGui { void Init(); void Render(); void Destroy(); - +extern std::vector> matrixValues; +extern int matrixSizeX; +extern int matrixSizeY; } // namespace PivotGui