Better Alignment
-Created some Layouts to properly adjust where things go -LayoutEdges for text on the same row on opposite sides of the screen -LayoutColumn for a non-max width column -More accessible version string
This commit is contained in:
parent
0f0a94811f
commit
5af1b7309d
1
logs/game.log
Normal file
1
logs/game.log
Normal file
@ -0,0 +1 @@
|
||||
22:26:25.948 [Music Thread ] WARN ru.windcorp.progressia.test.TestMusicPlayer > No music found
|
@ -23,6 +23,10 @@ import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
|
||||
/** Class for a traditional button that gets clicked to activate
|
||||
*
|
||||
* @author opfromthestart
|
||||
*/
|
||||
public class Button extends BasicButton {
|
||||
|
||||
public Button(String name, String label, Font labelFont) {
|
||||
|
@ -27,8 +27,8 @@ import ru.windcorp.progressia.client.graphics.gui.Layout;
|
||||
|
||||
public class LayoutAlign implements Layout {
|
||||
|
||||
private final int margin;
|
||||
private double alignX, alignY;
|
||||
protected final int margin;
|
||||
protected double alignX, alignY;
|
||||
|
||||
public LayoutAlign(double alignX, double alignY, int margin) {
|
||||
this.alignX = alignX;
|
||||
|
@ -0,0 +1,60 @@
|
||||
package ru.windcorp.progressia.client.graphics.gui.layout;
|
||||
|
||||
import glm.vec._2.i.Vec2i;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Layout;
|
||||
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
public class LayoutEdges implements Layout {
|
||||
|
||||
private int margin;
|
||||
|
||||
public LayoutEdges(int margin) {
|
||||
this.margin = margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layout(Component c) {
|
||||
for (int i=0;i<2;i++)
|
||||
{
|
||||
Component child = c.getChild(i);
|
||||
|
||||
Vec2i size = child.getPreferredSize();
|
||||
|
||||
int cWidth = c.getWidth() - 2 * margin;
|
||||
int cHeight = c.getHeight() - 2 * margin;
|
||||
|
||||
size.x = min(size.x, cWidth);
|
||||
size.y = min(size.y, cHeight);
|
||||
|
||||
if (i==0) {
|
||||
child.setBounds(
|
||||
c.getX() + margin,
|
||||
c.getY(),
|
||||
size
|
||||
);
|
||||
} else {
|
||||
child.setBounds(
|
||||
1920 - size.x - margin,
|
||||
c.getY(),
|
||||
size
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2i calculatePreferredSize(Component c) {
|
||||
Vec2i result = new Vec2i(1920,0);
|
||||
c.getChildren().stream()
|
||||
.map(child -> child.getPreferredSize())
|
||||
.forEach(size -> {
|
||||
result.y = max(Math.abs(size.y), result.y);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
@ -22,8 +22,13 @@ public class CubeComponent extends Component {
|
||||
|
||||
private int size = 400;
|
||||
|
||||
public CubeComponent(String name) {
|
||||
public CubeComponent(String name)
|
||||
{
|
||||
this(name, 400);
|
||||
}
|
||||
public CubeComponent(String name, int size) {
|
||||
super(name);
|
||||
this.size = size;
|
||||
transforms = new Mat4[6];
|
||||
normals = new Vec4[6];
|
||||
setPreferredSize((int) Math.ceil(r3*size),(int) Math.ceil(r3*size));
|
||||
|
@ -30,6 +30,8 @@ import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||
|
||||
public class LayerAbout extends GUILayer {
|
||||
|
||||
public static String version = "pre-alpha 3";
|
||||
|
||||
public LayerAbout() {
|
||||
super("LayerAbout", new LayoutAlign(1, 1, 5));
|
||||
|
||||
@ -50,7 +52,7 @@ public class LayerAbout extends GUILayer {
|
||||
new Label(
|
||||
"Version",
|
||||
font,
|
||||
new MutableStringLocalized("LayerAbout.Version").format("pre-alpha 3")
|
||||
new MutableStringLocalized("LayerAbout.Version").format(version)
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||
import ru.windcorp.progressia.client.graphics.gui.TextureComponent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutEdges;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
|
||||
import ru.windcorp.progressia.client.localization.MutableString;
|
||||
@ -33,11 +34,28 @@ public class LayerTitle extends Background {
|
||||
public LayerTitle(String name) {
|
||||
super(name, new LayoutAlign(0, 1f, 15), SimpleTextures.get("title/background"));
|
||||
Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15));
|
||||
Group buttonContent = new Group("Layer" + name + ".ButtonGroup", new LayoutVertical(15));
|
||||
Group info = new Group("Layer"+name+".InfoGroup", new LayoutEdges(30));
|
||||
Group buttonContent = new Group("Layer" + name + ".ButtonGroup", new LayoutColumn(15, 320));
|
||||
|
||||
Font titleFont = new Font().deriveBold().withColor(Colors.BLUE).withAlign(0.5f);
|
||||
content.addChild(new TextureComponent(name + ".Title", SimpleTextures.get("title/progressia")));
|
||||
|
||||
info.addChild(new Label(
|
||||
"About",
|
||||
titleFont,
|
||||
new MutableStringLocalized("LayerAbout.Title")
|
||||
)
|
||||
);
|
||||
|
||||
info.addChild(
|
||||
new Label(
|
||||
"Version",
|
||||
titleFont,
|
||||
new MutableStringLocalized("LayerAbout.Version").format(LayerAbout.version)
|
||||
)
|
||||
);
|
||||
content.addChild(info);
|
||||
|
||||
Font buttonFont = titleFont.deriveNotBold();
|
||||
MutableString playText = new MutableStringLocalized("Layer" + name + ".Play");
|
||||
buttonContent.addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(this::startGame));
|
||||
@ -57,7 +75,7 @@ public class LayerTitle extends Background {
|
||||
getRoot().addChild(content);
|
||||
buttonContent.setPreferredSize(500, 1000);
|
||||
|
||||
CubeComponent cube = new CubeComponent(name+".Cube");
|
||||
CubeComponent cube = new CubeComponent(name+".Cube",300);
|
||||
|
||||
getRoot().addChild(cube);
|
||||
}
|
||||
|
36
src/main/java/ru/windcorp/progressia/test/LayoutColumn.java
Normal file
36
src/main/java/ru/windcorp/progressia/test/LayoutColumn.java
Normal file
@ -0,0 +1,36 @@
|
||||
package ru.windcorp.progressia.test;
|
||||
|
||||
import glm.vec._2.i.Vec2i;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
|
||||
public class LayoutColumn extends LayoutVertical {
|
||||
|
||||
protected int maxWidth;
|
||||
private int margin;
|
||||
|
||||
public LayoutColumn(int gap, int maxWidth)
|
||||
{
|
||||
super(gap);
|
||||
this.maxWidth = maxWidth;
|
||||
margin = gap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layout(Component c) {
|
||||
int x = c.getX() + margin,
|
||||
y = c.getY() + c.getHeight();
|
||||
|
||||
synchronized (c.getChildren()) {
|
||||
for (Component child : c.getChildren()) {
|
||||
|
||||
int height = child.getPreferredSize().y;
|
||||
y -= margin + height;
|
||||
child.setBounds(x, y, maxWidth, height);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user