From: Daniel Kirschten Date: Sun, 1 Sep 2019 16:25:43 +0000 (+0200) Subject: TextComponent now only calculates its size once => speedup X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=5ce55d9c7ebe3ae1d294ccf7d1cb3588324f3d1d;p=Mograsim.git TextComponent now only calculates its size once => speedup --- diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java index 4161406a..e00dbb92 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java @@ -20,6 +20,7 @@ import net.mograsim.preferences.Preferences; public class TextComponent extends GUIComponent { private final String text; + private boolean calculatedSize; public TextComponent(ViewModelModifiable model, String text) { @@ -38,9 +39,12 @@ public class TextComponent extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - Point textExtent = gc.textExtent(text); - if (getWidth() != textExtent.x || getHeight() != textExtent.y) + if (!calculatedSize) + { + calculatedSize = true; + Point textExtent = gc.textExtent(text); setSize(textExtent.x, textExtent.y); + } Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); if (textColor != null)