devtools: reg popup size adjusted to the content

This commit is contained in:
Vinicius Rangel 2024-10-15 02:38:43 -03:00
parent a145ed0f07
commit ca0ca4913f
No known key found for this signature in database
GPG Key ID: A5B154D904B761D9
4 changed files with 22 additions and 18 deletions

View File

@ -9,6 +9,7 @@
#include "cmd_list.h" #include "cmd_list.h"
#include "common.h" #include "common.h"
#include "imgui/imgui_std.h"
using namespace ImGui; using namespace ImGui;
using magic_enum::enum_name; using magic_enum::enum_name;
@ -143,29 +144,31 @@ RegPopup::RegPopup() {
void RegPopup::SetData(AmdGpu::Liverpool::ColorBuffer color_buffer, u32 batch_id, u32 cb_id) { void RegPopup::SetData(AmdGpu::Liverpool::ColorBuffer color_buffer, u32 batch_id, u32 cb_id) {
this->data = color_buffer; this->data = color_buffer;
this->title = fmt::format("Batch #{} CB #{}", batch_id, cb_id); this->title = fmt::format("Batch #{} CB #{}###reg_popup_%d", batch_id, cb_id, id);
} }
void RegPopup::SetData(AmdGpu::Liverpool::DepthBuffer depth_buffer, void RegPopup::SetData(AmdGpu::Liverpool::DepthBuffer depth_buffer,
AmdGpu::Liverpool::DepthControl depth_control, u32 batch_id) { AmdGpu::Liverpool::DepthControl depth_control, u32 batch_id) {
this->data = std::make_tuple(depth_buffer, depth_control); this->data = std::make_tuple(depth_buffer, depth_control);
this->title = fmt::format("Batch #{} Depth", batch_id); this->title = fmt::format("Batch #{} Depth###reg_popup_%d", batch_id, id);
} }
void RegPopup::Draw() { void RegPopup::Draw(bool auto_resize) {
if (Begin(title.c_str(), &open, flags)) {
char name[128];
snprintf(name, sizeof(name), "%s###reg_popup_%d", title.c_str(), id);
SetNextWindowSize({250.0f, 300.0f}, ImGuiCond_FirstUseEver);
if (Begin(name, &open, ImGuiWindowFlags_NoSavedSettings)) {
if (const auto* buffer = std::get_if<AmdGpu::Liverpool::ColorBuffer>(&data)) { if (const auto* buffer = std::get_if<AmdGpu::Liverpool::ColorBuffer>(&data)) {
if (auto_resize) {
SetWindowSize({589.0f, 522.0f});
KeepWindowInside();
}
DrawColorBuffer(*buffer); DrawColorBuffer(*buffer);
} else if (const auto* depth_data = std::get_if<DepthBuffer>(&data)) { } else if (const auto* depth_data = std::get_if<DepthBuffer>(&data)) {
if (auto_resize) {
SetWindowSize({404.0f, 543.0f});
KeepWindowInside();
}
DrawDepthBuffer(*depth_data); DrawDepthBuffer(*depth_data);
} }
} }
End(); End();
} }
} // namespace Core::Devtools::Widget } // namespace Core::Devtools::Widget

View File

@ -5,6 +5,8 @@
#include <variant> #include <variant>
#include <imgui.h>
#include "common/types.h" #include "common/types.h"
#include "video_core/renderer_vulkan/liverpool_to_vk.h" #include "video_core/renderer_vulkan/liverpool_to_vk.h"
@ -12,14 +14,13 @@ namespace Core::Devtools::Widget {
class RegPopup { class RegPopup {
int id; int id;
ImGuiWindowFlags flags{ImGuiWindowFlags_NoSavedSettings};
using DepthBuffer = std::tuple<AmdGpu::Liverpool::DepthBuffer, AmdGpu::Liverpool::DepthControl>; using DepthBuffer = std::tuple<AmdGpu::Liverpool::DepthBuffer, AmdGpu::Liverpool::DepthControl>;
std::variant<AmdGpu::Liverpool::ColorBuffer, DepthBuffer> data; std::variant<AmdGpu::Liverpool::ColorBuffer, DepthBuffer> data;
std::string title{}; std::string title{};
void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer);
static void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer); static void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer);
static void DrawDepthBuffer(const DepthBuffer& depth_data); static void DrawDepthBuffer(const DepthBuffer& depth_data);
@ -34,7 +35,7 @@ public:
void SetData(AmdGpu::Liverpool::DepthBuffer depth_buffer, void SetData(AmdGpu::Liverpool::DepthBuffer depth_buffer,
AmdGpu::Liverpool::DepthControl depth_control, u32 batch_id); AmdGpu::Liverpool::DepthControl depth_control, u32 batch_id);
void Draw(); void Draw(bool auto_resize = false);
}; };
} // namespace Core::Devtools::Widget } // namespace Core::Devtools::Widget

View File

@ -113,6 +113,7 @@ void RegView::DrawRegs() {
auto& pop = extra_reg_popup.emplace_back(); auto& pop = extra_reg_popup.emplace_back();
pop.SetData(args...); pop.SetData(args...);
pop.open = true; pop.open = true;
pop.Draw(true);
} else if (last_selected_cb == cb && default_reg_popup.open) { } else if (last_selected_cb == cb && default_reg_popup.open) {
default_reg_popup.open = false; default_reg_popup.open = false;
} else { } else {
@ -120,10 +121,9 @@ void RegView::DrawRegs() {
default_reg_popup.SetData(args...); default_reg_popup.SetData(args...);
if (!default_reg_popup.open) { if (!default_reg_popup.open) {
default_reg_popup.open = true; default_reg_popup.open = true;
auto popup_pos = const auto pos = GImGui->LastItemData.Rect.Max + ImVec2(5.0f, 0.0f);
GetCurrentContext()->LastItemData.Rect.Max + ImVec2(5.0f, 0.0f); SetNextWindowPos(pos, ImGuiCond_Always);
SetNextWindowPos(popup_pos, ImGuiCond_Always); default_reg_popup.Draw(true);
default_reg_popup.Draw();
} }
} }
}; };

View File

@ -41,7 +41,7 @@ inline void KeepWindowInside(ImVec2 display_size = GetIO().DisplaySize) {
SetWindowPos(ImMax(cur_pos, ImVec2(0.0f, 0.0f))); SetWindowPos(ImMax(cur_pos, ImVec2(0.0f, 0.0f)));
return; return;
} }
const auto cur_size = GetWindowSize(); const auto cur_size = GetCurrentWindowRead()->SizeFull;
const auto bottom_right = cur_pos + cur_size; const auto bottom_right = cur_pos + cur_size;
if (bottom_right.x > display_size.x || bottom_right.y > display_size.y) { if (bottom_right.x > display_size.x || bottom_right.y > display_size.y) {
const auto max_pos = display_size - cur_size; const auto max_pos = display_size - cur_size;