61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
package speiger.src.coreengine.rendering.gui.components;
|
|
|
|
import speiger.src.coreengine.rendering.gui.GuiComponent;
|
|
import speiger.src.coreengine.rendering.gui.helper.Align;
|
|
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
|
|
import speiger.src.coreengine.rendering.gui.helper.constrains.ParentConstrain;
|
|
|
|
public class TabbedWindowComponent extends WindowComponent
|
|
{
|
|
|
|
public TabbedWindowComponent(float x, float y, float width, float height)
|
|
{
|
|
super(x, y, width, height, DEFAULT_FLAGS, "Test");
|
|
}
|
|
|
|
@Override
|
|
public void init()
|
|
{
|
|
super.init();
|
|
addChild(new Tab("Testing My theory with the full lenght text"), null, null, new ParentConstrain(), null);
|
|
}
|
|
|
|
public static class Tab extends GuiComponent
|
|
{
|
|
String name;
|
|
float width = -1F;
|
|
boolean closeable;
|
|
TextComponent comp;
|
|
|
|
public Tab(String name)
|
|
{
|
|
super(0F, 7F, 100F, 10F);
|
|
this.name = name;
|
|
comp = new TextComponent(name).setTextScale(0.4F).singleLine(true).horizontal(Align.LEFT_TOP);
|
|
}
|
|
|
|
@Override
|
|
public void init()
|
|
{
|
|
width = getFont().width(name);
|
|
addChild(comp, Constrains.parent());
|
|
}
|
|
|
|
@Override
|
|
protected void repaint()
|
|
{
|
|
String s = name;
|
|
float scale = comp.getTextScale();
|
|
float width = getFont().width(s)*scale;
|
|
float desiredWidth = getBox().getBaseWidth();
|
|
if(width > desiredWidth) {
|
|
while(getFont().width(s+"...") * scale > desiredWidth) {
|
|
s = s.substring(0, s.length()-1);
|
|
}
|
|
comp.setText(s+"...");
|
|
return;
|
|
}
|
|
comp.setText(s);
|
|
}
|
|
}
|
|
} |