Selaa lähdekoodia

more robust ui_main window height/width for text

clementinecomputing 5 vuotta sitten
vanhempi
commit
c8b37e2e8d

+ 13 - 0
busunit/DIUv2/html/css/diustyles.css

@@ -18,6 +18,19 @@
  *
  */
 
+#ui_test {
+  position:absolute;
+  visibility:hidden;
+  height:auto;
+  width:auto;
+  white-space:nowrap;
+
+  font-size: 3vw;
+  letter-spacing: 0.125vw;
+  font-weight:bold;
+  font-family: monospace;
+}
+
 html, body {
   height: 100%;
 }

+ 4 - 0
busunit/DIUv2/html/index-ORG.html

@@ -32,6 +32,10 @@
 
   <body id='body'>
 
+    <div id='ui_test'>
+      X
+    </div>
+
     <!-- ************************* -->
     <!-- ******            ******* -->
     <!-- ******  Watchdog  ******* -->

+ 27 - 3
busunit/DIUv2/html/js/diu_ui-ORG.js

@@ -210,8 +210,6 @@ function _set_ui_watchdog(failsafe_ui, _dt) {
 function _switch_ui(to) {
   var ele;
 
-  console.log(">>>to", to);
-
   if (g_ctx.ui_change_timeoutid > 0) {
     window.clearTimeout(g_ctx.ui_change_timeoutid);
     g_ctx.ui_change_timeoutid = -1;
@@ -227,6 +225,12 @@ function _switch_ui(to) {
 
   g_ctx.current_ui = to;
 
+  if (to == "ui_main") {
+    var _x = _calculate_ui_main_status_width_height();
+    g_ctx.status_text_h = _x.n_height;
+    g_ctx.status_text_w = _x.n_width;
+  }
+
   if ((to == "ui_main") ||
       (to == "ui_login")) {
     _block_status_window(to);
@@ -893,7 +897,7 @@ function _main_message_add(msg, bg_color, text_color) {
     lines = lines.slice(n - g_ctx.status_text_h);
   }
   for (var i=0; i<lines.length; i++) {
-    html_lines.push(lines[i].slice(0,g_ctx.status_text_w));
+    html_lines.push(lines[i].slice(0,g_ctx.status_text_w-1));
 
     if (html_lines[i].match(/ACCEPT/)) {
       html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
@@ -1204,6 +1208,26 @@ function _eqnum_input(inp) {
 
 //-------------
 
+function _text_width_height() {
+  var _t = document.getElementById("ui_test");
+  console.log(">>>", _t.clientHeight, _t.clientWidth);
+}
+
+function _calculate_ui_main_status_width_height() {
+  var _t = document.getElementById("ui_test");
+  var ch_w = _t.clientWidth;
+  var ch_h = _t.clientHeight;
+
+  var _w = document.getElementById("ui_main_status");
+  var win_w = _w.clientWidth;
+  var win_h = _w.clientHeight;
+
+  var n_w = Math.floor(win_w / ch_w);
+  var n_h = Math.floor(win_h / ch_h);
+
+  return {"n_width": n_w, "n_height":n_h};
+}
+
 function init() {
 
   _init_websocket();