Skip to content

Commit

Permalink
feat(levels): move values to monospace font
Browse files Browse the repository at this point in the history
The level values are moving left to right as the digits take more or less space in the default font. To stabilize these labels, we use a monospace font by switching to Markdown formatting.
  • Loading branch information
tlecomte committed Nov 3, 2024
1 parent 14663c1 commit 78eb24b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions friture/Levels.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Rectangle {
// but do not bind directly to their widths
// to avoid frequent costly resizes
//due to level changes or variations in the width of the font characters
implicitWidth: 2 + fontMetrics.boundingRect(level_view_model.two_channels ? "2: -88.8" : "-88:8").width
implicitWidth: 4 + fontMetrics.boundingRect(level_view_model.two_channels ? "2: -88.8" : "-88:8").width

FontMetrics {
id: fontMetrics
Expand All @@ -34,8 +34,8 @@ Rectangle {

Text {
id: peakValues
textFormat: Text.PlainText
text: level_view_model.two_channels ? "1: " + level_to_text(level_view_model.level_data_slow.level_max) + "\n2: " + level_to_text(level_view_model.level_data_slow_2.level_max) : level_to_text(level_view_model.level_data_slow.level_max)
textFormat: Text.MarkdownText
text: level_view_model.two_channels ? "1: " + level_to_text(level_view_model.level_data_slow.level_max) + "<br />2: " + level_to_text(level_view_model.level_data_slow_2.level_max) : level_to_text(level_view_model.level_data_slow.level_max)
font.pointSize: 14
font.bold: true
verticalAlignment: Text.AlignBottom
Expand All @@ -56,8 +56,8 @@ Rectangle {

Text {
id: rmsValues
textFormat: Text.PlainText
text: level_view_model.two_channels ? "1: " + level_to_text(level_view_model.level_data_slow.level_rms) + "\n2: " + level_to_text(level_view_model.level_data_slow_2.level_rms) : level_to_text(level_view_model.level_data_slow.level_rms)
textFormat: Text.MarkdownText
text: level_view_model.two_channels ? "1: " + level_to_text(level_view_model.level_data_slow.level_rms) + "<br />2: " + level_to_text(level_view_model.level_data_slow_2.level_rms) : level_to_text(level_view_model.level_data_slow.level_rms)
font.pointSize: 14
font.bold: true
verticalAlignment: Text.AlignBottom
Expand Down Expand Up @@ -85,9 +85,9 @@ Rectangle {

function level_to_text(dB) {
if (dB < -150.) {
return "-Inf";
return "`-Inf`";
}

return dB.toFixed(1);
return "`" + dB.toFixed(1) + "`";
}
}

0 comments on commit 78eb24b

Please sign in to comment.