Skip to content

Commit

Permalink
refactor: refactored table view
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Nov 24, 2024
1 parent 2b21e0b commit 9ac4c81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
28 changes: 18 additions & 10 deletions src/Gui/GuiPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,34 +266,42 @@ void Gui::drawPlotTable(std::shared_ptr<Plot> plot)
continue;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
Variable::Color a = serPtr->var->getColor();
ImVec4 col = {a.r, a.g, a.b, a.a};
Variable::Color color = serPtr->var->getColor();
ImVec4 col = {color.r, color.g, color.b, color.a};
ImGui::ColorButton("##", col, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoTooltip, ImVec2(10 * GuiHelper::contentScale, 10 * GuiHelper::contentScale));
ImGui::SameLine();
ImGui::Text("%s", key.c_str());
ImGui::TableSetColumnIndex(1);
ImGui::Text("%s", ("0x" + std::string(GuiHelper::intToHexString(serPtr->var->getAddress()))).c_str());
ImGui::TableSetColumnIndex(2);
ImGui::SelectableInput(key.c_str(), false, ImGuiSelectableFlags_None, plot->getSeriesValueString(key, serPtr->var->getValue()).data(), Variable::maxVariableNameLength);
ImGui::Text("%s", plot->getSeriesValueString(key, serPtr->var->getValue()).data());
showChangeFormatPopup("format", *plot, key);
ImGui::TableSetColumnIndex(3);
ImGui::PushID("input");
char newValue[Variable::maxVariableNameLength] = {0};
if (ImGui::SelectableInput(key.c_str(), false, ImGuiSelectableFlags_None, newValue, Variable::maxVariableNameLength))

std::string valueToWrite = "";
std::string inputName = "##Input" + key;

ImVec4 cellBgColor = ImGui::GetStyle().Colors[ImGuiCol_TableRowBg];
ImGui::PushStyleColor(ImGuiCol_FrameBg, cellBgColor);
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, cellBgColor);
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, cellBgColor);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);

if (ImGui::InputText(inputName.c_str(), &valueToWrite, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
{
if (viewerDataHandler->getState() == DataHandlerBase::state::STOP)
{
ImGui::PopID();
ImGui::PopStyleColor(3);
continue;
}
if (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter))
{
logger->info("New value to be written: {}", newValue);
if (!viewerDataHandler->writeSeriesValue(*serPtr->var, std::stod(newValue)))
logger->info("New value to be written: {}", valueToWrite);
if (!viewerDataHandler->writeSeriesValue(*serPtr->var, std::stod(valueToWrite)))
logger->error("Error while writing new value!");
}
}
ImGui::PopID();
ImGui::PopStyleColor(3);
}
ImGui::EndTable();

Expand Down
2 changes: 0 additions & 2 deletions src/Gui/GuiVarTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class VariableTableWindow
ImGui::ColorEdit4("##", &var->getColor().r, ImGuiColorEditFlags_NoInputs);
ImGui::SameLine();
ImGui::PopID();
char variable[Variable::maxVariableNameLength] = {0};
std::memcpy(variable, var->getName().data(), var->getName().length());

const bool itemIsSelected = selection.contains(name);

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/GuiVariablesEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class VariableEditWindow
bool selectNameManually = editedVariable->getIsTrackedNameDifferent();

ImGui::Dummy(ImVec2(-1, 5));
GuiHelper::drawCenteredText("Variable");
GuiHelper::drawCenteredText("General");
ImGui::Separator();

if (stateChanged)
Expand Down
2 changes: 0 additions & 2 deletions src/Variable/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class Variable
double transformToDouble();

public:
static constexpr uint32_t maxVariableNameLength = 100;

static const char* types[8];
static const char* highLevelTypes[3];

Expand Down

0 comments on commit 9ac4c81

Please sign in to comment.