Skip to content

Commit

Permalink
UI: Fix text stacking in paused indicator
Browse files Browse the repository at this point in the history
Currently, the paused indicator is never undone, instead relying on the
update timer to eventually erase it away when the recording duration is
updated. If the user spams pause fast enough, the indicator will stack
several times before it is erased - especially if the unpaused branch in
the update timer never has a chance to run.

Instead of mutating the recordTime text on pause and requiring an undo,
extract the UI update to a separate function which computes the full
text based on the current state. Call this function when pause is
toggled, thereby forcing an accurate UI update that either does or does
not incude the paused text.

An added benefit is that the paused indicator now disappears
immediately.
  • Loading branch information
Aleksbgbg authored and Lain-B committed May 4, 2024
1 parent ec31c7e commit bad7b78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
35 changes: 22 additions & 13 deletions UI/window-basic-status-bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,6 @@ void OBSBasicStatusBar::UpdateRecordTime()
if (!paused) {
totalRecordSeconds++;

int seconds = totalRecordSeconds % 60;
int totalMinutes = totalRecordSeconds / 60;
int minutes = totalMinutes % 60;
int hours = totalMinutes / 60;

QString text = QString::asprintf("%02d:%02d:%02d", hours,
minutes, seconds);

statusWidget->ui->recordTime->setText(text);
if (recordOutput && !statusWidget->ui->recordTime->isEnabled())
statusWidget->ui->recordTime->setDisabled(false);
} else {
Expand All @@ -322,6 +313,24 @@ void OBSBasicStatusBar::UpdateRecordTime()

streamPauseIconToggle = !streamPauseIconToggle;
}

UpdateRecordTimeLabel();
}

void OBSBasicStatusBar::UpdateRecordTimeLabel()
{
int seconds = totalRecordSeconds % 60;
int totalMinutes = totalRecordSeconds / 60;
int minutes = totalMinutes % 60;
int hours = totalMinutes / 60;

QString text =
QString::asprintf("%02d:%02d:%02d", hours, minutes, seconds);
if (os_atomic_load_bool(&recording_paused)) {
text += QStringLiteral(" (PAUSED)");
}

statusWidget->ui->recordTime->setText(text);
}

void OBSBasicStatusBar::UpdateDroppedFrames()
Expand Down Expand Up @@ -547,21 +556,21 @@ void OBSBasicStatusBar::RecordingStopped()

void OBSBasicStatusBar::RecordingPaused()
{
QString text = statusWidget->ui->recordTime->text() +
QStringLiteral(" (PAUSED)");
statusWidget->ui->recordTime->setText(text);

if (recordOutput) {
statusWidget->ui->recordIcon->setPixmap(recordingPausePixmap);
streamPauseIconToggle = true;
}

UpdateRecordTimeLabel();
}

void OBSBasicStatusBar::RecordingUnpaused()
{
if (recordOutput) {
statusWidget->ui->recordIcon->setPixmap(recordingActivePixmap);
}

UpdateRecordTimeLabel();
}

static QPixmap GetPixmap(const QString &filename)
Expand Down
1 change: 1 addition & 0 deletions UI/window-basic-status-bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class OBSBasicStatusBar : public QStatusBar {
void UpdateBandwidth();
void UpdateStreamTime();
void UpdateRecordTime();
void UpdateRecordTimeLabel();
void UpdateDroppedFrames();

static void OBSOutputReconnect(void *data, calldata_t *params);
Expand Down

0 comments on commit bad7b78

Please sign in to comment.