aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI/UI_Templates.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/UI/UI_Templates.cpp')
-rw-r--r--core/src/UI/UI_Templates.cpp83
1 files changed, 68 insertions, 15 deletions
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);
}