Skip to content

Commit

Permalink
More DPI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Feb 25, 2022
1 parent 8a603c5 commit 7638075
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions core/src/gui/menus/module_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@ namespace module_manager_menu {

void draw(void* ctx) {
bool modified = false;

// Calculate delete button size and cell size
ImVec2 cellpad = ImGui::GetStyle().CellPadding;
float lheight = ImGui::GetTextLineHeight();
float cellWidth = lheight - (2.0f * cellpad.y);
float hdiff = cellpad.x - cellpad.y;
ImVec2 btnSize = ImVec2(lheight + 1, lheight - 1);
ImVec2 textOff = ImVec2(3.0f * style::uiScale, -5.0f * style::uiScale);

if (ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, 200))) {
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 10);
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, cellWidth);
ImGui::TableSetupScrollFreeze(3, 1);
ImGui::TableHeadersRow();

float height = ImGui::CalcTextSize("-").y;

for (auto& [name, inst] : core::moduleManager.instances) {
ImGui::TableNextRow();

Expand All @@ -49,13 +56,13 @@ namespace module_manager_menu {
ImGui::TextUnformatted(inst.module.info->name);

ImGui::TableSetColumnIndex(2);
ImVec2 origPos = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(origPos.x - 3, origPos.y));
if (ImGui::Button(("##module_mgr_" + name).c_str(), ImVec2(height, height))) {
ImVec2 cpos = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(cpos.x - hdiff, cpos.y + 1));
if (ImGui::Button(("##module_mgr_" + name).c_str(), btnSize)) {
toBeRemoved = name;
confirmOpened = true;
}
ImGui::SetCursorPos(ImVec2(origPos.x + 2, origPos.y - 5));
ImGui::SetCursorPos(ImVec2(cpos.x + textOff.x, cpos.y + textOff.y));
ImGui::TextUnformatted("_");
}
ImGui::EndTable();
Expand All @@ -73,34 +80,38 @@ namespace module_manager_menu {
});

// Add module row with slightly different settings
ImGui::BeginTable("Module Manager Add Table", 3);
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 16);
ImGui::TableNextRow();

ImGui::TableSetColumnIndex(0);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputText("##module_mod_name", modName, 1000);

ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::Combo("##module_mgr_type", &modTypeId, modTypesTxt.c_str());

ImGui::TableSetColumnIndex(2);
if (strlen(modName) == 0) { style::beginDisabled(); }
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16, 0))) {
if (!core::moduleManager.createInstance(modName, modTypes[modTypeId])) {
core::moduleManager.postInit(modName);
modified = true;
}
else {
errorMessage = "Could not create new instance of " + modTypes[modTypeId];
errorOpen = true;
if (ImGui::BeginTable("Module Manager Add Table", 3)) {
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, cellWidth);

ImGui::TableNextRow();

ImGui::TableSetColumnIndex(0);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x + cellpad.x);
ImGui::InputText("##module_mod_name", modName, 1000);

ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x + cellpad.x);
ImGui::Combo("##module_mgr_type", &modTypeId, modTypesTxt.c_str());

ImGui::TableSetColumnIndex(2);
if (strlen(modName) == 0) { style::beginDisabled(); }
ImVec2 cpos = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(cpos.x - hdiff, cpos.y));
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(btnSize.x, 0))) {
if (!core::moduleManager.createInstance(modName, modTypes[modTypeId])) {
core::moduleManager.postInit(modName);
modified = true;
}
else {
errorMessage = "Could not create new instance of " + modTypes[modTypeId];
errorOpen = true;
}
}
if (strlen(modName) == 0) { style::endDisabled(); }
ImGui::EndTable();
}
if (strlen(modName) == 0) { style::endDisabled(); }
ImGui::EndTable();

if (modified) {
// Update enabled and disabled modules
Expand Down

0 comments on commit 7638075

Please sign in to comment.