aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-04-28 15:18:51 -0700
committerrtk0c <[email protected]>2021-04-28 15:18:51 -0700
commit00fd95526677d670d002ca81069636f0f74b91f7 (patch)
treea783f05be218a58c2b78175425f7576664c3f1a9 /core/src/UI
parentb7d5b514e7bffd3149a99bc7f1424f8251876d85 (diff)
Code cleanup, fix database view paging and selection
Diffstat (limited to 'core/src/UI')
-rw-r--r--core/src/UI/UI_DatabaseView.cpp22
-rw-r--r--core/src/UI/UI_Items.cpp36
-rw-r--r--core/src/UI/UI_Workflows.cpp31
3 files changed, 65 insertions, 24 deletions
diff --git a/core/src/UI/UI_DatabaseView.cpp b/core/src/UI/UI_DatabaseView.cpp
index 884ab51..4009e5b 100644
--- a/core/src/UI/UI_DatabaseView.cpp
+++ b/core/src/UI/UI_DatabaseView.cpp
@@ -56,6 +56,8 @@ private:
/// index by offsetting by \c mFirstCachedRowId.
std::vector<int> mActiveEntries;
+ /// Number of rows in the table.
+ int mRowCount;
/// Last possible page for the current set table and filter (inclusive).
int mLastPage;
/// The current page the user is on.
@@ -71,6 +73,13 @@ public:
void OnProjectChanged(Project* newProject) {
mProject = newProject;
+ auto& stmt = newProject->GetTransactionsModel().GetSales().GetRowCountStatement;
+ if (stmt.executeStep()) {
+ mRowCount = stmt.getColumn(0).getInt();
+ } else {
+ // TODO report error
+ }
+
mFirstCachedRowId = 0;
mLastCachedRowId = 0;
@@ -116,6 +125,7 @@ public:
auto ls = LocaleStrings::Instance.get();
if (ImGui::Button(ICON_FA_ARROW_LEFT, mCurrentPage == 0)) {
+ mSelectedEntryRowId = -1;
SetPage(mCurrentPage - 1);
}
@@ -125,6 +135,7 @@ public:
ImGui::SameLine();
if (ImGui::Button(ICON_FA_ARROW_RIGHT, mCurrentPage == mLastPage)) {
+ mSelectedEntryRowId = -1;
SetPage(mCurrentPage + 1);
}
@@ -165,6 +176,9 @@ public:
void DrawEntry(const SaleEntry& entry, int rowId) {
auto ls = LocaleStrings::Instance.get();
+ ImGui::PushID(rowId);
+ ImGui::TableNextRow();
+
ImGui::TableNextColumn();
if (ImGui::Selectable(entry.Customer.c_str(), mSelectedEntryRowId == rowId, ImGuiSelectableFlags_SpanAllColumns)) {
mSelectedEntryRowId = rowId;
@@ -179,6 +193,8 @@ public:
} else {
ImGui::Text("%s", entry.DeliveryTime.c_str());
}
+
+ ImGui::PopID();
}
const SaleEntry& GetEntry(int64_t rowId) const {
@@ -197,7 +213,7 @@ private:
void UpdateLastPage() {
mLastPage = mActiveEntries.empty()
- ? 0 // TODO calc page
+ ? CalcPageForRowId(mRowCount)
: CalcPageForRowId(mActiveEntries.back());
}
@@ -267,7 +283,10 @@ private:
auto t = chrono::system_clock::to_time_t(tp);
char data[32];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // C++ doesn't have std::localtime_s
std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
+#pragma clang diagnostic pop
return std::string(data);
};
@@ -351,7 +370,6 @@ void UI::DatabaseViewTab() {
purchasesView.Draw();
ImGui::EndTabItem();
}
-
ImGui::EndTabBar();
}
}
diff --git a/core/src/UI/UI_Items.cpp b/core/src/UI/UI_Items.cpp
index 56d6c2a..899db6e 100644
--- a/core/src/UI/UI_Items.cpp
+++ b/core/src/UI/UI_Items.cpp
@@ -220,27 +220,19 @@ void UI::ItemsTab() {
auto ls = LocaleStrings::Instance.get();
auto& uis = UIState::GetInstance();
- constexpr float kAmount = 16.0f;
- int id = 0;
- if (ImGui::CollapsingHeader(ls->ProductCategoryName.Get())) {
- ImGui::PushID(id++);
- ImGui::Indent(kAmount);
- ItemListEditor(uis.CurrentProject->Products);
- ImGui::Unindent(kAmount);
- ImGui::PopID();
- }
- if (ImGui::CollapsingHeader(ls->FactoryCategoryName.Get())) {
- ImGui::PushID(id++);
- ImGui::Indent(kAmount);
- ItemListEditor(uis.CurrentProject->Factories);
- ImGui::Unindent(kAmount);
- ImGui::PopID();
- }
- if (ImGui::CollapsingHeader(ls->CustomerCategoryName.Get())) {
- ImGui::PushID(id++);
- ImGui::Indent(kAmount);
- ItemListEditor(uis.CurrentProject->Customers);
- ImGui::Unindent(kAmount);
- ImGui::PopID();
+ if (ImGui::BeginTabBar("##ItemViewTabs")) {
+ if (ImGui::BeginTabItem(ls->ProductCategoryName.Get())) {
+ ItemListEditor(uis.CurrentProject->Products);
+ ImGui::EndTabItem();
+ }
+ if (ImGui::BeginTabItem(ls->FactoryCategoryName.Get())) {
+ ItemListEditor(uis.CurrentProject->Factories);
+ ImGui::EndTabItem();
+ }
+ if (ImGui::BeginTabItem(ls->CustomerCategoryName.Get())) {
+ ItemListEditor(uis.CurrentProject->Customers);
+ ImGui::EndTabItem();
+ }
+ ImGui::EndTabBar();
}
}
diff --git a/core/src/UI/UI_Workflows.cpp b/core/src/UI/UI_Workflows.cpp
index 0adfdc2..fe504e2 100644
--- a/core/src/UI/UI_Workflows.cpp
+++ b/core/src/UI/UI_Workflows.cpp
@@ -9,10 +9,13 @@
#include "Utils/Macros.hpp"
#include <imgui.h>
+#include <imgui_node_editor.h>
#include <memory>
#include <span>
#include <vector>
+namespace ImNodes = ax::NodeEditor;
+
namespace {
class WorkflowCreationMenu {
private:
@@ -127,13 +130,41 @@ private:
class WorkflowUI {
private:
Workflow* mWorkflow;
+ ImNodes::EditorContext* mContext;
public:
+ WorkflowUI() {
+ mContext = ImNodes::CreateEditor();
+ }
+
+ ~WorkflowUI() {
+ ImNodes::DestroyEditor(mContext);
+ }
+
void Draw() {
+ ImNodes::SetCurrentEditor(mContext);
+ ImNodes::Begin("");
+
+ for (auto& node : mWorkflow->GetNodes()) {
+ if (!node) continue;
+
+ ImNodes::BeginNode(node->GetId());
+ node->Draw();
+ ImNodes::EndNode();
+ }
+
+ for (auto& conn : mWorkflow->GetConnections()) {
+ if (!conn.IsValid()) continue;
+
+ // TODO create link
+ }
+
+ ImNodes::End();
}
};
} // namespace
void UI::WorkflowsTab() {
+ static std::unique_ptr<WorkflowUI> openWorkflow;
// TODO
}