Fixed display of numbers in list watchers

Numbers are now rounded to three decimal places like they are in variable watchers.
This commit is contained in:
Nathan Dinsmore 2014-05-27 16:04:10 -04:00
parent b858d029dc
commit ab09998c46
2 changed files with 11 additions and 7 deletions

View file

@ -417,7 +417,7 @@ public class ListWatcher extends Sprite {
var cellW:int = cellPane.width - cellX - 1;
var nextY:int = 0;
for (var i:int = firstVisibleIndex; i < contents.length; i++) {
var s:String = contents[i];
var s:String = Watcher.formatValue(contents[i]);
if (limitedView && (s.length > 8)) s = s.slice(0, 8) + '...';
var cell:ListCell = allocateCell(s, cellW);
cell.x = cellX;

View file

@ -40,8 +40,16 @@ import flash.display.*;
public class Watcher extends Sprite implements DragClient {
private static const precision:Number = 1000;
public static function formatValue(value:*):String {
if (value is Number && Math.abs(value) > 0.001) {
// show at most N digits after the decimal point
value = Math.round(value * precision) / precision;
}
return '' + value;
}
private const format:TextFormat = new TextFormat(CSS.font, 11, 0, true);
private const precision:Number = 1000;
private const NORMAL_MODE:int = 1;
private const LARGE_MODE:int = 2;
@ -188,11 +196,7 @@ public class Watcher extends Sprite implements DragClient {
}
private function showValue(value:*):void {
if ((value is Number) && (Math.abs(value) > 0.001)) {
// show at most N digits after the decimal point
value = Math.round(value * precision) / precision;
}
readout.setContents(value.toString());
readout.setContents(formatValue(value));
fixLayout();
}