diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index 71518a2dda83..2427101cb7b5 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -45,23 +45,21 @@ CodeViewWidget::CodeViewWidget() setSelectionBehavior(QAbstractItemView::SelectRows); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - for (int i = 0; i < columnCount(); i++) - { - horizontalHeader()->setSectionResizeMode(i, QHeaderView::Fixed); - } + setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); verticalHeader()->hide(); horizontalHeader()->hide(); - horizontalHeader()->setStretchLastSection(true); setFont(Settings::Instance().GetDebugFont()); - Update(); + FontBasedSizing(); connect(this, &CodeViewWidget::customContextMenuRequested, this, &CodeViewWidget::OnContextMenu); connect(this, &CodeViewWidget::itemSelectionChanged, this, &CodeViewWidget::OnSelectionChanged); connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &QWidget::setFont); + connect(&Settings::Instance(), &Settings::DebugFontChanged, this, + &CodeViewWidget::FontBasedSizing); + connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] { m_address = PC; Update(); @@ -82,6 +80,16 @@ static u32 GetBranchFromAddress(u32 addr) return std::stoul(hex, nullptr, 16); } +void CodeViewWidget::FontBasedSizing() +{ + const QFontMetrics fm(Settings::Instance().GetDebugFont()); + const int rowh = fm.height() + 1; + verticalHeader()->setMaximumSectionSize(rowh); + horizontalHeader()->setMinimumSectionSize(rowh + 5); + setColumnWidth(0, rowh + 5); + Update(); +} + void CodeViewWidget::Update() { if (m_updating) @@ -98,8 +106,11 @@ void CodeViewWidget::Update() setRowCount(rows); + const QFontMetrics fm(Settings::Instance().GetDebugFont()); + const int rowh = fm.height() + 1; + for (int i = 0; i < rows; i++) - setRowHeight(i, 24); + setRowHeight(i, rowh); u32 pc = PowerPC::ppcState.pc; @@ -122,9 +133,17 @@ void CodeViewWidget::Update() std::string param = (split == std::string::npos ? "" : disas.substr(split + 1)); std::string desc = PowerPC::debug_interface.GetDescription(addr); - auto* ins_item = new QTableWidgetItem(QString::fromStdString(ins)); - auto* param_item = new QTableWidgetItem(QString::fromStdString(param)); - auto* description_item = new QTableWidgetItem(QString::fromStdString(desc)); + // Adds whitespace and a minimum size to ins and param. Helps to prevent frequent resizing while + // scrolling. + const QString ins_formatted = + QStringLiteral("%1").arg(QString::fromStdString(ins), -7, QLatin1Char(' ')); + const QString param_formatted = + QStringLiteral("%1").arg(QString::fromStdString(param), -19, QLatin1Char(' ')); + const QString desc_formatted = QStringLiteral("%1 ").arg(QString::fromStdString(desc)); + + auto* ins_item = new QTableWidgetItem(ins_formatted); + auto* param_item = new QTableWidgetItem(param_formatted); + auto* description_item = new QTableWidgetItem(desc_formatted); for (auto* item : {bp_item, addr_item, ins_item, param_item, description_item}) { @@ -162,8 +181,9 @@ void CodeViewWidget::Update() if (PowerPC::debug_interface.IsBreakpoint(addr)) { - bp_item->setData(Qt::DecorationRole, - Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(24, 24))); + bp_item->setData( + Qt::DecorationRole, + Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(rowh - 2, rowh - 2))); } setItem(i, 0, bp_item); @@ -179,8 +199,6 @@ void CodeViewWidget::Update() } resizeColumnsToContents(); - setColumnWidth(0, 24 + 5); - g_symbolDB.FillInCallers(); repaint(); diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h index 758fdceebd96..bf191649e0a7 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h @@ -30,6 +30,8 @@ class CodeViewWidget : public QTableWidget u32 GetContextAddress() const; void SetAddress(u32 address, SetAddressUpdate update); + // Set tighter row height. Set BP column sizing. This needs to run when font type changes. + void FontBasedSizing(); void Update(); void ToggleBreakpoint();