Skip to content

Commit 9309179

Browse files
committed
collapse down the UI for mode autodetect
I don't know if this is really better than the other way, but it *is* less real estate...
1 parent 8409e62 commit 9309179

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

web/recv.html

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,12 @@
129129

130130
/* options */
131131
#nav-container a.mode-auto,
132-
#nav-container a.mode-b,
133-
#nav-container a.mode-bm,
134-
#nav-container a.mode-4c {
132+
#nav-container a.mode-b {
135133
color: #555;
136134
}
137135

138136
#nav-container.mode-auto a.mode-auto,
139-
#nav-container.mode-b a.mode-b,
140-
#nav-container.mode-bm a.mode-bm,
141-
#nav-container.mode-4c a.mode-4c {
137+
#nav-container.mode-b a.mode-b {
142138
color: #9fa6b2;
143139
}
144140

@@ -329,7 +325,7 @@
329325

330326
#nav-content li.modesel a {
331327
display: inline-block;
332-
width: 2em;
328+
width: 4em;
333329
}
334330

335331
#nav-content li:hover {
@@ -397,11 +393,10 @@
397393
</button>
398394
<div id="nav-content" tabindex="-1">
399395
<ul>
400-
<li><a class="mode-auto" href="javascript:void(0)" onclick="Recv.setMode('Auto')">Mode auto</a></li>
401396
<li class="modesel">
402-
<a class="mode-b" href="javascript:void(0)" onclick="Recv.setMode('B')">B</a>
403-
<a class="mode-bm" href="javascript:void(0)" onclick="Recv.setMode('Bm')">Bm</a>
404-
<a class="mode-4c" href="javascript:void(0)" onclick="Recv.setMode('4C')">4C</a>
397+
<h4>Mode</h4>
398+
<a class="mode-auto" href="javascript:void(0)" onclick="Recv.setMode('Auto')">Auto</a>
399+
<a class="mode-b" id="mode-val" href="javascript:void(0)" onclick="Recv.setMode(this.textContent)">B</a>
405400
</li>
406401
<li class="small"><a href="javascript:void(0)" onclick="Recv.showDebug()">Debug</a></li>
407402
<li class="small"><a href="javascript:void(0)" onclick="Recv.toggleFullscreen()">Fullscreen</a></li>

web/recv.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -392,48 +392,45 @@ var Recv = function () {
392392
document.getElementById("nav-content").blur();
393393
},
394394

395-
setMode: function (mode_str) {
396-
let modeVal = mode_str;
397-
if (modeVal == "4C") {
398-
modeVal = 4;
399-
}
400-
else if (modeVal == "Bm") {
401-
modeVal = 67;
402-
}
403-
else if (modeVal == "B") {
404-
modeVal = 68;
395+
setMode: function (modeVal) {
396+
// these should be moved elsewhere...
397+
const modeToString = {
398+
4: "4C",
399+
8: "8C",
400+
67: "Bm",
401+
68: "B"
402+
};
403+
let modeStringToVal = {
404+
"Auto": 0
405+
};
406+
for (const val in modeToString) {
407+
modeStringToVal[modeToString[val]] = val;
405408
}
406-
else if (modeVal == "Auto") {
407-
modeVal = 0;
409+
410+
if (modeVal in modeStringToVal) {
411+
modeVal = modeStringToVal[modeVal];
408412
}
409-
// set in main thread
413+
414+
// configure wasm in main thread
410415
_mode = modeVal;
411416
if (_mode > 0) {
412417
Module._cimbard_configure_decode(_mode);
413418
Sink.allocate();
414419
}
415420

421+
// update ui
422+
if (_mode > 0) {
423+
var nav = document.getElementById("mode-val");
424+
nav.innerHTML = modeToString[_mode];
425+
}
426+
416427
var nav = document.getElementById("nav-container");
417-
if (modeVal == 4) {
418-
nav.classList.add("mode-4c");
419-
nav.classList.remove("mode-auto");
428+
if (_mode == 0) {
429+
nav.classList.add("mode-auto");
420430
nav.classList.remove("mode-b");
421-
nav.classList.remove("mode-bm");
422-
} else if (modeVal == 68) {
431+
} else {
423432
nav.classList.add("mode-b");
424433
nav.classList.remove("mode-auto");
425-
nav.classList.remove("mode-bm");
426-
nav.classList.remove("mode-4c");
427-
} else if (modeVal == 67) {
428-
nav.classList.add("mode-bm");
429-
nav.classList.remove("mode-auto");
430-
nav.classList.remove("mode-b");
431-
nav.classList.remove("mode-4c");
432-
} else {
433-
nav.classList.add("mode-auto");
434-
nav.classList.remove("mode-b");
435-
nav.classList.remove("mode-bm");
436-
nav.classList.remove("mode-4c");
437434
}
438435
},
439436

0 commit comments

Comments
 (0)