projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TextComponent no longer overrides getBounds but rather calls setSize()
[Mograsim.git]
/
net.mograsim.logic.ui
/
src
/
net
/
mograsim
/
logic
/
ui
/
model
/
components
/
TextComponent.java
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
e5a6347
..
b0138aa
100644
(file)
--- 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
@@
-10,35
+10,32
@@
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.NoLogicAdapter;
import net.mograsim.preferences.Preferences;
import net.mograsim.logic.ui.modeladapter.componentadapters.NoLogicAdapter;
import net.mograsim.preferences.Preferences;
+//TODO clean size calculation mess
public class TextComponent extends GUIComponent
{
private final String text;
public class TextComponent extends GUIComponent
{
private final String text;
- private Point textExtent;
public TextComponent(ViewModelModifiable model, String text)
{
super(model);
this.text = text;
public TextComponent(ViewModelModifiable model, String text)
{
super(model);
this.text = text;
+ // If size is unset, it defaults to 0, which could prohibit this component from being rendered, which would prohibit the size being
+ // set to a better guess
+ setSize(1, 1);
}
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
{
}
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
{
- textExtent = gc.textExtent(text);
+ Point textExtent = gc.textExtent(text);
+ setSize(textExtent.x, textExtent.y);
+
Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(text, getPosX(), getPosY(), true);
}
Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
if (textColor != null)
gc.setForeground(textColor);
gc.drawText(text, getPosX(), getPosY(), true);
}
- @Override
- public Rectangle getBounds()
- {
- if (textExtent == null)
- return super.getBounds();
- return new Rectangle(getPosX(), getPosY(), textExtent.x, textExtent.y);
- }
-
static
{
ViewLogicModelAdapter.addComponentAdapter(new NoLogicAdapter<>(TextComponent.class));
static
{
ViewLogicModelAdapter.addComponentAdapter(new NoLogicAdapter<>(TextComponent.class));