Skip to content

Commit e5d92c3

Browse files
Scale problem badges for very small screens.
1 parent 07f819e commit e5d92c3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

webapp/public/style_domjudge.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ del {
220220
overflow: hidden;
221221
}
222222

223+
.mobile-problem-badges {
224+
position: relative;
225+
display: block;
226+
white-space: nowrap;
227+
}
228+
223229
.toolong:after {
224230
content: "";
225231
width: 30%;

webapp/templates/partials/scoreboard_table.html.twig

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,12 @@
471471
</tr>
472472
<tr style="height: 32px;">
473473
<td colspan="3" class="text-end">
474-
{% for problem in problems %}
475-
{% set matrixItem = scoreboard.matrix[score.team.teamid][problem.probid] %}
476-
{{ problem | problemBadgeMaybe(matrixItem) }}
477-
{% endfor %}
474+
<span class="mobile-problem-badges me-2 ms-2">
475+
{% for problem in problems %}
476+
{% set matrixItem = scoreboard.matrix[score.team.teamid][problem.probid] %}
477+
{{ problem | problemBadgeMaybe(matrixItem) }}
478+
{% endfor %}
479+
</span>
478480
</td>
479481
</tr>
480482
{% endfor %}
@@ -598,18 +600,31 @@
598600
if (mobileScoreboard.offsetWidth === 0) {
599601
return;
600602
}
601-
const windowWidth = window.screen.width;
602-
const teamNameMaxWidth = Math.max(100, windowWidth - 150);
603+
const windowWidth = document.body.offsetWidth;
604+
const teamNameMaxWidth = Math.max(10, windowWidth - 150);
605+
const problemBadgesMaxWidth = Math.max(10, windowWidth - 78);
603606
document.querySelectorAll(".mobile-scoreboard .forceWidth:not(.toolong)").forEach(el => {
604-
console.warn(el.innerText);
605-
console.warn(`teamNameMaxWidth: ${teamNameMaxWidth}, el.offsetWidth: ${el.offsetWidth}`);
607+
el.classList.remove("toolong");
606608
el.style.maxWidth = teamNameMaxWidth + 'px';
607609
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
608610
el.classList.add("toolong");
609611
} else {
610612
el.classList.remove("toolong");
611613
}
612614
});
615+
document.querySelectorAll(".mobile-scoreboard .mobile-problem-badges:not(.toolong)").forEach(el => {
616+
el.classList.remove("toolong");
617+
el.style.maxWidth = problemBadgesMaxWidth + 'px';
618+
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
619+
el.classList.add("toolong");
620+
const scale = el.offsetWidth / el.scrollWidth;
621+
const offset = -1 * (el.scrollWidth - el.offsetWidth) / 2;
622+
el.style.transform = `scale(${scale}) translateX(${offset}px)`;
623+
} else {
624+
el.classList.remove("toolong");
625+
el.style.transform = null;
626+
}
627+
});
613628
};
614629
window.addEventListener('resize', () => {
615630
resizeMobileTeamNames();

0 commit comments

Comments
 (0)