Update README to use GitHub Actions Build Status
[Mograsim.git] / plugins / net.mograsim.logic.model / src / net / mograsim / logic / model / model / components / atomic / ModelFixedOutput.java
index 1d3bb1e..1d70458 100644 (file)
@@ -6,7 +6,6 @@ import org.eclipse.swt.graphics.Color;
 
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.types.BitVectorFormatter;
@@ -19,13 +18,15 @@ import net.mograsim.logic.model.modeladapter.componentadapters.FixedOutputAdapte
 import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
 import net.mograsim.logic.model.util.JsonHandler;
+import net.mograsim.logic.model.util.TextRenderingHelper;
 import net.mograsim.preferences.Preferences;
 
 public class ModelFixedOutput extends ModelComponent
 {
-       private static final double width = 20;
-       private static final double height = 20;
+       private static final double width = 10;
+       private static final double height = 10;
        private static final double fontHeight = 5;
+       private static final double textMargin = 0.5;
 
        public final BitVector bits;
 
@@ -58,15 +59,14 @@ public class ModelFixedOutput extends ModelComponent
                if (foreground != null)
                        gc.setForeground(foreground);
                gc.drawRectangle(getBounds());
-               String label = BitVectorFormatter.formatAsString(bits);
+               String label = BitVectorFormatter.formatAsString(bits, false);
                Font oldFont = gc.getFont();
                Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
                gc.setFont(labelFont);
-               Point textExtent = gc.textExtent(label);
                Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
                if (textColor != null)
                        gc.setForeground(textColor);
-               gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
+               TextRenderingHelper.drawTextFitting(gc, label, getBounds(), textMargin, true);
                gc.setFont(oldFont);
        }