X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FTextComponent.java;fp=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FTextComponent.java;h=18f4384f9f58e093351493449f4bf20008e0a69b;hb=838c017db855038424e4948e1d33898c8dda023f;hp=871d4f9d41ec7efa9215cd65acb00f451e566426;hpb=c6ad3a18e8a437d7b131b203267fe2723708641f;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/TextComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/TextComponent.java index 871d4f9d..18f4384f 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/TextComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/TextComponent.java @@ -13,6 +13,7 @@ import net.mograsim.preferences.Preferences; public class TextComponent extends GUIComponent { private final String text; + private Point textExtent; public TextComponent(ViewModelModifiable model, String text) { @@ -23,13 +24,21 @@ public class TextComponent extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - Point textExtent = gc.textExtent(text); + textExtent = gc.textExtent(text); Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text"); if (textColor != null) gc.setForeground(textColor); gc.drawText(text, getPosX() - textExtent.x / 2, getPosY() - textExtent.y / 2, true); } + @Override + public Rectangle getBounds() + { + if (textExtent == null) + return super.getBounds(); + return new Rectangle(getPosX() - textExtent.x / 2, getPosY() - textExtent.y / 2, textExtent.x, textExtent.y); + } + static { ViewLogicModelAdapter.addComponentAdapter(NoLogicAdapter.forClass(TextComponent.class));