summaryrefslogtreecommitdiff
path: root/core/src/UI
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-11 22:19:23 -0700
committerrtk0c <[email protected]>2021-06-11 22:19:23 -0700
commitbdee9dd0c92865e0cec2f4bbf170959df282a930 (patch)
treeaf9d40cb4378ee2166574faed9cc16e283110f31 /core/src/UI
parent8f7daa9bd100345d7e23639604c9a3a50ce6448b (diff)
More UI polishing and fix asset saving/reloading
Diffstat (limited to 'core/src/UI')
-rw-r--r--core/src/UI/UI_DatabaseView.cpp10
-rw-r--r--core/src/UI/UI_Templates.cpp83
2 files changed, 73 insertions, 20 deletions
diff --git a/core/src/UI/UI_DatabaseView.cpp b/core/src/UI/UI_DatabaseView.cpp
index caf81d8..40f29ca 100644
--- a/core/src/UI/UI_DatabaseView.cpp
+++ b/core/src/UI/UI_DatabaseView.cpp
@@ -225,6 +225,11 @@ public:
}
ImGui::SameLine();
+ if (ImGui::Button(ICON_FA_PLUS " " I18N_TEXT("Add", L10N_ADD))) {
+ // TODO
+ }
+
+ ImGui::SameLine();
if (ImGui::Button(ICON_FA_EDIT " " I18N_TEXT("Edit", L10N_EDIT), mSelectRow == -1)) {
ImGui::OpenPopup(mEditDialogTitle);
}
@@ -236,11 +241,6 @@ public:
}
ImGui::SameLine();
- if (ImGui::Button(ICON_FA_PLUS " " I18N_TEXT("Add", L10N_ADD))) {
- // TODO
- }
-
- ImGui::SameLine();
if (ImGui::Button(ICON_FA_TRASH " " I18N_TEXT("Delete", L10N_DELETE), mSelectRow == -1)) {
// TODO
}
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index e08510a..7d0251a 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -30,17 +30,27 @@ class TableTemplateUI : public TemplateUI
private:
std::unique_ptr<TableTemplate> mTable;
- TableCell* mSelectedCell = nullptr;
+ Vec2i mSelectionTL;
+ Vec2i mSelectionBR;
+
+ bool mDirty = false;
+ bool mFirstDraw = true;
public:
TableTemplateUI(std::unique_ptr<TableTemplate> table)
: mTable{ std::move(table) }
{
+ // TODO debug code
+ mTable->Resize(6, 2);
}
virtual void Draw() override
{
ImGui::Columns(2);
+ if (mFirstDraw) {
+ mFirstDraw = false;
+ ImGui::SetColumnWidth(0, ImGui::GetWindowWidth() * 0.15f);
+ }
DrawInspector();
ImGui::NextColumn();
@@ -55,36 +65,43 @@ private:
void DrawInspector()
{
if (ImGui::BeginTabBar("Inspector")) {
- if (ImGui::BeginTabItem("Table")) {
- DrawTableInspector();
- ImGui::EndTabItem();
- }
if (ImGui::BeginTabItem("Cell")) {
DrawCellInspector();
ImGui::EndTabItem();
}
+ if (ImGui::BeginTabItem("Table")) {
+ DrawTableInspector();
+ ImGui::EndTabItem();
+ }
ImGui::EndTabBar();
}
}
- void DrawTableInspector()
- {
- // TODO
- }
-
void DrawCellInspector()
{
- if (mSelectedCell) {
-
+ if (IsSelected()) {
+ if (mSelectionTL == mSelectionBR) {
+ auto& selectCell = mTable->GetCell(mSelectionTL);
+ // TODO
+ } else {
+ // TODO
+ }
} else {
ImGui::Text("Select a cell to edit");
}
}
+ void DrawTableInspector()
+ {
+ // TODO
+ }
+
void DrawTable()
{
constexpr int kCellSpacing = 20;
+ ImGui::BeginChild("TableTemplate");
+
int colCount = mTable->GetTableWidth();
int rowCount = mTable->GetTableHeight();
float x = 0.0f;
@@ -95,12 +112,28 @@ private:
for (int colIdx = 0; colIdx < colCount; ++colIdx) {
int colWidth = mTable->GetColumnWidth(colIdx);
+ int i = rowIdx * colCount + colIdx;
+ ImGuiID id = ImGui::GetCurrentWindow()->GetID(i);
+
+ auto p = ImGui::GetCursorPos();
+ ImGui::GetWindowDrawList()->AddRectFilled(
+ ImVec2(p.x + x, p.y + y),
+ ImVec2(p.x + x + colWidth, p.y + y + rowHeight),
+ RgbaColor(170, 204, 244).AsImU32());
+
ImRect rect{
ImVec2(x, y),
ImVec2(colWidth, rowHeight),
};
-
- // TODO
+ if (ImGui::ButtonBehavior(rect, id, nullptr, nullptr)) {
+ if (ImGui::GetIO().KeyShift && IsSelected()) {
+ // Select range
+ mSelectionBR = { colIdx, rowIdx };
+ } else {
+ // Select a single cell
+ SelectCell({ colIdx, rowIdx });
+ }
+ }
x += colWidth;
x += kCellSpacing;
@@ -109,6 +142,25 @@ private:
y += rowHeight;
y += kCellSpacing;
}
+
+ ImGui::EndChild();
+ }
+
+ bool IsSelected() const
+ {
+ return mSelectionTL.x != -1;
+ }
+
+ void ClearSelection()
+ {
+ mSelectionTL = { -1, -1 };
+ mSelectionBR = { -1, -1 };
+ }
+
+ void SelectCell(Vec2i cell)
+ {
+ mSelectionTL = cell;
+ mSelectionBR = cell;
}
};
@@ -152,7 +204,8 @@ void UI::TemplatesTab()
ImGui::OpenPopup(I18N_TEXT("Open asset", L10N_ASSET_OPEN_DIALOG_TITLE));
}
if (ImGui::BeginPopupModal(I18N_TEXT("Open asset", L10N_ASSET_OPEN_DIALOG_TITLE), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
- if (ImGui::Button(I18N_TEXT("Open", L10N_OPEN), state.SelectedAsset == nullptr)) {
+ if (ImGui::Button(ICON_FA_FOLDER_OPEN " " I18N_TEXT("Open", L10N_OPEN), state.SelectedAsset == nullptr)) {
+ ImGui::CloseCurrentPopup();
auto kind = static_cast<Template::Kind>(state.SelectedAsset->Payload);
openTemplate = TemplateUI::CreateByKind(kind);
}