Panel now has decorations; functionality moved to new superclass Group
This commit is contained in:
parent
737b495fc4
commit
085f602427
@ -85,13 +85,13 @@ public class Checkbox extends BasicButton {
|
|||||||
assert getChildren().size() == 1 : "Checkbox expects that BasicButton contains exactly one child";
|
assert getChildren().size() == 1 : "Checkbox expects that BasicButton contains exactly one child";
|
||||||
Component basicChild = getChild(0);
|
Component basicChild = getChild(0);
|
||||||
|
|
||||||
Panel panel = new Panel(getName() + ".LabelAndTick", new LayoutHorizontal(0, 10));
|
Group group = new Group(getName() + ".LabelAndTick", new LayoutHorizontal(0, 10));
|
||||||
removeChild(basicChild);
|
removeChild(basicChild);
|
||||||
setLayout(new LayoutAlign(0, 0.5f, 10));
|
setLayout(new LayoutAlign(0, 0.5f, 10));
|
||||||
panel.setLayoutHint(basicChild.getLayoutHint());
|
group.setLayoutHint(basicChild.getLayoutHint());
|
||||||
panel.addChild(new Tick());
|
group.addChild(new Tick());
|
||||||
panel.addChild(basicChild);
|
group.addChild(basicChild);
|
||||||
addChild(panel);
|
addChild(group);
|
||||||
|
|
||||||
addAction(b -> switchState());
|
addAction(b -> switchState());
|
||||||
}
|
}
|
||||||
|
28
src/main/java/ru/windcorp/progressia/client/graphics/gui/Group.java
Executable file
28
src/main/java/ru/windcorp/progressia/client/graphics/gui/Group.java
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
public class Group extends Component {
|
||||||
|
|
||||||
|
public Group(String name, Layout layout) {
|
||||||
|
super(name);
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
src/main/java/ru/windcorp/progressia/client/graphics/gui/Panel.java
Executable file → Normal file
15
src/main/java/ru/windcorp/progressia/client/graphics/gui/Panel.java
Executable file → Normal file
@ -15,14 +15,21 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.gui;
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
public class Panel extends Component {
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
|
|
||||||
|
public class Panel extends Group {
|
||||||
|
|
||||||
public Panel(String name, Layout layout) {
|
public Panel(String name, Layout layout) {
|
||||||
super(name);
|
super(name, layout);
|
||||||
setLayout(layout);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void assembleSelf(RenderTarget target) {
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), Colors.LIGHT_GRAY);
|
||||||
|
target.fill(getX() + 2, getY() + 2, getWidth() - 4, getHeight() - 4, Colors.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,28 +96,28 @@ public class RadioButton extends BasicButton {
|
|||||||
assert getChildren().size() == 1 : "RadioButton expects that BasicButton contains exactly one child";
|
assert getChildren().size() == 1 : "RadioButton expects that BasicButton contains exactly one child";
|
||||||
Component basicChild = getChild(0);
|
Component basicChild = getChild(0);
|
||||||
|
|
||||||
Panel panel = new Panel(getName() + ".LabelAndTick", new LayoutHorizontal(0, 10));
|
Group group = new Group(getName() + ".LabelAndTick", new LayoutHorizontal(0, 10));
|
||||||
removeChild(basicChild);
|
removeChild(basicChild);
|
||||||
setLayout(new LayoutAlign(0, 0.5f, 10));
|
setLayout(new LayoutAlign(0, 0.5f, 10));
|
||||||
panel.setLayoutHint(basicChild.getLayoutHint());
|
group.setLayoutHint(basicChild.getLayoutHint());
|
||||||
panel.addChild(new Tick());
|
group.addChild(new Tick());
|
||||||
panel.addChild(basicChild);
|
group.addChild(basicChild);
|
||||||
addChild(panel);
|
addChild(group);
|
||||||
|
|
||||||
addListener(KeyEvent.class, e -> {
|
addListener(KeyEvent.class, e -> {
|
||||||
if (e.isRelease()) return false;
|
if (e.isRelease()) return false;
|
||||||
|
|
||||||
if (e.getKey() == GLFW.GLFW_KEY_LEFT || e.getKey() == GLFW.GLFW_KEY_UP) {
|
if (e.getKey() == GLFW.GLFW_KEY_LEFT || e.getKey() == GLFW.GLFW_KEY_UP) {
|
||||||
if (group != null) {
|
if (this.group != null) {
|
||||||
group.selectPrevious();
|
this.group.selectPrevious();
|
||||||
group.getSelected().takeFocus();
|
this.group.getSelected().takeFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (e.getKey() == GLFW.GLFW_KEY_RIGHT || e.getKey() == GLFW.GLFW_KEY_DOWN) {
|
} else if (e.getKey() == GLFW.GLFW_KEY_RIGHT || e.getKey() == GLFW.GLFW_KEY_DOWN) {
|
||||||
if (group != null) {
|
if (this.group != null) {
|
||||||
group.selectNext();
|
this.group.selectNext();
|
||||||
group.getSelected().takeFocus();
|
this.group.getSelected().takeFocus();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import ru.windcorp.progressia.client.graphics.font.Font;
|
|||||||
import ru.windcorp.progressia.client.graphics.font.Typeface;
|
import ru.windcorp.progressia.client.graphics.font.Typeface;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||||
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||||
@ -33,12 +33,12 @@ public class LayerAbout extends GUILayer {
|
|||||||
public LayerAbout() {
|
public LayerAbout() {
|
||||||
super("LayerAbout", new LayoutAlign(1, 1, 5));
|
super("LayerAbout", new LayoutAlign(1, 1, 5));
|
||||||
|
|
||||||
Panel panel = new Panel("ControlDisplays", new LayoutVertical(5));
|
Group group = new Group("ControlDisplays", new LayoutVertical(5));
|
||||||
|
|
||||||
Font font = new Font().withColor(Colors.WHITE).deriveOutlined().withAlign(Typeface.ALIGN_RIGHT);
|
Font font = new Font().withColor(Colors.WHITE).deriveOutlined().withAlign(Typeface.ALIGN_RIGHT);
|
||||||
Font aboutFont = font.withColor(0xFF37A3E6).deriveBold();
|
Font aboutFont = font.withColor(0xFF37A3E6).deriveBold();
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"About",
|
"About",
|
||||||
aboutFont,
|
aboutFont,
|
||||||
@ -46,7 +46,7 @@ public class LayerAbout extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"Version",
|
"Version",
|
||||||
font,
|
font,
|
||||||
@ -54,7 +54,7 @@ public class LayerAbout extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"DebugHint",
|
"DebugHint",
|
||||||
font,
|
font,
|
||||||
@ -62,7 +62,7 @@ public class LayerAbout extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
getRoot().addChild(panel);
|
getRoot().addChild(group);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
|||||||
import ru.windcorp.progressia.client.graphics.gui.Button;
|
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Checkbox;
|
import ru.windcorp.progressia.client.graphics.gui.Checkbox;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
|
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.RadioButtonGroup;
|
import ru.windcorp.progressia.client.graphics.gui.RadioButtonGroup;
|
||||||
@ -41,20 +42,14 @@ public class LayerButtonTest extends GUILayer {
|
|||||||
public LayerButtonTest() {
|
public LayerButtonTest() {
|
||||||
super("LayerButtonTest", new LayoutBorderHorizontal(0));
|
super("LayerButtonTest", new LayoutBorderHorizontal(0));
|
||||||
|
|
||||||
Panel background = new Panel("Background", new LayoutAlign(10)) {
|
Group background = new Group("Background", new LayoutAlign(10)) {
|
||||||
@Override
|
@Override
|
||||||
protected void assembleSelf(RenderTarget target) {
|
protected void assembleSelf(RenderTarget target) {
|
||||||
target.fill(Colors.toVector(0x88FFFFFF));
|
target.fill(Colors.toVector(0x88FFFFFF));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Panel panel = new Panel("Panel", new LayoutVertical(10)) {
|
Panel panel = new Panel("Panel", new LayoutVertical(10));
|
||||||
@Override
|
|
||||||
protected void assembleSelf(RenderTarget target) {
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), Colors.LIGHT_GRAY);
|
|
||||||
target.fill(getX() + 2, getY() + 2, getWidth() - 4, getHeight() - 4, Colors.WHITE);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Button blockableButton;
|
Button blockableButton;
|
||||||
panel.addChild((blockableButton = new Button("BlockableButton", "Blockable")).addAction(b -> {
|
panel.addChild((blockableButton = new Button("BlockableButton", "Blockable")).addAction(b -> {
|
||||||
|
@ -29,7 +29,7 @@ import ru.windcorp.progressia.client.graphics.font.Font;
|
|||||||
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||||
import ru.windcorp.progressia.client.localization.Localizer;
|
import ru.windcorp.progressia.client.localization.Localizer;
|
||||||
@ -50,14 +50,14 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
public LayerTestGUI() {
|
public LayerTestGUI() {
|
||||||
super("LayerTestGui", new LayoutAlign(0, 1, 5));
|
super("LayerTestGui", new LayoutAlign(0, 1, 5));
|
||||||
|
|
||||||
Panel panel = new Panel("ControlDisplays", new LayoutVertical(5));
|
Group group = new Group("ControlDisplays", new LayoutVertical(5));
|
||||||
|
|
||||||
Vec4 color = Colors.WHITE;
|
Vec4 color = Colors.WHITE;
|
||||||
Font font = new Font().withColor(color).deriveOutlined();
|
Font font = new Font().withColor(color).deriveOutlined();
|
||||||
|
|
||||||
TestPlayerControls tpc = TestPlayerControls.getInstance();
|
TestPlayerControls tpc = TestPlayerControls.getInstance();
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"IsFlyingDisplay",
|
"IsFlyingDisplay",
|
||||||
font,
|
font,
|
||||||
@ -65,7 +65,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"IsSprintingDisplay",
|
"IsSprintingDisplay",
|
||||||
font,
|
font,
|
||||||
@ -73,7 +73,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"IsMouseCapturedDisplay",
|
"IsMouseCapturedDisplay",
|
||||||
font,
|
font,
|
||||||
@ -81,7 +81,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"CameraModeDisplay",
|
"CameraModeDisplay",
|
||||||
font,
|
font,
|
||||||
@ -92,7 +92,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"GravityModeDisplay",
|
"GravityModeDisplay",
|
||||||
font,
|
font,
|
||||||
@ -103,7 +103,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"LanguageDisplay",
|
"LanguageDisplay",
|
||||||
font,
|
font,
|
||||||
@ -111,7 +111,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"FullscreenDisplay",
|
"FullscreenDisplay",
|
||||||
font,
|
font,
|
||||||
@ -119,7 +119,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"VSyncDisplay",
|
"VSyncDisplay",
|
||||||
font,
|
font,
|
||||||
@ -127,7 +127,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new DynamicLabel(
|
new DynamicLabel(
|
||||||
"FPSDisplay",
|
"FPSDisplay",
|
||||||
font,
|
font,
|
||||||
@ -139,7 +139,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new DynamicLabel(
|
new DynamicLabel(
|
||||||
"TPSDisplay",
|
"TPSDisplay",
|
||||||
font,
|
font,
|
||||||
@ -148,7 +148,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new DynamicLabel(
|
new DynamicLabel(
|
||||||
"ChunkUpdatesDisplay",
|
"ChunkUpdatesDisplay",
|
||||||
font,
|
font,
|
||||||
@ -160,7 +160,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new DynamicLabel(
|
new DynamicLabel(
|
||||||
"PosDisplay",
|
"PosDisplay",
|
||||||
font,
|
font,
|
||||||
@ -169,7 +169,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"SelectedBlockDisplay",
|
"SelectedBlockDisplay",
|
||||||
font,
|
font,
|
||||||
@ -180,7 +180,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"SelectedTileDisplay",
|
"SelectedTileDisplay",
|
||||||
font,
|
font,
|
||||||
@ -191,7 +191,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
panel.addChild(
|
group.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"PlacementModeHint",
|
"PlacementModeHint",
|
||||||
font,
|
font,
|
||||||
@ -199,7 +199,7 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
getRoot().addChild(panel);
|
getRoot().addChild(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Runnable getUpdateCallback() {
|
public Runnable getUpdateCallback() {
|
||||||
|
Reference in New Issue
Block a user