More work on MacOS and the scheduler

This commit is contained in:
AlexandreRouma
2021-11-15 17:15:59 +01:00
parent 0ab4d16f9d
commit 40e2564ef9
7 changed files with 200 additions and 33 deletions

View File

@@ -23,10 +23,35 @@ public:
return true;
}
void prepareEditMenu() {
for (auto& act : actions) {
act->selected = false;
}
}
bool showEditMenu(char* name, bool& valid) {
ImGui::LeftLabel("Name");
ImGui::InputText("##scheduler_task_edit_name", name, 1023);
if (editedAction >= 0) {
bool valid = false;
std::string id = "Edit Action##scheduler_edit_action";
ImGui::OpenPopup(id.c_str());
if (ImGui::BeginPopup(id.c_str(), ImGuiWindowFlags_NoResize)) {
bool valid = false;
bool open = actions[editedAction]->showEditMenu(valid);
// Stop editing of closed
if (!open) {
// TODO: Do something if valid I think
editedAction = -1;
}
ImGui::EndPopup();
}
}
if (ImGui::BeginTable("scheduler_task_triggers", 1, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, 100))) {
ImGui::TableSetupColumn("Triggers");
ImGui::TableSetupScrollFreeze(1, 1);
@@ -45,10 +70,31 @@ public:
ImGui::TableSetupScrollFreeze(1, 1);
ImGui::TableHeadersRow();
int id = 0;
for (auto& act : actions) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text(act->getName().c_str());
if (ImGui::Selectable((act->getName() + "##scheduler_task_actions_entry").c_str(), &act->selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
// if shift or control isn't pressed, deselect all others
if (!ImGui::IsKeyDown(GLFW_KEY_LEFT_SHIFT) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_SHIFT) &&
!ImGui::IsKeyDown(GLFW_KEY_LEFT_CONTROL) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) {
int _id = 0;
for (auto& _act : actions) {
if (_id == id) { continue; }
_act->selected = false;
_id++;
}
}
}
// Open edit menu on double click
if (ImGui::TableGetHoveredColumn() >= 0 && ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && editedAction < 0) {
editedAction = id;
act->prepareEditMenu();
}
id++;
}
ImGui::EndTable();
@@ -72,4 +118,6 @@ public:
private:
std::vector<sched_action::Action> actions;
int editedAction = -1;
};