[XAM/UI] Simplified profile menu drawing logic
- Removed size precalculation. - Fixed image ratio to 1:1. - Removed scaling code that doesn't work anyway. If scaling is needed then it is in achievement earned notification code. - Removed hardcoded -1 in user_index comparation.
This commit is contained in:
parent
6a380bcd91
commit
fadc8d5a4d
|
@ -894,33 +894,52 @@ bool xeDrawProfileContent(ui::ImGuiDrawer* imgui_drawer, const uint64_t xuid,
|
||||||
auto profile_manager = kernel_state()->xam_state()->profile_manager();
|
auto profile_manager = kernel_state()->xam_state()->profile_manager();
|
||||||
|
|
||||||
const float default_image_size = 75.0f;
|
const float default_image_size = 75.0f;
|
||||||
auto position = ImGui::GetCursorPos();
|
const ImVec2 drawing_start_position = ImGui::GetCursorPos();
|
||||||
const float selectable_height =
|
ImVec2 current_drawing_position = ImGui::GetCursorPos();
|
||||||
ImGui::GetTextLineHeight() *
|
|
||||||
5; // 3 is for amount of lines of text behind image/object.
|
|
||||||
const auto font = imgui_drawer->GetIO().Fonts->Fonts[0];
|
|
||||||
|
|
||||||
const auto text_size = font->CalcTextSizeA(
|
// In the future it can be replaced with profile icon.
|
||||||
font->FontSize, FLT_MAX, -1.0f,
|
ImGui::Image(user_index < XUserMaxUserCount
|
||||||
fmt::format("XUID: {:016X}\n", 0xB13EBABEBABEBABE).c_str());
|
? imgui_drawer->GetNotificationIcon(user_index)
|
||||||
|
: nullptr,
|
||||||
|
ImVec2(default_image_size, default_image_size));
|
||||||
|
|
||||||
const auto image_scale = selectable_height / default_image_size;
|
ImGui::SameLine();
|
||||||
const auto image_size = ImVec2(default_image_size * image_scale,
|
current_drawing_position = ImGui::GetCursorPos();
|
||||||
default_image_size * image_scale);
|
ImGui::TextUnformatted(
|
||||||
|
fmt::format("User: {}\n", account->GetGamertagString()).c_str());
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPos(current_drawing_position);
|
||||||
|
ImGui::SetCursorPosY(current_drawing_position.y + ImGui::GetTextLineHeight());
|
||||||
|
ImGui::TextUnformatted(fmt::format("XUID: {:016X} \n", xuid).c_str());
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPos(current_drawing_position);
|
||||||
|
ImGui::SetCursorPosY(current_drawing_position.y +
|
||||||
|
2 * ImGui::GetTextLineHeight());
|
||||||
|
|
||||||
|
if (user_index != XUserIndexAny) {
|
||||||
|
ImGui::TextUnformatted(
|
||||||
|
fmt::format("Assigned to slot: {}\n", user_index + 1).c_str());
|
||||||
|
} else {
|
||||||
|
ImGui::TextUnformatted(fmt::format("Profile is not signed in").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
const ImVec2 drawing_end_position = ImGui::GetCursorPos();
|
||||||
|
|
||||||
if (xuid && selected_xuid) {
|
if (xuid && selected_xuid) {
|
||||||
// This includes 10% to include empty spaces between border and elements.
|
ImGui::SetCursorPos(drawing_start_position);
|
||||||
auto selectable_region_size =
|
|
||||||
ImVec2((image_size.x + text_size.x) * 1.10f, selectable_height);
|
|
||||||
|
|
||||||
if (ImGui::Selectable("##Selectable", *selected_xuid == xuid,
|
if (ImGui::Selectable(
|
||||||
ImGuiSelectableFlags_SpanAllColumns,
|
"##Selectable", *selected_xuid == xuid,
|
||||||
selectable_region_size)) {
|
ImGuiSelectableFlags_SpanAllColumns,
|
||||||
|
ImVec2(drawing_end_position.x - drawing_start_position.x,
|
||||||
|
drawing_end_position.y - drawing_start_position.y))) {
|
||||||
*selected_xuid = xuid;
|
*selected_xuid = xuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::BeginPopupContextItem("Profile Menu")) {
|
if (ImGui::BeginPopupContextItem("Profile Menu")) {
|
||||||
if (user_index == static_cast<uint8_t>(-1)) {
|
if (user_index == XUserIndexAny) {
|
||||||
if (ImGui::MenuItem("Login")) {
|
if (ImGui::MenuItem("Login")) {
|
||||||
profile_manager->Login(xuid);
|
profile_manager->Login(xuid);
|
||||||
}
|
}
|
||||||
|
@ -990,37 +1009,6 @@ bool xeDrawProfileContent(ui::ImGuiDrawer* imgui_drawer, const uint64_t xuid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::SetCursorPos(position);
|
|
||||||
|
|
||||||
// In the future it can be replaced with profile icon.
|
|
||||||
ImGui::Image(user_index < XUserMaxUserCount
|
|
||||||
? imgui_drawer->GetNotificationIcon(user_index)
|
|
||||||
: nullptr,
|
|
||||||
ImVec2(default_image_size * image_scale,
|
|
||||||
default_image_size * image_scale));
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
position = ImGui::GetCursorPos();
|
|
||||||
ImGui::TextUnformatted(
|
|
||||||
fmt::format("User: {}\n", account->GetGamertagString()).c_str());
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::SetCursorPos(position);
|
|
||||||
ImGui::SetCursorPosY(position.y + ImGui::GetTextLineHeight());
|
|
||||||
ImGui::TextUnformatted(fmt::format("XUID: {:016X}\n", xuid).c_str());
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::SetCursorPos(position);
|
|
||||||
ImGui::SetCursorPosY(position.y + 2 * ImGui::GetTextLineHeight());
|
|
||||||
|
|
||||||
if (user_index != static_cast<uint8_t>(-1)) {
|
|
||||||
ImGui::TextUnformatted(
|
|
||||||
fmt::format("Assigned to slot: {}\n", user_index + 1).c_str());
|
|
||||||
} else {
|
|
||||||
ImGui::TextUnformatted(fmt::format("Profile is not signed in").c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue