import net.mograsim.logic.ui.modeladapter.componentadapters.NoLogicAdapter;\r
import net.mograsim.preferences.Preferences;\r
\r
+//TODO clean size calculation mess\r
public class TextComponent extends GUIComponent\r
{\r
private final String text;\r
- private Point textExtent;\r
\r
public TextComponent(ViewModelModifiable model, String text)\r
{\r
super(model);\r
this.text = text;\r
+ // If size is unset, it defaults to 0, which could prohibit this component from being rendered, which would prohibit the size being\r
+ // set to a better guess\r
+ setSize(1, 1);\r
}\r
\r
@Override\r
public void render(GeneralGC gc, Rectangle visibleRegion)\r
{\r
- textExtent = gc.textExtent(text);\r
+ Point textExtent = gc.textExtent(text);\r
+ setSize(textExtent.x, textExtent.y);\r
+\r
Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");\r
if (textColor != null)\r
gc.setForeground(textColor);\r
- gc.drawText(text, getPosX() - textExtent.x / 2, getPosY() - textExtent.y / 2, true);\r
- }\r
-\r
- @Override\r
- public Rectangle getBounds()\r
- {\r
- if (textExtent == null)\r
- return super.getBounds();\r
- return new Rectangle(getPosX() - textExtent.x / 2, getPosY() - textExtent.y / 2, textExtent.x, textExtent.y);\r
+ gc.drawText(text, getPosX(), getPosY(), true);\r
}\r
\r
static\r
{\r
- ViewLogicModelAdapter.addComponentAdapter(NoLogicAdapter.forClass(TextComponent.class));\r
+ ViewLogicModelAdapter.addComponentAdapter(new NoLogicAdapter<>(TextComponent.class));\r
}\r
}\r