Browse Source

Make the Stats bar minimalist. Add a button to expand the details

customisations
alemart 9 months ago
parent
commit
01f8967308
1 changed files with 45 additions and 16 deletions
  1. 45
    16
      src/ui/stats-panel.ts

+ 45
- 16
src/ui/stats-panel.ts View File

25
 import { Viewport } from '../core/viewport';
25
 import { Viewport } from '../core/viewport';
26
 import { Tracker } from '../trackers/tracker';
26
 import { Tracker } from '../trackers/tracker';
27
 import { Source } from '../sources/source';
27
 import { Source } from '../sources/source';
28
-import { Utils, Nullable } from '../utils/utils';
28
+import { Nullable } from '../utils/utils';
29
 import AR from '../main';
29
 import AR from '../main';
30
 
30
 
31
 
31
 
39
     'high-performance': '&#x26A1'
39
     'high-performance': '&#x26A1'
40
 });
40
 });
41
 
41
 
42
+/** Button icons (atlas) */
43
+const BUTTON_ICONS = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAQCAYAAAB3AH1ZAAAAVUlEQVRIS2NkGGDAOMD2M4w6YDQE8IbAfyBgBAJSEipIDy712MzCaTiyQdRwBC4zsDoAmy8ocQQ+vRgOIDUI8UUPMVFIUvySkhaIVTvqgNEQGPAQAABSNiARgz5LggAAAABJRU5ErkJggg==';
44
+
42
 
45
 
43
 
46
 
44
 /**
47
 /**
151
             lout.innerText = trackerStats;
154
             lout.innerText = trackerStats;
152
         }
155
         }
153
 
156
 
154
-        const ldraw = this._label('_ar_draw');
155
-        if(ldraw !== null) {
157
+        const lview = this._label('_ar_view');
158
+        if(lview !== null) {
156
             const size = viewport.virtualSize;
159
             const size = viewport.virtualSize;
157
-            ldraw.innerText = `${size.width}x${size.height} rendering`;
160
+            lview.innerText = `${size.width}x${size.height} rendering`;
158
         }
161
         }
159
     }
162
     }
160
 
163
 
209
     private _createTitle(): HTMLElement
212
     private _createTitle(): HTMLElement
210
     {
213
     {
211
         const title = document.createElement('div');
214
         const title = document.createElement('div');
215
+        const button = document.createElement('button');
212
 
216
 
217
+        title.style.display = 'flex';
213
         title.style.backgroundColor = '#7e56c2';
218
         title.style.backgroundColor = '#7e56c2';
214
         title.style.color = 'white';
219
         title.style.color = 'white';
215
         title.style.fontFamily = 'monospace';
220
         title.style.fontFamily = 'monospace';
216
         title.style.fontSize = '14px';
221
         title.style.fontSize = '14px';
217
         title.style.fontWeight = 'bold';
222
         title.style.fontWeight = 'bold';
218
-        title.style.padding = '2px';
223
+        title.style.paddingRight = '4px';
219
         title.innerText = 'encantar.js ' + AR.version;
224
         title.innerText = 'encantar.js ' + AR.version;
220
 
225
 
226
+        button.style.width = '18px';
227
+        button.style.height = '18px';
228
+        button.style.marginRight = '4px';
229
+        button.style.backgroundColor = '#7e56c2';
230
+        button.style.backgroundImage = 'url(' + BUTTON_ICONS + ')';
231
+        button.style.backgroundRepeat = 'no-repeat';
232
+        button.style.backgroundPosition = '0 0';
233
+        button.style.borderWidth = '2px';
234
+        button.style.borderColor = '#b588fb #46346a #46346a #b588fb';
235
+        title.insertBefore(button, title.firstChild);
236
+
237
+        button.addEventListener('click', () => {
238
+            const container = title.parentNode;
239
+            const details = container && container.querySelector<HTMLElement>('._ar_details');
240
+
241
+            if(!details)
242
+                return;
243
+
244
+            details.hidden = !details.hidden;
245
+            button.style.backgroundPosition = details.hidden ? '0 0 ' : '-16px 0';
246
+        });
247
+
221
         return title;
248
         return title;
222
     }
249
     }
223
 
250
 
228
     private _createContent(): HTMLElement
255
     private _createContent(): HTMLElement
229
     {
256
     {
230
         const content = document.createElement('div');
257
         const content = document.createElement('div');
231
-        const print = (html: string): void => content.insertAdjacentHTML('beforeend', html);
258
+        const details = document.createElement('div');
232
 
259
 
233
         content.style.backgroundColor = 'rgba(0,0,0,0.5)';
260
         content.style.backgroundColor = 'rgba(0,0,0,0.5)';
234
         content.style.color = 'white';
261
         content.style.color = 'white';
237
         content.style.padding = '2px';
264
         content.style.padding = '2px';
238
         content.style.whiteSpace = 'pre-line';
265
         content.style.whiteSpace = 'pre-line';
239
 
266
 
240
-        // all sanitized
241
-        print('FPS: <span class="_ar_fps"></span> | ');
242
-        print('GPU: <span class="_ar_gpu"></span> ');
243
-        print('<span class="_ar_power"></span>');
267
+        details.classList.add('_ar_details');
268
+        details.hidden = true;
244
 
269
 
245
-        print('<br>');
246
-        print('IN: <span class="_ar_in"></span>');
270
+        // all sanitized
271
+        const append = (div: HTMLDivElement, html: string): void => div.insertAdjacentHTML('beforeend', html);
247
 
272
 
248
-        print('<br>');
249
-        print('OUT: <span class="_ar_out"></span>');
273
+        append(content, 'FPS: <span class="_ar_fps"></span> | ');
274
+        append(content, 'GPU: <span class="_ar_gpu"></span> ');
275
+        append(content, '<span class="_ar_power"></span>');
250
 
276
 
251
-        print('<br>');
252
-        print('VIEW: <span class="_ar_draw"></span>');
277
+        append(details, 'IN: <span class="_ar_in"></span><br>');
278
+        append(details, 'OUT: <span class="_ar_out"></span><br>');
279
+        append(details, 'VIEW: <span class="_ar_view"></span>');
253
 
280
 
281
+        // done!
282
+        content.appendChild(details);
254
         return content;
283
         return content;
255
     }
284
     }
256
 }
285
 }

Loading…
Cancel
Save