Added a way to move menus around

This commit is contained in:
Ryzerth
2021-07-09 04:29:16 +02:00
parent 29ec14d3f0
commit cf3c976651
4 changed files with 160 additions and 15 deletions

View File

@ -35,9 +35,9 @@ namespace sourecmenu {
if (offsetMode == OFFSET_MODE_CUSTOM) { effectiveOffset = customOffset; }
else if (offsetMode == OFFSET_MODE_SPYVERTER) { effectiveOffset = 120000000; } // 120MHz Up-conversion
else if (offsetMode == OFFSET_MODE_HAM_IT_UP) { effectiveOffset = 125000000; } // 125MHz Up-conversion
else if (offsetMode == OFFSET_MODE_DK5AV_XB) { effectiveOffset = -6800000000; } // 6.8GHz Down-conversion
else if (offsetMode == OFFSET_MODE_KU_LNB_9750) { effectiveOffset = -9750000000; } // 9.750GHz Down-conversion
else if (offsetMode == OFFSET_MODE_KU_LNB_10700) { effectiveOffset = -10700000000; } // 10.7GHz Down-conversion
else if (offsetMode == OFFSET_MODE_DK5AV_XB) { effectiveOffset = -6800000000; } // 6.8GHz Down-conversion
else if (offsetMode == OFFSET_MODE_KU_LNB_9750) { effectiveOffset = -9750000000; } // 9.750GHz Down-conversion
else if (offsetMode == OFFSET_MODE_KU_LNB_10700) { effectiveOffset = -10700000000; } // 10.7GHz Down-conversion
else { effectiveOffset = 0; }
sigpath::sourceManager.setTuningOffset(effectiveOffset);
}

View File

@ -1,6 +1,7 @@
#include <gui/widgets/menu.h>
#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <gui/style.h>
Menu::Menu() {
@ -26,19 +27,61 @@ void Menu::removeEntry(std::string name) {
bool Menu::draw(bool updateStates) {
bool changed = false;
headerTops.clear();
displayedNames.clear();
float menuWidth = ImGui::GetContentRegionAvailWidth();
ImGuiWindow* window = ImGui::GetCurrentWindow();
int id = 0;
ImU32 textColor = ImGui::GetColorU32(ImGuiCol_Text);
for (MenuOption_t& opt : order) {
if (items.find(opt.name) == items.end()) {
continue;
}
if (opt.name == draggedMenuName) {
ImGui::BeginTooltip();
ImGui::Text("%s", draggedMenuName.c_str());
ImGui::EndTooltip();
continue;
}
if (id == insertBefore && draggedMenuName != "") {
if (updateStates) { ImGui::SetNextItemOpen(false); }
ImVec2 posMin = ImGui::GetCursorScreenPos();
ImVec2 posMax = ImVec2(posMin.x + menuWidth, posMin.y + ImGui::GetFrameHeight());
style::beginDisabled();
ImGui::CollapsingHeader((draggedMenuName + "##sdrpp_main_menu_dragging").c_str());
style::endDisabled();
window->DrawList->AddRect(posMin, posMax, textColor);
}
id++;
MenuItem_t& item = items[opt.name];
ImRect orginalRect = window->WorkRect;
if (item.inst != NULL) {
window->WorkRect = ImRect(orginalRect.Min, ImVec2(orginalRect.Max.x - ImGui::GetTextLineHeight() - 6, orginalRect.Max.y));
}
ImVec2 posMin = ImGui::GetCursorScreenPos();
ImVec2 posMax = ImVec2(posMin.x + menuWidth, posMin.y + ImGui::GetFrameHeight());
headerTops.push_back(posMin.y);
displayedNames.push_back(opt.name);
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsMouseHoveringRect(posMin, posMax)) {
menuClicked = true;
clickedMenuName = opt.name;
}
if (menuClicked && ImGui::IsMouseDragging(ImGuiMouseButton_Left) && draggedMenuName == "" && clickedMenuName == opt.name) {
draggedMenuName = opt.name;
continue;
}
if (updateStates) { ImGui::SetNextItemOpen(opt.open); }
if (ImGui::CollapsingHeader((opt.name + "##sdrpp_main_menu").c_str())) {
if (item.inst != NULL) {
@ -83,6 +126,69 @@ bool Menu::draw(bool updateStates) {
changed = true;
}
}
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && menuClicked) {
if (draggedMenuName != "") {
// Move menu
int movedId = 0;
MenuOption_t movedOpt;
for (int i = 0; i < order.size(); i++) {
if (order[i].name == draggedMenuName) {
movedId = i;
movedOpt = order[i];
break;
}
}
order.erase(order.begin() + movedId);
if (insertBefore == headerTops.size()) {
order.push_back(movedOpt);
}
else if (insertBeforeName != "") {
int beforeId = 0;
for (int i = 0; i < order.size(); i++) {
if (order[i].name == insertBeforeName) {
beforeId = i;
break;
}
}
order.insert(order.begin() + beforeId, movedOpt);
}
changed = true;
}
menuClicked = false;
draggedMenuName = "";
insertBeforeName = "";
insertBefore = -1;
}
if (insertBefore == headerTops.size() && draggedMenuName != "") {
if (updateStates) { ImGui::SetNextItemOpen(false); }
ImVec2 posMin = ImGui::GetCursorScreenPos();
ImVec2 posMax = ImVec2(posMin.x + menuWidth, posMin.y + ImGui::GetFrameHeight());
style::beginDisabled();
ImGui::CollapsingHeader((draggedMenuName + "##sdrpp_main_menu_dragging").c_str());
style::endDisabled();
window->DrawList->AddRect(posMin, posMax, textColor);
}
if (draggedMenuName != "") {
insertBefore = headerTops.size();
ImVec2 mPos = ImGui::GetMousePos();
for (int i = 0; i < headerTops.size(); i++) {
if (headerTops[i] > mPos.y) {
insertBefore = i;
insertBeforeName = displayedNames[i];
break;
}
}
}
return changed;
}

View File

@ -28,5 +28,13 @@ public:
private:
bool isInOrderList(std::string name);
bool menuClicked = false;
std::string clickedMenuName = "";
std::string draggedMenuName = "";
std::vector<float> headerTops;
int insertBefore = -1;
std::string insertBeforeName = "";
std::vector<std::string> displayedNames;
std::map<std::string, MenuItem_t> items;
};